#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__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int compare_buffers(void *buf1, int buf1_size, void *buf2, int buf2_size) {
  int n_diffs = 1;
  unsigned char *b1 = buf1;
  unsigned char *b2 = buf2;
  if (buf1_size == buf2_size) {
    if (memcmp(b1, b2, buf1_size)) {
      int j;
      for (j = 0; j < buf1_size; j++) {
        if (!(j % 16)) {
          printf("\n%04X\t", j);
        }
        if (b1[j] != b2[j]) {
          n_diffs++;
          printf(" [%02X->%02X] ", b1[j], b2[j]);
        } else {
          printf("%02X ", b1[j]);
        }
      }
      printf("\n");
    } else {
      n_diffs = 0;
    }
  } else {
    printf("DIFFERENT ENC/DEC SIZES!!!: %d != %d\n", buf1_size, buf2_size);
  }
  return (n_diffs);
}


x86 assembly (clang, -O0):
<compare_buffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    124b <compare_buffers+0x12b>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     123f <compare_buffers+0x11f>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122c <compare_buffers+0x10c>
mov    -0x34(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ab <compare_buffers+0x8b>
mov    -0x34(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11ff <compare_buffers+0xdf>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1219 <compare_buffers+0xf9>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121e <compare_buffers+0xfe>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117a <compare_buffers+0x5a>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1246 <compare_buffers+0x126>
movl   $0x0,-0x20(%rbp)
jmp    125f <compare_buffers+0x13f>
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_buffers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
cmp    %ecx,%esi
jne    11bc <compare_buffers+0x8c>
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rdx,%rsi
mov    %ebp,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11d5 <compare_buffers+0xa5>
test   %ebp,%ebp
jle    11d9 <compare_buffers+0xa9>
mov    %ebp,%r12d
mov    $0x1,%ebp
lea    0xe9e(%rip),%r13
xor    %r15d,%r15d
jmp    1187 <compare_buffers+0x57>
xchg   %ax,%ax
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r12
je     11de <compare_buffers+0xae>
test   $0xf,%r15b
jne    119e <compare_buffers+0x6e>
lea    0xe6c(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx,%r15,1),%esi
movzbl (%r14,%r15,1),%edx
cmp    %dl,%sil
je     1170 <compare_buffers+0x40>
add    $0x1,%ebp
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    117e <compare_buffers+0x4e>
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
mov    %ecx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
jmp    11e8 <compare_buffers+0xb8>
xor    %ebp,%ebp
jmp    11e8 <compare_buffers+0xb8>
mov    $0x1,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\0A%04X\09\00"
@.str.1 = [15 x i8] c" [%02X->%02X] \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [38 x i8] c"DIFFERENT ENC/DEC SIZES!!!: %d != %d\0A\00"
define i32 @compare_buffers(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 1, i32* %9
%13 = load i8*, i8** %5
store i8* %13, i8** %10
%14 = load i8*, i8** %7
store i8* %14, i8** %11
%15 = load i32, i32* %6
%16 = load i32, i32* %8
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %82
18: ; preds = %4
%19 = load i8*, i8** %10
%20 = load i8*, i8** %11
%21 = load i32, i32* %6
%22 = call i64 @memcmp(i8* %19, i8* %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %80
24: ; preds = %18
store i32 0, i32* %12
br label %25
25: ; preds = %75, %24
%26 = load i32, i32* %12
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %78
29: ; preds = %25
%30 = load i32, i32* %12
%31 = srem i32 %30, 16
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i32, i32* %12
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %29
%37 = load i8*, i8** %10
%38 = load i32, i32* %12
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = load i8*, i8** %11
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp ne i32 %42, %48
br i1 %49, label %50, label %66
50: ; preds = %36
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
%53 = load i8*, i8** %10
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = load i8*, i8** %11
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %58, i32 %64)
br label %74
66: ; preds = %36
%67 = load i8*, i8** %10
%68 = load i32, i32* %12
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %66, %50
br label %75
75: ; preds = %74
%76 = load i32, i32* %12
%77 = add nsw i32 %76, 1
store i32 %77, i32* %12
br label %25
78: ; preds = %25
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %81
80: ; preds = %18
store i32 0, i32* %9
br label %81
81: ; preds = %80, %78
br label %86
82: ; preds = %4
%83 = load i32, i32* %6
%84 = load i32, i32* %8
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %83, i32 %84)
br label %86
86: ; preds = %82, %81
%87 = load i32, i32* %9
ret i32 %87
}

LLVM IR (-O2):
@.str = [7 x i8] c"\0A%04X\09\00"
@.str.1 = [15 x i8] c" [%02X->%02X] \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.4 = [38 x i8] c"DIFFERENT ENC/DEC SIZES!!!: %d != %d\0A\00"
define i32 @compare_buffers(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i32 %1, %3
br i1 %5, label %6, label %41
6: ; preds = %4
%7 = tail call i64 @memcmp(i8* %0, i8* %2, i32 %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %43, label %9
9: ; preds = %6
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %38
11: ; preds = %9
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %11, %34
%14 = phi i64 [ 0, %11 ], [ %36, %34 ]
%15 = phi i32 [ 1, %11 ], [ %35, %34 ]
%16 = trunc i64 %14 to i32
%17 = and i32 %16, 15
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %21
21: ; preds = %19, %13
%22 = getelementptr inbounds i8, i8* %0, i64 %14
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = getelementptr inbounds i8, i8* %2, i64 %14
%26 = load i8, i8* %25
%27 = icmp eq i8 %23, %26
br i1 %27, label %32, label %28
28: ; preds = %21
%29 = zext i8 %26 to i32
%30 = add nsw i32 %15, 1
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %29)
br label %34
32: ; preds = %21
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %34
34: ; preds = %28, %32
%35 = phi i32 [ %30, %28 ], [ %15, %32 ]
%36 = add nuw nsw i64 %14, 1
%37 = icmp eq i64 %36, %12
br i1 %37, label %38, label %13
38: ; preds = %34, %9
%39 = phi i32 [ 1, %9 ], [ %35, %34 ]
%40 = tail call i32 @putchar(i32 10)
br label %43
41: ; preds = %4
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %1, i32 %3)
br label %43
43: ; preds = %6, %38, %41
%44 = phi i32 [ %39, %38 ], [ 1, %41 ], [ 0, %6 ]
ret i32 %44
}