#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)
    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    1279 <compare_file+0x139>
mov    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a9 <compare_file+0x69>
movl   $0x0,-0x4(%rbp)
jmp    1279 <compare_file+0x139>
jmp    11ae <compare_file+0x6e>
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    1211 <compare_file+0xd1>
cmpq   $0x0,-0x1040(%rbp)
jne    1211 <compare_file+0xd1>
movl   $0x1,-0x1044(%rbp)
jmp    125e <compare_file+0x11e>
cmpq   $0x0,-0x1038(%rbp)
je     124a <compare_file+0x10a>
cmpq   $0x0,-0x1040(%rbp)
je     124a <compare_file+0x10a>
lea    -0x830(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1259 <compare_file+0x119>
movl   $0x0,-0x1044(%rbp)
jmp    125e <compare_file+0x11e>
jmp    11ae <compare_file+0x6e>
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,%rbx
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11fc <compare_file+0xbc>
mov    %rax,%r12
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fc <compare_file+0xbc>
mov    %rax,%r14
lea    0x800(%rsp),%r15
mov    %rsp,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rcx
or     %rax,%rcx
je     11e7 <compare_file+0xa7>
test   %rbx,%rbx
je     11ec <compare_file+0xac>
test   %rax,%rax
je     11ec <compare_file+0xac>
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a0 <compare_file+0x60>
jmp    11ec <compare_file+0xac>
mov    $0x1,%ebp
mov    %r12,%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 %57
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 %24, label %23
23: ; preds = %18
store i32 0, i32* %3
br label %57
24: ; preds = %18
br label %25
25: ; preds = %24, %50
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%27 = load i32*, i32** %6
%28 = call i8* @fgets(i8* %26, i32 2048, i32* %27)
store i8* %28, i8** %10
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%30 = load i32*, i32** %7
%31 = call i8* @fgets(i8* %29, i32 2048, i32* %30)
store i8* %31, i8** %11
%32 = load i8*, i8** %10
%33 = icmp ne i8* %32, null
br i1 %33, label %38, label %34
34: ; preds = %25
%35 = load i8*, i8** %11
%36 = icmp ne i8* %35, null
br i1 %36, label %38, label %37
37: ; preds = %34
store i32 1, i32* %12
br label %51
38: ; preds = %34, %25
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i8*, i8** %11
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%47 = call i64 @strcmp(i8* %45, i8* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44, %41, %38
store i32 0, i32* %12
br label %51
50: ; preds = %44
br label %25
51: ; preds = %49, %37
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* %12
store i32 %56, i32* %3
br label %57
57: ; preds = %51, %23, %17
%58 = load i32, i32* %3
ret i32 %58
}

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 %27, 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 %27, label %12
12: ; preds = %9, %20
%13 = call i8* @fgets(i8* %5, i32 2048, i32* %7)
%14 = call i8* @fgets(i8* %6, i32 2048, i32* %10)
%15 = icmp ne i8* %13, null
%16 = icmp ne i8* %14, null
%17 = or i1 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = and i1 %15, %16
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = call i64 @strcmp(i8* %5, i8* %6)
%22 = icmp eq i64 %21, 0
br i1 %22, label %12, label %23
23: ; preds = %18, %20, %12
%24 = phi i32 [ 1, %12 ], [ 0, %20 ], [ 0, %18 ]
%25 = call i32 @fclose(i32* %7)
%26 = call i32 @fclose(i32* %10)
br label %27
27: ; preds = %9, %2, %23
%28 = phi i32 [ %24, %23 ], [ 0, %2 ], [ 0, %9 ]
ret i32 %28
}