#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*/ memcmp(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *, char *,
                          int /*<<< orphan*/, char *, int /*<<< orphan*/,
                          char *, int /*<<< orphan*/);
void fig08_30() {
  char s1[] = "ABCDEFG";
  char s2[] = "ABCDXYZ";
  printf("%s%s\n%s%s\n\n%s%2d\n%s%2d\n%s%2d\n", "s1 = ", s1, "s2 = ", s2,
         "memcmp( s1, s2, 4 ) = ", memcmp(s1, s2, 4),
         "memcmp( s1, s2, 7 ) = ", memcmp(s1, s2, 7),
         "memcmp( s2, s1, 7 ) = ", memcmp(s1, s2, 7));
}


x86 assembly (clang, -O0):
<fig08_30>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcmp@plt>
mov    %eax,%r14d
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x7,%edx
call   1040 <memcmp@plt>
mov    %eax,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x7,%edx
call   1040 <memcmp@plt>
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%r8
mov    -0x24(%rbp),%r11d
lea    0xe70(%rip),%rdi
lea    0xe87(%rip),%rsi
lea    0xe86(%rip),%rcx
lea    0xe85(%rip),%r9
lea    0xe95(%rip),%rbx
lea    0xea5(%rip),%r10
mov    %r14d,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %eax,0x20(%rsp)
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_30>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x47464544434241,%rax
mov    %rax,0x10(%rsp)
movabs $0x5a595844434241,%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <memcmp@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1040 <memcmp@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1040 <memcmp@plt>
sub    $0x8,%rsp
lea    0xec4(%rip),%r10
lea    0xea6(%rip),%r11
lea    0xe5e(%rip),%rdi
lea    0xe75(%rip),%rsi
lea    0xe74(%rip),%rcx
lea    0xe73(%rip),%r9
mov    %rbx,%rdx
mov    %r15,%r8
push   %rax
push   %r10
push   %r12
push   %r11
push   %r14
call   1030 <printf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.fig08_30.s1 = [8 x i8] c"ABCDEFG\00"
@__const.fig08_30.s2 = [8 x i8] c"ABCDXYZ\00"
@.str = [30 x i8] c"%s%s\0A%s%s\0A\0A%s%2d\0A%s%2d\0A%s%2d\0A\00"
@.str.1 = [6 x i8] c"s1 = \00"
@.str.2 = [6 x i8] c"s2 = \00"
@.str.3 = [23 x i8] c"memcmp( s1, s2, 4 ) = \00"
@.str.4 = [23 x i8] c"memcmp( s1, s2, 7 ) = \00"
@.str.5 = [23 x i8] c"memcmp( s2, s1, 7 ) = \00"
define void @fig08_30() {
%1 = alloca [8 x i8]
%2 = alloca [8 x i8]
%3 = bitcast [8 x i8]* %1 to i8*
%4 = bitcast [8 x i8]* %2 to i8*
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%9 = call i32 @memcmp(i8* %7, i8* %8, i32 4)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%12 = call i32 @memcmp(i8* %10, i8* %11, i32 7)
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%15 = call i32 @memcmp(i8* %13, i8* %14, i32 7)
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %15)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"%s%s\0A%s%s\0A\0A%s%2d\0A%s%2d\0A%s%2d\0A\00"
@.str.1 = [6 x i8] c"s1 = \00"
@.str.2 = [6 x i8] c"s2 = \00"
@.str.3 = [23 x i8] c"memcmp( s1, s2, 4 ) = \00"
@.str.4 = [23 x i8] c"memcmp( s1, s2, 7 ) = \00"
@.str.5 = [23 x i8] c"memcmp( s2, s1, 7 ) = \00"
define void @fig08_30() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
store i64 20061986658402881, i64* %1
%4 = bitcast i64* %2 to i8*
store i64 25430983541211713, i64* %2
%5 = call i32 @memcmp(i8* %3, i8* %4, i32 4)
%6 = call i32 @memcmp(i8* %3, i8* %4, i32 7)
%7 = call i32 @memcmp(i8* %3, i8* %4, i32 7)
%8 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %7)
ret void
}