#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 */

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int is_tracBINARY(char *file) {
  char ver;
  int fd, ret;
  if (file == 0)
    return 0;
  fd = open(file, O_RDONLY);
  if (fd < 0)
    return -1;
  do {
    ret = read(fd, &ver, 1);
  } while (ret < 0 && errno == EINTR);
  close(fd);
  if (ret <= 0)
    return -1;
  if (ver != 2)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_tracBINARY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <is_tracBINARY+0x23>
movl   $0x0,-0x4(%rbp)
jmp    1209 <is_tracBINARY+0xd9>
mov    -0x10(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    117e <is_tracBINARY+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <is_tracBINARY+0xd9>
jmp    1183 <is_tracBINARY+0x53>
mov    -0x18(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jge    11c0 <is_tracBINARY+0x90>
mov    0x2e2b(%rip),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1183 <is_tracBINARY+0x53>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     11e9 <is_tracBINARY+0xb9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <is_tracBINARY+0xd9>
movsbl -0x11(%rbp),%eax
cmp    $0x2,%eax
je     1202 <is_tracBINARY+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    1209 <is_tracBINARY+0xd9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_tracBINARY>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a8 <is_tracBINARY+0x78>
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     11ab <is_tracBINARY+0x7b>
mov    %eax,%ebp
lea    0x7(%rsp),%r15
mov    0x2e72(%rip),%r12
mov    0x2e63(%rip),%r13
nopl   (%rax)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    118f <is_tracBINARY+0x5f>
mov    0x0(%r13),%rax
cmp    %rax,(%r12)
je     1170 <is_tracBINARY+0x40>
mov    %ebp,%edi
call   1030 <close@plt>
test   %ebx,%ebx
jle    11ab <is_tracBINARY+0x7b>
xor    %r14d,%r14d
cmpb   $0x2,0x7(%rsp)
sete   %r14b
jmp    11ab <is_tracBINARY+0x7b>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @is_tracBINARY(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %42
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 -1, i32* %2
br label %42
17: ; preds = %10
br label %18
18: ; preds = %28, %17
%19 = load i32, i32* %5
%20 = call i32 @read(i32 %19, i8* %4, i32 1)
store i32 %20, i32* %6
br label %21
21: ; preds = %18
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp eq i64 %25, %26
br label %28
28: ; preds = %24, %21
%29 = phi i1 [ false, %21 ], [ %27, %24 ]
br i1 %29, label %18, label %30
30: ; preds = %28
%31 = load i32, i32* %5
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %6
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 -1, i32* %2
br label %42
36: ; preds = %30
%37 = load i8, i8* %4
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 2
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 0, i32* %2
br label %42
41: ; preds = %36
store i32 1, i32* %2
br label %42
42: ; preds = %41, %40, %35, %16, %9
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @is_tracBINARY(i8* %0) {
%2 = alloca i8
%3 = icmp eq i8* %0, null
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %4, %8
%9 = call i32 @read(i32 %6, i8* %2, i32 1)
%10 = icmp slt i32 %9, 0
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %8, label %15
15: ; preds = %8
%16 = tail call i32 @close(i32 %6)
%17 = icmp slt i32 %9, 1
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i8, i8* %2
%20 = icmp eq i8 %19, 2
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %18, %15, %4, %1
%23 = phi i32 [ 0, %1 ], [ -1, %4 ], [ -1, %15 ], [ %21, %18 ]
ret i32 %23
}