#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int FindTIFFOffset(FILE *file, unsigned short num_entries,
                   unsigned short tiff_tag, unsigned short tiff_type) {
  unsigned short tag = 0;
  unsigned short type = 0;
  unsigned int offset = 0;
  int i;
  for (i = 0; i < num_entries; i++) {
    tag = (fgetc(file) << 8) | fgetc(file);
    if (tag == tiff_tag) {
      type = (fgetc(file) << 8) | fgetc(file);
      if (type == tiff_type) {
        offset = (fgetc(file) << 24) | (fgetc(file) << 16) |
                 (fgetc(file) << 8) | fgetc(file);
        offset = (fgetc(file) << 24) | (fgetc(file) << 16) |
                 (fgetc(file) << 8) | fgetc(file);
        fseek(file, offset, SEEK_SET);
        return 1;
      }
    } else {
      fseek(file, 10, SEEK_CUR);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<FindTIFFOffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %si,%dx
mov    %rdi,-0x10(%rbp)
mov    %dx,-0x12(%rbp)
mov    %cx,-0x14(%rbp)
mov    %ax,-0x16(%rbp)
movw   $0x0,-0x18(%rbp)
movw   $0x0,-0x1a(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
movzwl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    12bc <FindTIFFOffset+0x19c>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
shl    $0x8,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x18(%rbp)
movzwl -0x18(%rbp),%eax
movzwl -0x14(%rbp),%ecx
cmp    %ecx,%eax
jne    1292 <FindTIFFOffset+0x172>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
shl    $0x8,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
movzwl -0x16(%rbp),%ecx
cmp    %ecx,%eax
jne    128d <FindTIFFOffset+0x16d>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
shl    $0x18,%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
shl    $0x18,%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    0x2d5e(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c3 <FindTIFFOffset+0x1a3>
jmp    12a9 <FindTIFFOffset+0x189>
mov    -0x10(%rbp),%rdi
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1040 <fseek@plt>
jmp    12ae <FindTIFFOffset+0x18e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115b <FindTIFFOffset+0x3b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindTIFFOffset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %esi,%esi
je     1212 <FindTIFFOffset+0xf2>
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r13
mov    0x2ea1(%rip),%r14
jmp    1169 <FindTIFFOffset+0x49>
nopl   0x0(%rax)
mov    (%r14),%edx
mov    %r13,%rdi
mov    $0xa,%esi
call   1040 <fseek@plt>
add    $0xffffffff,%ebp
je     1210 <FindTIFFOffset+0xf0>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
mov    %r13,%rdi
call   1030 <fgetc@plt>
or     %ebx,%eax
cmp    %r12w,%ax
jne    1150 <FindTIFFOffset+0x30>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
mov    %r13,%rdi
call   1030 <fgetc@plt>
or     %ebx,%eax
cmp    %r15w,%ax
jne    1160 <FindTIFFOffset+0x40>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
shl    $0x18,%ebx
mov    %r13,%rdi
call   1030 <fgetc@plt>
shl    $0x10,%eax
or     %eax,%ebx
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
mov    %r13,%rdi
call   1030 <fgetc@plt>
or     %eax,%ebp
or     %ebx,%ebp
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <fseek@plt>
mov    $0x1,%eax
jmp    1212 <FindTIFFOffset+0xf2>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @FindTIFFOffset(i32* %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %6
store i16 %1, i16* %7
store i16 %2, i16* %8
store i16 %3, i16* %9
store i16 0, i16* %10
store i16 0, i16* %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %14
14: ; preds = %84, %4
%15 = load i32, i32* %13
%16 = load i16, i16* %7
%17 = zext i16 %16 to i32
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %87
19: ; preds = %14
%20 = load i32*, i32** %6
%21 = call i32 @fgetc(i32* %20)
%22 = shl i32 %21, 8
%23 = load i32*, i32** %6
%24 = call i32 @fgetc(i32* %23)
%25 = or i32 %22, %24
%26 = trunc i32 %25 to i16
store i16 %26, i16* %10
%27 = load i16, i16* %10
%28 = zext i16 %27 to i32
%29 = load i16, i16* %8
%30 = zext i16 %29 to i32
%31 = icmp eq i32 %28, %30
br i1 %31, label %32, label %79
32: ; preds = %19
%33 = load i32*, i32** %6
%34 = call i32 @fgetc(i32* %33)
%35 = shl i32 %34, 8
%36 = load i32*, i32** %6
%37 = call i32 @fgetc(i32* %36)
%38 = or i32 %35, %37
%39 = trunc i32 %38 to i16
store i16 %39, i16* %11
%40 = load i16, i16* %11
%41 = zext i16 %40 to i32
%42 = load i16, i16* %9
%43 = zext i16 %42 to i32
%44 = icmp eq i32 %41, %43
br i1 %44, label %45, label %78
45: ; preds = %32
%46 = load i32*, i32** %6
%47 = call i32 @fgetc(i32* %46)
%48 = shl i32 %47, 24
%49 = load i32*, i32** %6
%50 = call i32 @fgetc(i32* %49)
%51 = shl i32 %50, 16
%52 = or i32 %48, %51
%53 = load i32*, i32** %6
%54 = call i32 @fgetc(i32* %53)
%55 = shl i32 %54, 8
%56 = or i32 %52, %55
%57 = load i32*, i32** %6
%58 = call i32 @fgetc(i32* %57)
%59 = or i32 %56, %58
store i32 %59, i32* %12
%60 = load i32*, i32** %6
%61 = call i32 @fgetc(i32* %60)
%62 = shl i32 %61, 24
%63 = load i32*, i32** %6
%64 = call i32 @fgetc(i32* %63)
%65 = shl i32 %64, 16
%66 = or i32 %62, %65
%67 = load i32*, i32** %6
%68 = call i32 @fgetc(i32* %67)
%69 = shl i32 %68, 8
%70 = or i32 %66, %69
%71 = load i32*, i32** %6
%72 = call i32 @fgetc(i32* %71)
%73 = or i32 %70, %72
store i32 %73, i32* %12
%74 = load i32*, i32** %6
%75 = load i32, i32* %12
%76 = load i32, i32* @SEEK_SET
%77 = call i32 @fseek(i32* %74, i32 %75, i32 %76)
store i32 1, i32* %5
br label %88
78: ; preds = %32
br label %83
79: ; preds = %19
%80 = load i32*, i32** %6
%81 = load i32, i32* @SEEK_CUR
%82 = call i32 @fseek(i32* %80, i32 10, i32 %81)
br label %83
83: ; preds = %79, %78
br label %84
84: ; preds = %83
%85 = load i32, i32* %13
%86 = add nsw i32 %85, 1
store i32 %86, i32* %13
br label %14
87: ; preds = %14
store i32 0, i32* %5
br label %88
88: ; preds = %87, %45
%89 = load i32, i32* %5
ret i32 %89
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @FindTIFFOffset(i32* nocapture %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = zext i16 %1 to i32
%6 = icmp eq i16 %1, 0
br i1 %6, label %45, label %7
7: ; preds = %4, %42
%8 = phi i32 [ %43, %42 ], [ 0, %4 ]
%9 = tail call i32 @fgetc(i32* %0)
%10 = shl i32 %9, 8
%11 = tail call i32 @fgetc(i32* %0)
%12 = or i32 %10, %11
%13 = trunc i32 %12 to i16
%14 = icmp eq i16 %13, %2
br i1 %14, label %15, label %39
15: ; preds = %7
%16 = tail call i32 @fgetc(i32* %0)
%17 = shl i32 %16, 8
%18 = tail call i32 @fgetc(i32* %0)
%19 = or i32 %17, %18
%20 = trunc i32 %19 to i16
%21 = icmp eq i16 %20, %3
br i1 %21, label %22, label %42
22: ; preds = %15
%23 = tail call i32 @fgetc(i32* %0)
%24 = tail call i32 @fgetc(i32* %0)
%25 = tail call i32 @fgetc(i32* %0)
%26 = tail call i32 @fgetc(i32* %0)
%27 = tail call i32 @fgetc(i32* %0)
%28 = shl i32 %27, 24
%29 = tail call i32 @fgetc(i32* %0)
%30 = shl i32 %29, 16
%31 = or i32 %30, %28
%32 = tail call i32 @fgetc(i32* %0)
%33 = shl i32 %32, 8
%34 = or i32 %31, %33
%35 = tail call i32 @fgetc(i32* %0)
%36 = or i32 %34, %35
%37 = load i32, i32* @SEEK_SET
%38 = tail call i32 @fseek(i32* %0, i32 %36, i32 %37)
br label %45
39: ; preds = %7
%40 = load i32, i32* @SEEK_CUR
%41 = tail call i32 @fseek(i32* %0, i32 10, i32 %40)
br label %42
42: ; preds = %39, %15
%43 = add nuw nsw i32 %8, 1
%44 = icmp eq i32 %43, %5
br i1 %44, label %45, label %7
45: ; preds = %42, %4, %22
%46 = phi i32 [ 1, %22 ], [ 0, %4 ], [ 0, %42 ]
ret i32 %46
}