#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 buffer_compare(void *ibuf, void *obuf, size_t len) {
  int i;
  int ret = 0;
  unsigned char *p1 = ibuf;
  unsigned char *p2 = obuf;
  for (i = 0; i < len; i++) {
    do {
      printf("%02X  %02X\n", *(p1 + i), *(p2 + i));
    } while (0);
    if (p1[i] != p2[i]) {
      ret = i + 1;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<buffer_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b7 <buffer_compare+0xa7>
jmp    1155 <buffer_compare+0x45>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe91(%rip),%rdi
movzbl %dl,%esi
movzbl (%rax,%rcx,1),%edx
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11a4 <buffer_compare+0x94>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a9 <buffer_compare+0x99>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1142 <buffer_compare+0x32>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_compare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     116e <buffer_compare+0x5e>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
xor    %ebx,%ebx
lea    0xece(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x0(%r13,%rbx,1),%esi
movzbl (%r15,%rbx,1),%edx
mov    %r12,%rdi
call   1030 <printf@plt>
movzbl 0x0(%r13,%rbx,1),%eax
cmp    (%r15,%rbx,1),%al
lea    0x1(%rbx),%rax
cmovne %eax,%ebp
mov    %rax,%rbx
cmp    %rax,%r14
jne    1140 <buffer_compare+0x30>
jmp    1170 <buffer_compare+0x60>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%02X %02X\0A\00"
define i32 @buffer_compare(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %8
%11 = load i8*, i8** %4
store i8* %11, i8** %9
%12 = load i8*, i8** %5
store i8* %12, i8** %10
store i32 0, i32* %7
br label %13
13: ; preds = %49, %3
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %52
18: ; preds = %13
br label %19
19: ; preds = %18
%20 = load i8*, i8** %9
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %10
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %24, i8 zeroext %29)
br label %31
31: ; preds = %19
%32 = load i8*, i8** %9
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = load i8*, i8** %10
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp ne i32 %37, %43
br i1 %44, label %45, label %48
45: ; preds = %31
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %48
48: ; preds = %45, %31
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %13
52: ; preds = %13
%53 = load i32, i32* %8
ret i32 %53
}

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