#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 */
scalar_t__ k_memcmp(char *, char *, int);
int test_memcmp_1() {
  char a1[] = {'a', 'b', 'c', 'd'};
  char a2[] = {'a', 'b', 'c', 'd'};
  int l;
  for (l = 0; l <= 4; l++) {
    if (k_memcmp(a1, a2, l) != 0)
      return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<test_memcmp_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xee2(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0xed9(%rip),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jg     1174 <test_memcmp_1+0x64>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <k_memcmp@plt>
cmp    $0x0,%rax
je     1161 <test_memcmp_1+0x51>
movl   $0x1,-0x4(%rbp)
jmp    117b <test_memcmp_1+0x6b>
jmp    1166 <test_memcmp_1+0x56>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <test_memcmp_1+0x21>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memcmp_1>:
push   %rbx
sub    $0x10,%rsp
movl   $0x64636261,0xc(%rsp)
64
movl   $0x64636261,0x8(%rsp)
64
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <k_memcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    11ac <test_memcmp_1+0x9c>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1030 <k_memcmp@plt>
test   %rax,%rax
jne    11ac <test_memcmp_1+0x9c>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x2,%edx
call   1030 <k_memcmp@plt>
test   %rax,%rax
jne    11ac <test_memcmp_1+0x9c>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x3,%edx
call   1030 <k_memcmp@plt>
test   %rax,%rax
jne    11ac <test_memcmp_1+0x9c>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1030 <k_memcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_memcmp_1.a1 = [4 x i8] c"abcd"
@__const.test_memcmp_1.a2 = [4 x i8] c"abcd"
define i32 @test_memcmp_1() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = bitcast [4 x i8]* %2 to i8*
%6 = bitcast [4 x i8]* %3 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 4
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* %4
%14 = call i64 @k_memcmp(i8* %11, i8* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 1, i32* %1
br label %22
17: ; preds = %10
br label %18
18: ; preds = %17
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %7
21: ; preds = %7
store i32 0, i32* %1
br label %22
22: ; preds = %21, %16
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
define i32 @test_memcmp_1() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 1684234849, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 1684234849, i32* %2
%5 = call i64 @k_memcmp(i8* %3, i8* %4, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %0
%8 = call i64 @k_memcmp(i8* %3, i8* %4, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = call i64 @k_memcmp(i8* %3, i8* %4, i32 2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = call i64 @k_memcmp(i8* %3, i8* %4, i32 3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = call i64 @k_memcmp(i8* %3, i8* %4, i32 4)
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %16, %13, %10, %7, %0
%21 = phi i32 [ 1, %0 ], [ 1, %7 ], [ 1, %10 ], [ 1, %13 ], [ %19, %16 ]
ret i32 %21
}