#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*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
unsigned char *malloc(int);
int /*<<< orphan*/ memcmp(unsigned char *, unsigned char *, int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char **, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char **, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int f1, f2, c1, c2;
  char err[50];
  unsigned char *buf1, *buf2;
  if (argc != 3) {
    sprintf(err, "Usage: %s hdnew.img hdref.img\n", argv[0]);
    write(2, &err, strlen(err));
    exit(1);
  }
  f1 = open(argv[1], O_RDONLY);
  if (f1 < 0) {
    sprintf(err, "Could not open file %s\n", argv[1]);
    write(2, &err, strlen(err));
    exit(1);
  }
  f2 = open(argv[2], O_RDONLY);
  if (f2 < 0) {
    sprintf(err, "Could not open file %s\n", argv[2]);
    write(2, &err, strlen(err));
    exit(1);
  }
  buf1 = malloc(131072);
  if (!buf1) {
    sprintf(err, "Could not allocate 128kb of memory for the 1st buffer\n");
    write(2, &err, strlen(err));
    exit(1);
  }
  buf2 = malloc(131072);
  if (!buf2) {
    sprintf(err, "Could not allocate 128kb of memory for the 2nd buffer\n");
    write(2, &err, strlen(err));
    exit(1);
  }
  c1 = read(f1, &buf1, 131072);
  c2 = read(f2, &buf2, 131072);
  memcmp(buf1, buf2, 131072);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e7 <main+0x67>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    124f <main+0xcf>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12bd <main+0x13d>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x20000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1319 <main+0x199>
lea    -0x60(%rbp),%rdi
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x20000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    1375 <main+0x1f5>
lea    -0x60(%rbp),%rdi
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    $0x20000,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x20000,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    $0x20000,%edx
call   1060 <memcmp@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1236 <main+0xb6>
mov    0x8(%rbx),%rdi
mov    0x2e49(%rip),%rbp
mov    0x0(%rbp),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1242 <main+0xc2>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    0x0(%rbp),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1248 <main+0xc8>
mov    %eax,%ebp
mov    $0x20000,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1264 <main+0xe4>
mov    $0x20000,%edi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1285 <main+0x105>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0x20000,%edx
call   1050 <read@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x20000,%edx
call   1050 <read@plt>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    $0x20000,%edx
call   1060 <memcmp@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rdx
lea    0xdc0(%rip),%rsi
jmp    1253 <main+0xd3>
mov    0x8(%rbx),%rdx
jmp    124c <main+0xcc>
mov    0x10(%rbx),%rdx
lea    0xdcc(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
jmp    12bd <main+0x13d>
movups 0xdec(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xdd0(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xdb4(%rip),%xmm0
jmp    12a4 <main+0x124>
movups 0xe02(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xde6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xdca(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0xa726566667562,%rax
mov    %rax,0x3f(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Usage: %s hdnew.img hdref.img\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
@.str.2 = [55 x i8] c"Could not allocate 128kb of memory for the 1st buffer\0A\00"
@.str.3 = [55 x i8] c"Could not allocate 128kb of memory for the 2nd buffer\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [50 x i8]
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %26
15: ; preds = %2
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = bitcast [50 x i8]* %10 to i8**
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 2, i8** %21, i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %26
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = bitcast [50 x i8]* %10 to i8**
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = call i32 @write(i32 2, i8** %40, i32 %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %26
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = load i32, i32* @O_RDONLY
%50 = call i32 @open(i8* %48, i32 %49)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %64
53: ; preds = %45
%54 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %57)
%59 = bitcast [50 x i8]* %10 to i8**
%60 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = call i32 @write(i32 2, i8** %59, i32 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %45
%65 = call i8* @malloc(i32 131072)
store i8* %65, i8** %11
%66 = load i8*, i8** %11
%67 = icmp ne i8* %66, null
br i1 %67, label %76, label %68
68: ; preds = %64
%69 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%70 = call i32 (i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%71 = bitcast [50 x i8]* %10 to i8**
%72 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%73 = call i32 @strlen(i8* %72)
%74 = call i32 @write(i32 2, i8** %71, i32 %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %64
%77 = call i8* @malloc(i32 131072)
store i8* %77, i8** %12
%78 = load i8*, i8** %12
%79 = icmp ne i8* %78, null
br i1 %79, label %88, label %80
80: ; preds = %76
%81 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%82 = call i32 (i8*, i8*, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%83 = bitcast [50 x i8]* %10 to i8**
%84 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%85 = call i32 @strlen(i8* %84)
%86 = call i32 @write(i32 2, i8** %83, i32 %85)
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %76
%89 = load i32, i32* %6
%90 = call i32 @read(i32 %89, i8** %11, i32 131072)
store i32 %90, i32* %8
%91 = load i32, i32* %7
%92 = call i32 @read(i32 %91, i8** %12, i32 131072)
store i32 %92, i32* %9
%93 = load i8*, i8** %11
%94 = load i8*, i8** %12
%95 = call i32 @memcmp(i8* %93, i8* %94, i32 131072)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Usage: %s hdnew.img hdref.img\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
@.str.2 = [55 x i8] c"Could not allocate 128kb of memory for the 1st buffer\0A\00"
@.str.3 = [55 x i8] c"Could not allocate 128kb of memory for the 2nd buffer\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = bitcast i8** %4 to i8*
%8 = bitcast i8** %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = bitcast [50 x i8]* %3 to i8**
%14 = call i32 @strlen(i8* %6)
%15 = call i32 @write(i32 2, i8** %13, i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i8* %19, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i8*, i8** %18
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = bitcast [50 x i8]* %3 to i8**
%27 = call i32 @strlen(i8* %6)
%28 = call i32 @write(i32 2, i8** %26, i32 %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_RDONLY
%34 = tail call i32 @open(i8* %32, i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %30
%37 = load i8*, i8** %31
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = bitcast [50 x i8]* %3 to i8**
%40 = call i32 @strlen(i8* %6)
%41 = call i32 @write(i32 2, i8** %39, i32 %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %30
%44 = tail call dereferenceable_or_null(131072) i8* @malloc(i32 131072)
store i8* %44, i8** %4
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = bitcast [50 x i8]* %3 to i8**
%48 = call i32 @strlen(i8* %6)
%49 = call i32 @write(i32 2, i8** %47, i32 %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %43
%52 = tail call dereferenceable_or_null(131072) i8* @malloc(i32 131072)
store i8* %52, i8** %5
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = bitcast [50 x i8]* %3 to i8**
%56 = call i32 @strlen(i8* %6)
%57 = call i32 @write(i32 2, i8** %55, i32 %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %51
%60 = call i32 @read(i32 %21, i8** %4, i32 131072)
%61 = call i32 @read(i32 %34, i8** %5, i32 131072)
%62 = load i8*, i8** %4
%63 = load i8*, i8** %5
%64 = tail call i32 @memcmp(i8* %62, i8* %63, i32 131072)
ret i32 0
}