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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ ftello(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char Dat2Check(char *path) {
  FILE *file = fopen(path, "rb");
  uint64_t arcsize;
  uint64_t t64 = ftello(file);
  uint32_t t32;
  int e;
  fseeko(file, -4, SEEK_END);
  e = fread(&t32, 4, 1, file);
  ;
  if (!e)
    fprintf(stderr, "Dat2Check failed to read dword at 0x%lx\n", t64);
  arcsize = ftello(file);
  fclose(file);
  t64 = t32;
  if (t64 == arcsize)
    return 2;
  else
    return 0;
}


x86 assembly (clang, -O0):
<Dat2Check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ftello@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   1070 <fseeko@plt>
mov    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11e1 <Dat2Check+0x81>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ftello@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1216 <Dat2Check+0xb6>
movb   $0x2,-0x1(%rbp)
jmp    121a <Dat2Check+0xba>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Dat2Check>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <ftello@plt>
mov    %rax,%r14
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffffc,%esi
call   1070 <fseeko@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    11c5 <Dat2Check+0x65>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <ftello@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    %r14,(%rsp)
sete   %al
add    %al,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Dat2Check failed to read dword at 0x%lx\0A\00"
define signext i8 @Dat2Check(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = call i64 @ftello(i32* %11)
store i64 %12, i64* %6
%13 = load i32*, i32** %4
%14 = load i32, i32* @SEEK_END
%15 = call i32 @fseeko(i32* %13, i32 -4, i32 %14)
%16 = load i32*, i32** %4
%17 = call i32 @fread(i64* %7, i32 4, i32 1, i32* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = load i64, i64* %6
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %22)
br label %24
24: ; preds = %20, %1
%25 = load i32*, i32** %4
%26 = call i64 @ftello(i32* %25)
store i64 %26, i64* %5
%27 = load i32*, i32** %4
%28 = call i32 @fclose(i32* %27)
%29 = load i64, i64* %7
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = load i64, i64* %5
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %24
store i8 2, i8* %2
br label %35
34: ; preds = %24
store i8 0, i8* %2
br label %35
35: ; preds = %34, %33
%36 = load i8, i8* %2
ret i8 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Dat2Check failed to read dword at 0x%lx\0A\00"
define signext i8 @Dat2Check(i8* nocapture %0) {
%2 = alloca i64
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @ftello(i32* %3)
%5 = bitcast i64* %2 to i8*
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseeko(i32* %3, i32 -4, i32 %6)
%8 = call i32 @fread(i64* %2, i32 4, i32 1, i32* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %4)
br label %13
13: ; preds = %10, %1
%14 = tail call i64 @ftello(i32* %3)
%15 = tail call i32 @fclose(i32* %3)
%16 = load i64, i64* %2
%17 = icmp eq i64 %16, %14
%18 = select i1 %17, i8 2, i8 0
ret i8 %18
}