#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*/ max(int /*<<< orphan*/, int /*<<< orphan*/);
int memcmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
void memcmpTest() {
  char str1[256] = "shaun1";
  char str2[256] = "shaun2";
  int n;
  n = memcmp(str1, str2, max(strlen(str1), strlen(str2)));
  if (n > 0)
    printf("'%s' is greater than '%s'.\n", str1, str2);
  else if (n < 0)
    printf("'%s' is less than '%s'.\n", str1, str2);
  else
    printf("'%s' is the same as '%s'.\n", str1, str2);
}


x86 assembly (clang, -O0):
<memcmpTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
movb   $0x73,-0x100(%rbp)
movb   $0x68,-0xff(%rbp)
movb   $0x61,-0xfe(%rbp)
movb   $0x75,-0xfd(%rbp)
movb   $0x6e,-0xfc(%rbp)
movb   $0x31,-0xfb(%rbp)
lea    -0x200(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
movb   $0x73,-0x200(%rbp)
movb   $0x68,-0x1ff(%rbp)
movb   $0x61,-0x1fe(%rbp)
movb   $0x75,-0x1fd(%rbp)
movb   $0x6e,-0x1fc(%rbp)
movb   $0x32,-0x1fb(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x200(%rbp),%rax
mov    %rax,-0x210(%rbp)
lea    -0x100(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x21c(%rbp)
lea    -0x200(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x21c(%rbp),%edi
mov    %eax,%esi
call   1050 <max@plt>
mov    -0x218(%rbp),%rdi
mov    -0x210(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcmp@plt>
mov    %eax,-0x204(%rbp)
cmpl   $0x0,-0x204(%rbp)
jle    1263 <memcmpTest+0x113>
lea    -0x100(%rbp),%rsi
lea    -0x200(%rbp),%rdx
lea    0xda7(%rip),%rdi
call   1040 <printf@plt>
jmp    12ae <memcmpTest+0x15e>
cmpl   $0x0,-0x204(%rbp)
jge    128f <memcmpTest+0x13f>
lea    -0x100(%rbp),%rsi
lea    -0x200(%rbp),%rdx
lea    0xd97(%rip),%rdi
call   1040 <printf@plt>
jmp    12a9 <memcmpTest+0x159>
lea    -0x100(%rbp),%rsi
lea    -0x200(%rbp),%rdx
lea    0xd91(%rip),%rdi
call   1040 <printf@plt>
jmp    12ae <memcmpTest+0x15e>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcmpTest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movl   $0x75616873,0x100(%rsp)
73 68 61 75
movw   $0x316e,0x104(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x75616873,(%rsp)
movw   $0x326e,0x4(%rsp)
lea    0x100(%rsp),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <max@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
lea    0xd88(%rip),%rax
lea    0xd9a(%rip),%rcx
cmovs  %rax,%rcx
lea    0xd5a(%rip),%rdi
cmovle %rcx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"'%s' is greater than '%s'.\0A\00"
@.str.1 = [25 x i8] c"'%s' is less than '%s'.\0A\00"
@.str.2 = [27 x i8] c"'%s' is the same as '%s'.\0A\00"
define void @memcmpTest() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = bitcast [256 x i8]* %1 to i8*
%5 = bitcast i8* %4 to [256 x i8]*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i32 0, i32 0
store i8 115, i8* %6
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i32 0, i32 1
store i8 104, i8* %7
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i32 0, i32 2
store i8 97, i8* %8
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i32 0, i32 3
store i8 117, i8* %9
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i32 0, i32 4
store i8 110, i8* %10
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i32 0, i32 5
store i8 49, i8* %11
%12 = bitcast [256 x i8]* %2 to i8*
%13 = bitcast i8* %12 to [256 x i8]*
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i32 0, i32 0
store i8 115, i8* %14
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i32 0, i32 1
store i8 104, i8* %15
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i32 0, i32 2
store i8 97, i8* %16
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i32 0, i32 3
store i8 117, i8* %17
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i32 0, i32 4
store i8 110, i8* %18
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i32 0, i32 5
store i8 50, i8* %19
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @max(i32 %23, i32 %25)
%27 = call i32 @memcmp(i8* %20, i8* %21, i32 %26)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %0
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32)
br label %46
34: ; preds = %0
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %39)
br label %45
41: ; preds = %34
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%44 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %43)
br label %45
45: ; preds = %41, %37
br label %46
46: ; preds = %45, %30
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"'%s' is greater than '%s'.\0A\00"
@.str.1 = [25 x i8] c"'%s' is less than '%s'.\0A\00"
@.str.2 = [27 x i8] c"'%s' is the same as '%s'.\0A\00"
define void @memcmpTest() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
store i8 115, i8* %3
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 1
store i8 104, i8* %4
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 2
store i8 97, i8* %5
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 3
store i8 117, i8* %6
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 4
store i8 110, i8* %7
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 5
store i8 49, i8* %8
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 115, i8* %9
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
store i8 104, i8* %10
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 2
store i8 97, i8* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 3
store i8 117, i8* %12
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 4
store i8 110, i8* %13
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 5
store i8 50, i8* %14
%15 = call i32 @strlen(i8* %3)
%16 = call i32 @strlen(i8* %9)
%17 = call i32 @max(i32 %15, i32 %16)
%18 = call i32 @memcmp(i8* %3, i8* %9, i32 %17)
%19 = icmp sgt i32 %18, 0
%20 = icmp slt i32 %18, 0
%21 = select i1 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0)
%22 = select i1 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %21
%23 = call i32 @printf(i8* %22, i8* %3, i8* %9)
ret void
}