#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ stat(char const *, struct stat *);
int files_differ(const char *name1, const char *name2) {
  FILE *x1, *x2;
  struct stat sb;
  if ((stat(name1, &sb) < 0) || (!S_ISREG(sb.st_mode)))
    return 2;
  if ((stat(name2, &sb) < 0) || (!S_ISREG(sb.st_mode)))
    return 2;
  x1 = fopen(name1, "rb");
  x2 = fopen(name2, "rb");
  if (x1 && x2) {
    int result = 0;
    int c1, c2;
    do {
      c1 = getc(x1);
      c2 = getc(x2);
      if (c1 == EOF) {
        if (c2 == EOF) {
          result = 0;
          break;
        } else {
          result = 1;
          break;
        }
      } else if (c2 == EOF) {
        result = 1;
        break;
      } else if (c1 != c2) {
        result = 1;
        break;
      }
    } while (1);
    fclose(x1);
    fclose(x2);
    return result;
  } else {
    if (x1)
      fclose(x1);
    if (x2)
      fclose(x2);
    return 2;
  }
}


x86 assembly (clang, -O0):
<files_differ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jl     1188 <files_differ+0x38>
mov    -0x30(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1194 <files_differ+0x44>
movl   $0x2,-0x4(%rbp)
jmp    1301 <files_differ+0x1b1>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jl     11bc <files_differ+0x6c>
mov    -0x30(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%eax
jne    11c8 <files_differ+0x78>
movl   $0x2,-0x4(%rbp)
jmp    1301 <files_differ+0x1b1>
mov    -0x10(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12d2 <files_differ+0x182>
cmpq   $0x0,-0x28(%rbp)
je     12d2 <files_differ+0x182>
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%eax
jne    1261 <files_differ+0x111>
mov    -0x3c(%rbp),%eax
mov    0x2da7(%rip),%rcx
cmp    (%rcx),%eax
jne    1255 <files_differ+0x105>
movl   $0x0,-0x34(%rbp)
jmp    12b5 <files_differ+0x165>
movl   $0x1,-0x34(%rbp)
jmp    12b5 <files_differ+0x165>
mov    -0x3c(%rbp),%eax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%eax
jne    127f <files_differ+0x12f>
movl   $0x1,-0x34(%rbp)
jmp    12b5 <files_differ+0x165>
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
je     1297 <files_differ+0x147>
movl   $0x1,-0x34(%rbp)
jmp    12b5 <files_differ+0x165>
jmp    129c <files_differ+0x14c>
jmp    12a1 <files_differ+0x151>
jmp    12a6 <files_differ+0x156>
mov    $0x1,%al
test   $0x1,%al
jne    120d <files_differ+0xbd>
jmp    12b5 <files_differ+0x165>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1301 <files_differ+0x1b1>
cmpq   $0x0,-0x20(%rbp)
je     12e6 <files_differ+0x196>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     12fa <files_differ+0x1aa>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<files_differ>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
mov    $0x2,%ebx
test   %rax,%rax
js     1244 <files_differ+0xf4>
mov    0x8(%rsp),%edi
call   1050 <S_ISREG@plt>
test   %eax,%eax
je     1244 <files_differ+0xf4>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
test   %rax,%rax
js     1244 <files_differ+0xf4>
mov    0x8(%rsp),%edi
call   1050 <S_ISREG@plt>
test   %eax,%eax
je     1244 <files_differ+0xf4>
lea    0xe47(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %r15,%r15
je     1214 <files_differ+0xc4>
test   %r14,%r14
je     1214 <files_differ+0xc4>
mov    0x2e02(%rip),%r12
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1070 <getc@plt>
mov    (%r12),%ecx
cmp    %ecx,%ebp
je     122d <files_differ+0xdd>
cmp    %eax,%ebp
jne    1234 <files_differ+0xe4>
cmp    %ecx,%eax
jne    11f0 <files_differ+0xa0>
jmp    1234 <files_differ+0xe4>
test   %r15,%r15
je     1221 <files_differ+0xd1>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x2,%ebx
test   %r14,%r14
jne    123c <files_differ+0xec>
jmp    1244 <files_differ+0xf4>
xor    %ebx,%ebx
cmp    %ebp,%eax
setne  %bl
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
define i32 @files_differ(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %4
%13 = call i64 @stat(i8* %12, %struct.stat* %8)
%14 = icmp slt i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %2
%16 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISREG(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15, %2
store i32 2, i32* %3
br label %89
21: ; preds = %15
%22 = load i8*, i8** %5
%23 = call i64 @stat(i8* %22, %struct.stat* %8)
%24 = icmp slt i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @S_ISREG(i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25, %21
store i32 2, i32* %3
br label %89
31: ; preds = %25
%32 = load i8*, i8** %4
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i8*, i8** %5
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %35, i32** %7
%36 = load i32*, i32** %6
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %76
38: ; preds = %31
%39 = load i32*, i32** %7
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %76
41: ; preds = %38
store i32 0, i32* %9
br label %42
42: ; preds = %69, %41
%43 = load i32*, i32** %6
%44 = call i32 @getc(i32* %43)
store i32 %44, i32* %10
%45 = load i32*, i32** %7
%46 = call i32 @getc(i32* %45)
store i32 %46, i32* %11
%47 = load i32, i32* %10
%48 = load i32, i32* @EOF
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %56
50: ; preds = %42
%51 = load i32, i32* %11
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %50
store i32 0, i32* %9
br label %70
55: ; preds = %50
store i32 1, i32* %9
br label %70
56: ; preds = %42
%57 = load i32, i32* %11
%58 = load i32, i32* @EOF
%59 = icmp eq i32 %57, %58
br i1 %59, label %60, label %61
60: ; preds = %56
store i32 1, i32* %9
br label %70
61: ; preds = %56
%62 = load i32, i32* %10
%63 = load i32, i32* %11
%64 = icmp ne i32 %62, %63
br i1 %64, label %65, label %66
65: ; preds = %61
store i32 1, i32* %9
br label %70
66: ; preds = %61
br label %67
67: ; preds = %66
br label %68
68: ; preds = %67
br label %69
69: ; preds = %68
br i1 true, label %42, label %70
70: ; preds = %69, %65, %60, %55, %54
%71 = load i32*, i32** %6
%72 = call i32 @fclose(i32* %71)
%73 = load i32*, i32** %7
%74 = call i32 @fclose(i32* %73)
%75 = load i32, i32* %9
store i32 %75, i32* %3
br label %89
76: ; preds = %38, %31
%77 = load i32*, i32** %6
%78 = icmp ne i32* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
br label %82
82: ; preds = %79, %76
%83 = load i32*, i32** %7
%84 = icmp ne i32* %83, null
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i32*, i32** %7
%87 = call i32 @fclose(i32* %86)
br label %88
88: ; preds = %85, %82
store i32 2, i32* %3
br label %89
89: ; preds = %88, %70, %30, %20
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
define i32 @files_differ(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i64 @stat(i8* %0, %struct.stat* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %47, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @S_ISREG(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %47, label %12
12: ; preds = %7
%13 = call i64 @stat(i8* %1, %struct.stat* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %47, label %15
15: ; preds = %12
%16 = load i32, i32* %8
%17 = call i32 @S_ISREG(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %47, label %19
19: ; preds = %15
%20 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%21 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32* %20, null
%23 = icmp ne i32* %21, null
%24 = and i1 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %19, %33
%26 = call i32 @getc(i32* %20)
%27 = call i32 @getc(i32* %21)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = icmp ne i32 %27, %26
%32 = zext i1 %31 to i32
br label %37
33: ; preds = %25
%34 = icmp ne i32 %27, %28
%35 = icmp eq i32 %26, %27
%36 = and i1 %35, %34
br i1 %36, label %25, label %37
37: ; preds = %33, %30
%38 = phi i32 [ %32, %30 ], [ 1, %33 ]
%39 = call i32 @fclose(i32* %20)
br label %44
40: ; preds = %19
br i1 %22, label %41, label %43
41: ; preds = %40
%42 = call i32 @fclose(i32* %20)
br label %43
43: ; preds = %41, %40
br i1 %23, label %44, label %47
44: ; preds = %43, %37
%45 = phi i32 [ %38, %37 ], [ 2, %43 ]
%46 = call i32 @fclose(i32* %21)
br label %47
47: ; preds = %44, %43, %12, %15, %2, %7
%48 = phi i32 [ 2, %7 ], [ 2, %2 ], [ 2, %15 ], [ 2, %12 ], [ 2, %43 ], [ %45, %44 ]
ret i32 %48
}