#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *f1, *f2;
  int b1, b2, differs = 0;
  if (argc != 3) {
    fputs("Usage: cmp <file1> <file2>\n", stderr);
    return 1;
  }
  f1 = fopen(*++argv, "r");
  f2 = fopen(*++argv, "r");
  if (f1 == NULL || f2 == NULL) {
    perror("cmp");
    if (f1 != NULL)
      fclose(f1);
    if (f2 != NULL)
      fclose(f2);
    return 1;
  }
CMP_LOOP:
  b1 = getc(f1);
  b2 = getc(f2);
  if (b1 == b2) {
    if (b1 == EOF)
      goto CMP_LOOP_EQ_END;
    goto CMP_LOOP;
  }
  differs = 1;
CMP_LOOP_EQ_END:
  fclose(f1);
  fclose(f2);
  return differs;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1198 <main+0x48>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1298 <main+0x148>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f4 <main+0xa4>
cmpq   $0x0,-0x20(%rbp)
jne    1234 <main+0xe4>
lea    0xe23(%rip),%rdi
call   1060 <perror@plt>
cmpq   $0x0,-0x18(%rbp)
je     1214 <main+0xc4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     1228 <main+0xd8>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1298 <main+0x148>
jmp    1239 <main+0xe9>
mov    -0x18(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    1279 <main+0x129>
mov    -0x24(%rbp),%eax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
jne    1274 <main+0x124>
jmp    1280 <main+0x130>
jmp    1239 <main+0xe9>
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11bf <main+0x6f>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xeb2(%rip),%r14
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     11fd <main+0xad>
test   %r14,%r14
je     11fd <main+0xad>
mov    0x2e53(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1070 <getc@plt>
cmp    %eax,%ebp
jne    11db <main+0x8b>
cmp    (%r15),%ebp
jne    11a0 <main+0x50>
xor    %ebp,%ebp
jmp    11e0 <main+0x90>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe31(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%ebp
jmp    11f0 <main+0xa0>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1a(%rip),%rdi
call   1060 <perror@plt>
test   %rbx,%rbx
je     1216 <main+0xc6>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebp
test   %r14,%r14
jne    11e8 <main+0x98>
jmp    11f0 <main+0xa0>

LLVM IR (-O0):
@.str = [28 x i8] c"Usage: cmp <file1> <file2>\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"cmp\00"
@EOF = global i32 0
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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 1, i32* %3
br label %66
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i32 1
store i8** %18, i8*** %5
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i32 1
store i8** %22, i8*** %5
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %7
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %16
%28 = load i32*, i32** %7
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %44
30: ; preds = %27, %16
%31 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32*, i32** %6
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %34, %30
%38 = load i32*, i32** %7
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %40, %37
store i32 1, i32* %3
br label %66
44: ; preds = %27
br label %45
45: ; preds = %58, %44
%46 = load i32*, i32** %6
%47 = call i32 @getc(i32* %46)
store i32 %47, i32* %8
%48 = load i32*, i32** %7
%49 = call i32 @getc(i32* %48)
store i32 %49, i32* %9
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %59
53: ; preds = %45
%54 = load i32, i32* %8
%55 = load i32, i32* @EOF
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %53
br label %60
58: ; preds = %53
br label %45
59: ; preds = %45
store i32 1, i32* %10
br label %60
60: ; preds = %59, %57
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
%65 = load i32, i32* %10
store i32 %65, i32* %3
br label %66
66: ; preds = %60, %43, %13
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [28 x i8] c"Usage: cmp <file1> <file2>\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"cmp\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %35
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %10, null
%15 = icmp eq i32* %13, null
%16 = or i1 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %7
%18 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br i1 %14, label %21, label %19
19: ; preds = %17
%20 = tail call i32 @fclose(i32* %10)
br label %21
21: ; preds = %19, %17
br i1 %15, label %35, label %22
22: ; preds = %21
%23 = tail call i32 @fclose(i32* %13)
br label %35
24: ; preds = %7, %28
%25 = tail call i32 @getc(i32* %10)
%26 = tail call i32 @getc(i32* %13)
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %25, %29
br i1 %30, label %31, label %24
31: ; preds = %24, %28
%32 = phi i32 [ 0, %28 ], [ 1, %24 ]
%33 = tail call i32 @fclose(i32* %10)
%34 = tail call i32 @fclose(i32* %13)
br label %35
35: ; preds = %21, %22, %31, %4
%36 = phi i32 [ 1, %4 ], [ %32, %31 ], [ 1, %22 ], [ 1, %21 ]
ret i32 %36
}