#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(char const *, char const *, int);
int /*<<< orphan*/ printf(char *, int, ...);
int compare_buffers(int round, long ret_outer, long ret_inner,
                    const char *outer, const char *inner) {
  int ret = 0;
  if (ret_outer != ret_inner) {
    printf("Round %d: return values differ (outer: %ld inner: %ld)\n", round,
           ret_outer, ret_inner);
    ret++;
  }
  if (memcmp(outer, inner, 2048)) {
    printf("Round %d strings differ:\n - outer: %s\n - inner: %s\n", round,
           outer, inner);
    ret++;
  }
  if (ret == 0)
    printf("Round %d success: %s\n", round, outer);
  return ret;
}


x86 assembly (clang, -O0):
<compare_buffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1172 <compare_buffers+0x52>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x800,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11b0 <compare_buffers+0x90>
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11cf <compare_buffers+0xaf>
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_buffers>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,%rcx
mov    %edi,%r14d
cmp    %rdx,%rsi
jne    116a <compare_buffers+0x4a>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x800,%edx
call   1040 <memcmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1198 <compare_buffers+0x78>
lea    0xf13(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b6 <compare_buffers+0x96>
mov    %rsi,%rdx
lea    0xe8c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x800,%edx
call   1040 <memcmp@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     11b1 <compare_buffers+0x91>
lea    0xe99(%rip),%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b6 <compare_buffers+0x96>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Round %d: return values differ (outer: %ld inner: %ld)\0A\00"
@.str.1 = [52 x i8] c"Round %d strings differ:\0A - outer: %s\0A - inner: %s\0A\00"
@.str.2 = [22 x i8] c"Round %d success: %s\0A\00"
define i32 @compare_buffers(i32 %0, i64 %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 0, i32* %11
%12 = load i64, i64* %7
%13 = load i64, i64* %8
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %5
%16 = load i32, i32* %6
%17 = load i64, i64* %7
%18 = load i64, i64* %8
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %16, i64 %17, i64 %18)
%20 = load i32, i32* %11
%21 = add nsw i32 %20, 1
store i32 %21, i32* %11
br label %22
22: ; preds = %15, %5
%23 = load i8*, i8** %9
%24 = load i8*, i8** %10
%25 = call i64 @memcmp(i8* %23, i8* %24, i32 2048)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* %6
%29 = load i8*, i8** %9
%30 = load i8*, i8** %10
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* %29, i8* %30)
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
br label %34
34: ; preds = %27, %22
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* %6
%39 = load i8*, i8** %9
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %38, i8* %39)
br label %41
41: ; preds = %37, %34
%42 = load i32, i32* %11
ret i32 %42
}

LLVM IR (-O2):
@.str = [56 x i8] c"Round %d: return values differ (outer: %ld inner: %ld)\0A\00"
@.str.1 = [52 x i8] c"Round %d strings differ:\0A - outer: %s\0A - inner: %s\0A\00"
@.str.2 = [22 x i8] c"Round %d success: %s\0A\00"
define i32 @compare_buffers(i32 %0, i64 %1, i64 %2, i8* %3, i8* %4) {
%6 = icmp eq i64 %1, %2
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = tail call i64 @memcmp(i8* %3, i8* %4, i32 2048)
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %14
10: ; preds = %5
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %0, i64 %1, i64 %2)
%12 = tail call i64 @memcmp(i8* %3, i8* %4, i32 2048)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %10, %7
%15 = phi i32 [ 2, %10 ], [ 1, %7 ]
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %3, i8* %4)
br label %19
17: ; preds = %7
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %3)
br label %19
19: ; preds = %10, %14, %17
%20 = phi i32 [ %15, %14 ], [ 0, %17 ], [ 1, %10 ]
ret i32 %20
}