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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ strcmp(char *, char *);
int compare_file(const char *outfn, const char *newfn) {
  FILE *old_f, *new_f;
  char oldbuf[2048], newbuf[2048], *oldcp, *newcp;
  int retval;
  old_f = fopen(outfn, "r");
  if (!old_f)
    return 0;
  new_f = fopen(newfn, "r");
  if (!new_f) {
    fclose(old_f);
    return 0;
  }
  while (1) {
    oldcp = fgets(oldbuf, sizeof(oldbuf), old_f);
    newcp = fgets(newbuf, sizeof(newbuf), new_f);
    if (!oldcp && !newcp) {
      retval = 1;
      break;
    }
    if (!oldcp || !newcp || strcmp(oldbuf, newbuf)) {
      retval = 0;
      break;
    }
  }
  fclose(old_f);
  fclose(new_f);
  return retval;
}


x86 assembly (clang, -O0):
<compare_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117e <compare_file+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1282 <compare_file+0x142>
mov    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b2 <compare_file+0x72>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1282 <compare_file+0x142>
jmp    11b7 <compare_file+0x77>
lea    -0x830(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
mov    %rax,-0x1038(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
mov    %rax,-0x1040(%rbp)
cmpq   $0x0,-0x1038(%rbp)
jne    121a <compare_file+0xda>
cmpq   $0x0,-0x1040(%rbp)
jne    121a <compare_file+0xda>
movl   $0x1,-0x1044(%rbp)
jmp    1267 <compare_file+0x127>
cmpq   $0x0,-0x1038(%rbp)
je     1253 <compare_file+0x113>
cmpq   $0x0,-0x1040(%rbp)
je     1253 <compare_file+0x113>
lea    -0x830(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1262 <compare_file+0x122>
movl   $0x0,-0x1044(%rbp)
jmp    1267 <compare_file+0x127>
jmp    11b7 <compare_file+0x77>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1044(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r14
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1201 <compare_file+0xc1>
mov    %rax,%r13
lea    0xe8b(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e7 <compare_file+0xa7>
mov    %rax,%r14
lea    0x800(%rsp),%r15
mov    %rsp,%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x800,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rcx
or     %rax,%rcx
je     11ec <compare_file+0xac>
test   %rbx,%rbx
je     11f1 <compare_file+0xb1>
test   %rax,%rax
je     11f1 <compare_file+0xb1>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a0 <compare_file+0x60>
jmp    11f1 <compare_file+0xb1>
mov    %r13,%rdi
jmp    11fc <compare_file+0xbc>
mov    $0x1,%ebp
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @compare_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [2048 x i8]
%9 = alloca [2048 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %2
store i32 0, i32* %3
br label %59
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i32*, i32** %6
%25 = call i32 @fclose(i32* %24)
store i32 0, i32* %3
br label %59
26: ; preds = %18
br label %27
27: ; preds = %26, %52
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%29 = load i32*, i32** %6
%30 = call i8* @fgets(i8* %28, i32 2048, i32* %29)
store i8* %30, i8** %10
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%32 = load i32*, i32** %7
%33 = call i8* @fgets(i8* %31, i32 2048, i32* %32)
store i8* %33, i8** %11
%34 = load i8*, i8** %10
%35 = icmp ne i8* %34, null
br i1 %35, label %40, label %36
36: ; preds = %27
%37 = load i8*, i8** %11
%38 = icmp ne i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %36
store i32 1, i32* %12
br label %53
40: ; preds = %36, %27
%41 = load i8*, i8** %10
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = load i8*, i8** %11
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%49 = call i64 @strcmp(i8* %47, i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46, %43, %40
store i32 0, i32* %12
br label %53
52: ; preds = %46
br label %27
53: ; preds = %51, %39
%54 = load i32*, i32** %6
%55 = call i32 @fclose(i32* %54)
%56 = load i32*, i32** %7
%57 = call i32 @fclose(i32* %56)
%58 = load i32, i32* %12
store i32 %58, i32* %3
br label %59
59: ; preds = %53, %23, %17
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @compare_file(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %29, label %9
9: ; preds = %2
%10 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @fclose(i32* %7)
br label %29
14: ; preds = %9, %22
%15 = call i8* @fgets(i8* %5, i32 2048, i32* %7)
%16 = call i8* @fgets(i8* %6, i32 2048, i32* %10)
%17 = icmp ne i8* %15, null
%18 = icmp ne i8* %16, null
%19 = or i1 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = and i1 %17, %18
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = call i64 @strcmp(i8* %5, i8* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %14, label %25
25: ; preds = %20, %22, %14
%26 = phi i32 [ 1, %14 ], [ 0, %22 ], [ 0, %20 ]
%27 = call i32 @fclose(i32* %7)
%28 = call i32 @fclose(i32* %10)
br label %29
29: ; preds = %2, %25, %12
%30 = phi i32 [ %26, %25 ], [ 0, %12 ], [ 0, %2 ]
ret i32 %30
}