#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 {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf1;

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ fstat(int, struct stat *);
scalar_t__ memcmp(char *, char *, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int AwFileCmp(char *f1, char *f2) {
  int fd1 = -1;
  int fd2 = -1;
  struct stat st1;
  struct stat st2;
  char buf1[1024];
  char buf2[1024];
  int ret;
  int sz;
  ret = 0;
  fd1 = open(f1, 0);
  if (fd1 < 0) {
    ret = -1;
    goto fctend;
  }
  if (fstat(fd1, &st1) < 0) {
    ret = -11;
    goto fctend;
  }
  fd2 = open(f2, 0);
  if (fd2 < 0) {
    ret = -2;
    goto fctend;
  }
  if (fstat(fd2, &st2) < 0) {
    ret = -22;
    goto fctend;
  }
  if (st1.st_size != st2.st_size) {
    ret = 1;
    goto fctend;
  }
  while ((sz = read(fd1, buf1, sizeof(buf1))) > 0) {
    if (read(fd2, buf2, sizeof(buf2)) != sz) {
      ret = -222;
      goto fctend;
    }
    if (memcmp(buf1, buf2, sz)) {
      ret = 2;
      goto fctend;
    }
  }
  if (sz < 0) {
    ret = -111;
    goto fctend;
  }
fctend:
  if (fd1 > 0)
    close(fd1);
  if (fd2 > 0)
    close(fd2);
  return ret;
}


x86 assembly (clang, -O0):
<AwFileCmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x834(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a2 <AwFileCmp+0x52>
movl   $0xffffffff,-0x834(%rbp)
ff ff ff
jmp    12df <AwFileCmp+0x18f>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <fstat@plt>
cmp    $0x0,%rax
jge    11c7 <AwFileCmp+0x77>
movl   $0xfffffff5,-0x834(%rbp)
ff ff ff
jmp    12df <AwFileCmp+0x18f>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ee <AwFileCmp+0x9e>
movl   $0xfffffffe,-0x834(%rbp)
ff ff ff
jmp    12df <AwFileCmp+0x18f>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1070 <fstat@plt>
cmp    $0x0,%rax
jge    1213 <AwFileCmp+0xc3>
movl   $0xffffffea,-0x834(%rbp)
ff ff ff
jmp    12df <AwFileCmp+0x18f>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1230 <AwFileCmp+0xe0>
movl   $0x1,-0x834(%rbp)
jmp    12df <AwFileCmp+0x18f>
jmp    1235 <AwFileCmp+0xe5>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x838(%rbp)
cmp    $0x0,%eax
jle    12be <AwFileCmp+0x16e>
mov    -0x18(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cmp    -0x838(%rbp),%eax
je     1287 <AwFileCmp+0x137>
movl   $0xffffff22,-0x834(%rbp)
ff ff ff
jmp    12df <AwFileCmp+0x18f>
lea    -0x430(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    -0x838(%rbp),%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     12b9 <AwFileCmp+0x169>
movl   $0x2,-0x834(%rbp)
jmp    12df <AwFileCmp+0x18f>
jmp    1235 <AwFileCmp+0xe5>
cmpl   $0x0,-0x838(%rbp)
jge    12da <AwFileCmp+0x18a>
movl   $0xffffff91,-0x834(%rbp)
ff ff ff
jmp    12df <AwFileCmp+0x18f>
jmp    12df <AwFileCmp+0x18f>
cmpl   $0x0,-0x14(%rbp)
jle    12f1 <AwFileCmp+0x1a1>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jle    1303 <AwFileCmp+0x1b3>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x834(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AwFileCmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    %rsi,%rbp
xor    %esi,%esi
call   1060 <open@plt>
test   %eax,%eax
js     1223 <AwFileCmp+0xd3>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1070 <fstat@plt>
test   %rax,%rax
js     122b <AwFileCmp+0xdb>
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1239 <AwFileCmp+0xe9>
mov    %rsp,%rsi
mov    %r14d,%edi
call   1070 <fstat@plt>
test   %rax,%rax
js     1241 <AwFileCmp+0xf1>
mov    0x8(%rsp),%rax
mov    $0x1,%r15d
cmp    (%rsp),%rax
jne    125b <AwFileCmp+0x10b>
lea    0x410(%rsp),%r15
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1249 <AwFileCmp+0xf9>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cmp    %ebp,%eax
jne    1255 <AwFileCmp+0x105>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11e0 <AwFileCmp+0x90>
mov    $0x2,%r15d
jmp    125b <AwFileCmp+0x10b>
mov    $0xffffffff,%r15d
jmp    1273 <AwFileCmp+0x123>
mov    $0xfffffff5,%r15d
mov    $0xffffffff,%r14d
jmp    125b <AwFileCmp+0x10b>
mov    $0xfffffffe,%r15d
jmp    125b <AwFileCmp+0x10b>
mov    $0xffffffea,%r15d
jmp    125b <AwFileCmp+0x10b>
mov    $0xffffff91,%r15d
cmove  %ebp,%r15d
jmp    125b <AwFileCmp+0x10b>
mov    $0xffffff22,%r15d
test   %ebx,%ebx
jle    1266 <AwFileCmp+0x116>
mov    %ebx,%edi
call   1030 <close@plt>
test   %r14d,%r14d
jle    1273 <AwFileCmp+0x123>
mov    %r14d,%edi
call   1030 <close@plt>
mov    %r15d,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
define i32 @AwFileCmp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca %struct.stat
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 -1, i32* %5
store i32 -1, i32* %6
store i32 0, i32* %11
%13 = load i8*, i8** %3
%14 = call i32 @open(i8* %13, i32 0)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %11
br label %67
18: ; preds = %2
%19 = load i32, i32* %5
%20 = call i64 @fstat(i32 %19, %struct.stat* %7)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -11, i32* %11
br label %67
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = call i32 @open(i8* %24, i32 0)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -2, i32* %11
br label %67
29: ; preds = %23
%30 = load i32, i32* %6
%31 = call i64 @fstat(i32 %30, %struct.stat* %8)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 -22, i32* %11
br label %67
34: ; preds = %29
%35 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%38 = load i64, i64* %37
%39 = icmp ne i64 %36, %38
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 1, i32* %11
br label %67
41: ; preds = %34
br label %42
42: ; preds = %61, %41
%43 = load i32, i32* %5
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%45 = call i32 @read(i32 %43, i8* %44, i32 1024)
store i32 %45, i32* %12
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %62
47: ; preds = %42
%48 = load i32, i32* %6
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%50 = call i32 @read(i32 %48, i8* %49, i32 1024)
%51 = load i32, i32* %12
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %47
store i32 -222, i32* %11
br label %67
54: ; preds = %47
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%57 = load i32, i32* %12
%58 = call i64 @memcmp(i8* %55, i8* %56, i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %54
store i32 2, i32* %11
br label %67
61: ; preds = %54
br label %42
62: ; preds = %42
%63 = load i32, i32* %12
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %62
store i32 -111, i32* %11
br label %67
66: ; preds = %62
br label %67
67: ; preds = %66, %65, %60, %53, %40, %33, %28, %22, %17
%68 = load i32, i32* %5
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i32, i32* %5
%72 = call i32 @close(i32 %71)
br label %73
73: ; preds = %70, %67
%74 = load i32, i32* %6
%75 = icmp sgt i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
br label %79
79: ; preds = %76, %73
%80 = load i32, i32* %11
ret i32 %80
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i32 @AwFileCmp(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = bitcast %struct.stat* %3 to i8*
%8 = bitcast %struct.stat* %4 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = tail call i32 @open(i8* %0, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %50, label %13
13: ; preds = %2
%14 = call i64 @fstat(i32 %11, %struct.stat* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %40, label %16
16: ; preds = %13
%17 = tail call i32 @open(i8* %1, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %40, label %19
19: ; preds = %16
%20 = call i64 @fstat(i32 %17, %struct.stat* %4)
%21 = icmp slt i64 %20, 0
br i1 %21, label %40, label %22
22: ; preds = %19
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%24 = load i64, i64* %23
%25 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%26 = load i64, i64* %25
%27 = icmp eq i64 %24, %26
br i1 %27, label %28, label %40
28: ; preds = %22, %34
%29 = call i32 @read(i32 %11, i8* %9, i32 1024)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = call i32 @read(i32 %17, i8* %10, i32 1024)
%33 = icmp eq i32 %32, %29
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = call i64 @memcmp(i8* %9, i8* %10, i32 %29)
%36 = icmp eq i64 %35, 0
br i1 %36, label %28, label %40
37: ; preds = %28
%38 = icmp eq i32 %29, 0
%39 = select i1 %38, i32 0, i32 -111
br label %40
40: ; preds = %34, %31, %37, %22, %19, %16, %13
%41 = phi i32 [ -1, %13 ], [ %17, %16 ], [ %17, %19 ], [ %17, %22 ], [ %17, %37 ], [ %17, %31 ], [ %17, %34 ]
%42 = phi i32 [ -11, %13 ], [ -2, %16 ], [ -22, %19 ], [ 1, %22 ], [ %39, %37 ], [ 2, %34 ], [ -222, %31 ]
%43 = icmp sgt i32 %11, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @close(i32 %11)
br label %46
46: ; preds = %44, %40
%47 = icmp sgt i32 %41, 0
br i1 %47, label %48, label %50
48: ; preds = %46
%49 = call i32 @close(i32 %41)
br label %50
50: ; preds = %2, %48, %46
%51 = phi i32 [ %42, %48 ], [ %42, %46 ], [ -1, %2 ]
ret i32 %51
}