#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 */
char k_memcmp(char *, char *, int);
int test_memcmp_2() {
  char a1[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
  char a2[] = {'a', 'b', 'c', 'd', 'e', 'f', 'e', 'h'};
  int l;
  for (l = 0; l <= 6; l++) {
    if (k_memcmp(a1, a2, l) != 0)
      return (1);
  }
  if (k_memcmp(a1, a2, 8) != ('g' - 'e'))
    return (2);
  if (k_memcmp(a2, a1, 8) != ('e' - 'g'))
    return (3);
  return (0);
}


x86 assembly (clang, -O0):
<test_memcmp_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xee1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jg     117a <test_memcmp_2+0x6a>
lea    -0xc(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <k_memcmp@plt>
movsbl %al,%eax
cmp    $0x0,%eax
je     1167 <test_memcmp_2+0x57>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <test_memcmp_2+0xc5>
jmp    116c <test_memcmp_2+0x5c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1135 <test_memcmp_2+0x25>
lea    -0xc(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1030 <k_memcmp@plt>
movsbl %al,%eax
cmp    $0x2,%eax
je     11a4 <test_memcmp_2+0x94>
movl   $0x2,-0x4(%rbp)
jmp    11d5 <test_memcmp_2+0xc5>
lea    -0x14(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x8,%edx
call   1030 <k_memcmp@plt>
movsbl %al,%eax
cmp    $0xfffffffe,%eax
je     11ce <test_memcmp_2+0xbe>
movl   $0x3,-0x4(%rbp)
jmp    11d5 <test_memcmp_2+0xc5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memcmp_2>:
push   %rbx
sub    $0x10,%rsp
movabs $0x6867666564636261,%rax
66 67 68
mov    %rax,0x8(%rsp)
movabs $0x6865666564636261,%rax
66 65 68
mov    %rax,(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <k_memcmp@plt>
mov    $0x1,%ebx
test   %al,%al
jne    1216 <test_memcmp_2+0x106>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1030 <k_memcmp@plt>
test   %al,%al
jne    1216 <test_memcmp_2+0x106>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x2,%edx
call   1030 <k_memcmp@plt>
test   %al,%al
jne    1216 <test_memcmp_2+0x106>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x3,%edx
call   1030 <k_memcmp@plt>
test   %al,%al
jne    1216 <test_memcmp_2+0x106>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1030 <k_memcmp@plt>
test   %al,%al
jne    1216 <test_memcmp_2+0x106>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x5,%edx
call   1030 <k_memcmp@plt>
test   %al,%al
jne    1216 <test_memcmp_2+0x106>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x6,%edx
call   1030 <k_memcmp@plt>
test   %al,%al
jne    1216 <test_memcmp_2+0x106>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x8,%edx
call   1030 <k_memcmp@plt>
mov    $0x2,%ebx
cmp    $0x2,%al
jne    1216 <test_memcmp_2+0x106>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1030 <k_memcmp@plt>
xor    %ecx,%ecx
cmp    $0xfe,%al
setne  %cl
lea    (%rcx,%rcx,2),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_memcmp_2.a1 = [8 x i8] c"abcdefgh"
@__const.test_memcmp_2.a2 = [8 x i8] c"abcdefeh"
define i32 @test_memcmp_2() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = bitcast [8 x i8]* %2 to i8*
%6 = bitcast [8 x i8]* %3 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %19, %0
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 6
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* %4
%14 = call signext i8 @k_memcmp(i8* %11, i8* %12, i32 %13)
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %10
store i32 1, i32* %1
br label %37
18: ; preds = %10
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %7
22: ; preds = %7
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%25 = call signext i8 @k_memcmp(i8* %23, i8* %24, i32 8)
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 2
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 2, i32* %1
br label %37
29: ; preds = %22
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%32 = call signext i8 @k_memcmp(i8* %30, i8* %31, i32 8)
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, -2
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 3, i32* %1
br label %37
36: ; preds = %29
store i32 0, i32* %1
br label %37
37: ; preds = %36, %35, %28, %17
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
define i32 @test_memcmp_2() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
store i64 7523094288207667809, i64* %1
%4 = bitcast i64* %2 to i8*
store i64 7522531338254246497, i64* %2
%5 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 0)
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %0
%8 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 1)
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %32
10: ; preds = %7
%11 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 2)
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %10
%14 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 3)
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 4)
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 5)
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 6)
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = call signext i8 @k_memcmp(i8* %3, i8* %4, i32 8)
%27 = icmp eq i8 %26, 2
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call signext i8 @k_memcmp(i8* %4, i8* %3, i32 8)
%30 = icmp eq i8 %29, -2
%31 = select i1 %30, i32 0, i32 3
br label %32
32: ; preds = %0, %7, %10, %13, %16, %19, %22, %28, %25
%33 = phi i32 [ 2, %25 ], [ %31, %28 ], [ 1, %22 ], [ 1, %19 ], [ 1, %16 ], [ 1, %13 ], [ 1, %10 ], [ 1, %7 ], [ 1, %0 ]
ret i32 %33
}