#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, char const *, char *, char const *,
                          char *, char const *, ...);
int /*<<< orphan*/ strcmp(char const *, char const *);
char *strncmp(char const *, char const *, int);
void fig08_18() {
  const char *s1 = "Happy New Year";
  const char *s2 = "Happy New Year";
  const char *s3 = "Happy Holiday";
  printf("%s%s\n%s%s\n%s%s\n\n%s%2d\n%s%2d\n%s%2d\n\n", "s1 = ", s1,
         "s2 = ", s2, "s3 = ", s3, "strcmp( s1, s2 ) = ", strcmp(s1, s2),
         "strcmp( s1, s2 ) = ", strcmp(s1, s3),
         "strcmp( s3, s1 ) = ", strcmp(s3, s1));
  printf("%s%2d\n%s%2d\n%s%2d\n", "strncmp( s1, s3, 6 ) = ", strncmp(s1, s3, 6),
         "strncmp( s1, s3, 7 ) = ", strncmp(s1, s3, 7),
         "strncmp( s3, s1, 7 ) = ", strncmp(s3, s1, 7));
}


x86 assembly (clang, -O0):
<fig08_18>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
lea    0xebc(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%r15
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,%r14d
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%r8
mov    -0x44(%rbp),%r11d
lea    0xe6b(%rip),%rdi
lea    0xe88(%rip),%rsi
lea    0xe87(%rip),%rcx
lea    0xe86(%rip),%r9
lea    0xe85(%rip),%rbx
lea    0xe92(%rip),%r10
mov    %r15,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r14d,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11d,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %eax,0x30(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%r8
lea    0xe31(%rip),%rdi
lea    0xe3d(%rip),%rsi
lea    0xe4e(%rip),%rcx
lea    0xe5f(%rip),%r9
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_18>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8,%rsp
lea    0xf33(%rip),%r10
lea    0xf18(%rip),%rbx
lea    0xecd(%rip),%r14
lea    0xed4(%rip),%rdi
lea    0xef1(%rip),%rsi
lea    0xef0(%rip),%rcx
lea    0xea2(%rip),%r12
lea    0xee8(%rip),%r9
mov    %r12,%rdx
mov    %r12,%r8
xor    %eax,%eax
push   $0xffffffffffffffff
push   %r10
push   $0x1
push   %rbx
push   $0x0
push   %rbx
push   %r14
call   1040 <printf@plt>
add    $0x40,%rsp
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0xeb5(%rip),%rdi
lea    0xec1(%rip),%rsi
lea    0xed2(%rip),%rcx
lea    0xee3(%rip),%r9
mov    %r15,%rdx
mov    %r13,%r8
xor    %eax,%eax
push   %rbx
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Happy New Year\00"
@.str.1 = [14 x i8] c"Happy Holiday\00"
@.str.2 = [36 x i8] c"%s%s\0A%s%s\0A%s%s\0A\0A%s%2d\0A%s%2d\0A%s%2d\0A\0A\00"
@.str.3 = [6 x i8] c"s1 = \00"
@.str.4 = [6 x i8] c"s2 = \00"
@.str.5 = [6 x i8] c"s3 = \00"
@.str.6 = [20 x i8] c"strcmp( s1, s2 ) = \00"
@.str.7 = [20 x i8] c"strcmp( s3, s1 ) = \00"
@.str.8 = [19 x i8] c"%s%2d\0A%s%2d\0A%s%2d\0A\00"
@.str.9 = [24 x i8] c"strncmp( s1, s3, 6 ) = \00"
@.str.10 = [24 x i8] c"strncmp( s1, s3, 7 ) = \00"
@.str.11 = [24 x i8] c"strncmp( s3, s1, 7 ) = \00"
define void @fig08_18() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %1
%5 = load i8*, i8** %2
%6 = load i8*, i8** %3
%7 = load i8*, i8** %1
%8 = load i8*, i8** %2
%9 = call i32 @strcmp(i8* %7, i8* %8)
%10 = load i8*, i8** %1
%11 = load i8*, i8** %3
%12 = call i32 @strcmp(i8* %10, i8* %11)
%13 = load i8*, i8** %3
%14 = load i8*, i8** %1
%15 = call i32 @strcmp(i8* %13, i8* %14)
%16 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %15)
%17 = load i8*, i8** %1
%18 = load i8*, i8** %3
%19 = call i8* @strncmp(i8* %17, i8* %18, i32 6)
%20 = load i8*, i8** %1
%21 = load i8*, i8** %3
%22 = call i8* @strncmp(i8* %20, i8* %21, i32 7)
%23 = load i8*, i8** %3
%24 = load i8*, i8** %1
%25 = call i8* @strncmp(i8* %23, i8* %24, i32 7)
%26 = call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"Happy New Year\00"
@.str.1 = [14 x i8] c"Happy Holiday\00"
@.str.2 = [36 x i8] c"%s%s\0A%s%s\0A%s%s\0A\0A%s%2d\0A%s%2d\0A%s%2d\0A\0A\00"
@.str.3 = [6 x i8] c"s1 = \00"
@.str.4 = [6 x i8] c"s2 = \00"
@.str.5 = [6 x i8] c"s3 = \00"
@.str.6 = [20 x i8] c"strcmp( s1, s2 ) = \00"
@.str.7 = [20 x i8] c"strcmp( s3, s1 ) = \00"
@.str.8 = [19 x i8] c"%s%2d\0A%s%2d\0A%s%2d\0A\00"
@.str.9 = [24 x i8] c"strncmp( s1, s3, 6 ) = \00"
@.str.10 = [24 x i8] c"strncmp( s1, s3, 7 ) = \00"
@.str.11 = [24 x i8] c"strncmp( s3, s1, 7 ) = \00"
define void @fig08_18() {
%1 = tail call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 -1)
%2 = tail call i8* @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 6)
%3 = tail call i8* @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 7)
%4 = tail call i8* @strncmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 7)
%5 = tail call i32 (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i8* %4)
ret void
}