#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 *, unsigned char, unsigned char);
int memcmp(unsigned char *b1, unsigned char *b2, int len) {
  int i;
  for (i = 0; i < len; i++) {
    if (*b1++ != *b2++) {
      b1--;
      b2--;
      printf("DIFF: %d != %d\n", *b1, *b2);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<memcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b5 <memcmp+0xa5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     11a2 <memcmp+0x92>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
lea    0xe75(%rip),%rdi
movzbl %cl,%esi
movzbl (%rax),%edx
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <memcmp+0xac>
jmp    11a7 <memcmp+0x97>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <memcmp+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcmp>:
push   %rax
test   %edx,%edx
jle    1135 <memcmp+0x25>
mov    %edx,%r8d
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rdi,%rcx,1),%edx
movzbl (%rsi,%rcx,1),%eax
cmp    %al,%dl
jne    1139 <memcmp+0x29>
add    $0x1,%rcx
cmp    %ecx,%r8d
jne    1120 <memcmp+0x10>
xor    %eax,%eax
pop    %rcx
ret
movzbl %dl,%esi
movzbl %al,%edx
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"DIFF: %d != %d\0A\00"
define i32 @memcmp(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %34, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %5
%16 = load i8, i8* %14
%17 = zext i8 %16 to i32
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %6
%20 = load i8, i8* %18
%21 = zext i8 %20 to i32
%22 = icmp ne i32 %17, %21
br i1 %22, label %23, label %33
23: ; preds = %13
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %5
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %6
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = load i8*, i8** %6
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 zeroext %29, i8 zeroext %31)
store i32 -1, i32* %4
br label %38
33: ; preds = %13
br label %34
34: ; preds = %33
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %9
37: ; preds = %9
store i32 0, i32* %4
br label %38
38: ; preds = %37, %23
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [16 x i8] c"DIFF: %d != %d\0A\00"
define i32 @memcmp(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %19
5: ; preds = %3, %14
%6 = phi i32 [ %17, %14 ], [ 0, %3 ]
%7 = phi i8* [ %15, %14 ], [ %1, %3 ]
%8 = phi i8* [ %16, %14 ], [ %0, %3 ]
%9 = load i8, i8* %8
%10 = load i8, i8* %7
%11 = icmp eq i8 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i8 zeroext %10)
br label %19
14: ; preds = %5
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = add nuw nsw i32 %6, 1
%18 = icmp eq i32 %17, %2
br i1 %18, label %19, label %5
19: ; preds = %14, %3, %12
%20 = phi i32 [ -1, %12 ], [ 0, %3 ], [ 0, %14 ]
ret i32 %20
}