#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 ape_header {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int find_ape_tag_slow(int);
int lseek(int, int, int /*<<< orphan*/);
int read_header(int, struct ape_header *);
int find_ape_tag(int fd, struct ape_header *h, int slow) {
  int pos;
  if (lseek(fd, -(32), SEEK_END) == -1)
    return 0;
  if (read_header(fd, h))
    return 1;
  if (lseek(fd, -((32) + 128), SEEK_END) == -1)
    return 0;
  if (read_header(fd, h))
    return 1;
  if (!slow)
    return 0;
  pos = find_ape_tag_slow(fd);
  if (pos == -1)
    return 0;
  if (lseek(fd, pos, SEEK_SET) == -1)
    return 0;
  return read_header(fd, h);
}


x86 assembly (clang, -O0):
<find_ape_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffe0,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    116d <find_ape_tag+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1249 <find_ape_tag+0x119>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <read_header@plt>
cmp    $0x0,%eax
je     118e <find_ape_tag+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    1249 <find_ape_tag+0x119>
mov    -0x8(%rbp),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    $0xffffff60,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11b9 <find_ape_tag+0x89>
movl   $0x0,-0x4(%rbp)
jmp    1249 <find_ape_tag+0x119>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <read_header@plt>
cmp    $0x0,%eax
je     11da <find_ape_tag+0xaa>
movl   $0x1,-0x4(%rbp)
jmp    1249 <find_ape_tag+0x119>
cmpl   $0x0,-0x14(%rbp)
jne    11f0 <find_ape_tag+0xc0>
movl   $0x0,-0x4(%rbp)
jmp    1249 <find_ape_tag+0x119>
mov    -0x8(%rbp),%edi
call   1030 <find_ape_tag_slow@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1211 <find_ape_tag+0xe1>
movl   $0x0,-0x4(%rbp)
jmp    1249 <find_ape_tag+0x119>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    123a <find_ape_tag+0x10a>
movl   $0x0,-0x4(%rbp)
jmp    1249 <find_ape_tag+0x119>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <read_header@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_ape_tag>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2ea1(%rip),%r12
mov    (%r12),%edx
mov    $0xffffffe0,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     11cf <find_ape_tag+0x9f>
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <read_header@plt>
mov    $0x1,%ebx
test   %eax,%eax
jne    11d1 <find_ape_tag+0xa1>
mov    (%r12),%edx
mov    %ebp,%edi
mov    $0xffffff60,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     11cf <find_ape_tag+0x9f>
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <read_header@plt>
test   %eax,%eax
jne    11d1 <find_ape_tag+0xa1>
test   %r14d,%r14d
je     11cf <find_ape_tag+0x9f>
mov    %ebp,%edi
call   1030 <find_ape_tag_slow@plt>
cmp    $0xffffffff,%eax
je     11cf <find_ape_tag+0x9f>
mov    0x2e30(%rip),%rcx
mov    (%rcx),%edx
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <lseek@plt>
mov    $0x0,%ebx
cmp    $0xffffffff,%eax
je     11d1 <find_ape_tag+0xa1>
mov    %ebp,%edi
mov    %r15,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <read_header@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ape_header = type { i32 }
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @find_ape_tag(i32 %0, %struct.ape_header* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.ape_header*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store %struct.ape_header* %1, %struct.ape_header** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i32, i32* @SEEK_END
%11 = call i32 @lseek(i32 %9, i32 -32, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 0, i32* %4
br label %53
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load %struct.ape_header*, %struct.ape_header** %6
%17 = call i32 @read_header(i32 %15, %struct.ape_header* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 1, i32* %4
br label %53
20: ; preds = %14
%21 = load i32, i32* %5
%22 = load i32, i32* @SEEK_END
%23 = call i32 @lseek(i32 %21, i32 -160, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 0, i32* %4
br label %53
26: ; preds = %20
%27 = load i32, i32* %5
%28 = load %struct.ape_header*, %struct.ape_header** %6
%29 = call i32 @read_header(i32 %27, %struct.ape_header* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 1, i32* %4
br label %53
32: ; preds = %26
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %32
store i32 0, i32* %4
br label %53
36: ; preds = %32
%37 = load i32, i32* %5
%38 = call i32 @find_ape_tag_slow(i32 %37)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %36
store i32 0, i32* %4
br label %53
42: ; preds = %36
%43 = load i32, i32* %5
%44 = load i32, i32* %8
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @lseek(i32 %43, i32 %44, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 0, i32* %4
br label %53
49: ; preds = %42
%50 = load i32, i32* %5
%51 = load %struct.ape_header*, %struct.ape_header** %6
%52 = call i32 @read_header(i32 %50, %struct.ape_header* %51)
store i32 %52, i32* %4
br label %53
53: ; preds = %49, %48, %41, %35, %31, %25, %19, %13
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
%struct.ape_header = type { i32 }
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @find_ape_tag(i32 %0, %struct.ape_header* %1, i32 %2) {
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @lseek(i32 %0, i32 -32, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %28, label %7
7: ; preds = %3
%8 = tail call i32 @read_header(i32 %0, %struct.ape_header* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @lseek(i32 %0, i32 -160, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %28, label %14
14: ; preds = %10
%15 = tail call i32 @read_header(i32 %0, %struct.ape_header* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = icmp eq i32 %2, 0
br i1 %18, label %28, label %19
19: ; preds = %17
%20 = tail call i32 @find_ape_tag_slow(i32 %0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @lseek(i32 %0, i32 %20, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @read_header(i32 %0, %struct.ape_header* %1)
br label %28
28: ; preds = %22, %19, %17, %14, %10, %7, %3, %26
%29 = phi i32 [ %27, %26 ], [ 0, %3 ], [ 1, %7 ], [ 0, %10 ], [ 1, %14 ], [ 0, %17 ], [ 0, %19 ], [ 0, %22 ]
ret i32 %29
}