#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*/ fslog(char *, char, ...);
int byte_compare(char *a, char *b, int len) {
  int i;
  for (i = 0; i < len; i++) {
    if (a[i] != b[i]) {
      fslog("byte compare failed at offset 0x%x", i);
      fslog("Expected 0x%x, read 0x%x", a[i], b[i]);
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<byte_compare>:
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    11b0 <byte_compare+0xa0>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     119d <byte_compare+0x8d>
mov    -0x20(%rbp),%eax
lea    0xea0(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <fslog@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%edx
lea    0xe9b(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <fslog@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <byte_compare+0xa7>
jmp    11a2 <byte_compare+0x92>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <byte_compare+0x1a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_compare>:
push   %r15
push   %r14
push   %rbx
mov    $0xffffffff,%eax
test   %edx,%edx
jle    1171 <byte_compare+0x61>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%ecx
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edx
cmp    (%r14,%rbx,1),%dl
jne    1146 <byte_compare+0x36>
add    $0x1,%rbx
cmp    %rbx,%rcx
jne    1130 <byte_compare+0x20>
jmp    1171 <byte_compare+0x61>
movsbl %bl,%esi
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
call   1030 <fslog@plt>
movsbl (%r15,%rbx,1),%esi
movsbl (%r14,%rbx,1),%edx
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1030 <fslog@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"byte compare failed at offset 0x%x\00"
@.str.1 = [25 x i8] c"Expected 0x%x, read 0x%x\00"
define i32 @byte_compare(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 = %45, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %48
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8*, i8** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %19, %25
br i1 %26, label %27, label %44
27: ; preds = %13
%28 = load i32, i32* %8
%29 = trunc i32 %28 to i8
%30 = call i32 (i8*, i8, ...) @fslog(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext %29)
%31 = load i8*, i8** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = load i8*, i8** %6
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, i8, ...) @fslog(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8 signext %35, i32 %41)
%43 = load i32, i32* %8
store i32 %43, i32* %4
br label %49
44: ; preds = %13
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %9
48: ; preds = %9
store i32 -1, i32* %4
br label %49
49: ; preds = %48, %27
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@.str = [35 x i8] c"byte compare failed at offset 0x%x\00"
@.str.1 = [25 x i8] c"Expected 0x%x, read 0x%x\00"
define i32 @byte_compare(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %28
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %25
%8 = phi i64 [ 0, %5 ], [ %26, %25 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %1, i64 %8
%12 = load i8, i8* %11
%13 = icmp eq i8 %10, %12
br i1 %13, label %25, label %14
14: ; preds = %7
%15 = trunc i64 %8 to i32
%16 = and i64 %8, 4294967295
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = getelementptr inbounds i8, i8* %1, i64 %16
%19 = trunc i64 %8 to i8
%20 = tail call i32 (i8*, i8, ...) @fslog(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext %19)
%21 = load i8, i8* %17
%22 = load i8, i8* %18
%23 = sext i8 %22 to i32
%24 = tail call i32 (i8*, i8, ...) @fslog(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8 signext %21, i32 %23)
br label %28
25: ; preds = %7
%26 = add nuw nsw i64 %8, 1
%27 = icmp eq i64 %26, %6
br i1 %27, label %28, label %7
28: ; preds = %25, %3, %14
%29 = phi i32 [ %15, %14 ], [ -1, %3 ], [ -1, %25 ]
ret i32 %29
}