#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_SET;
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
unsigned long find_offset(FILE *pFile) {
  unsigned long offset = 0;
  unsigned char b0, b1, b2, b3;
  if (0 != fseek(pFile, 20, SEEK_SET)) {
    return -1;
  }
  fread(&b3, sizeof b3, 1, pFile);
  fread(&b2, sizeof b2, 1, pFile);
  fread(&b1, sizeof b1, 1, pFile);
  fread(&b0, sizeof b0, 1, pFile);
  offset = (((unsigned long)b0) << 24) | (((unsigned long)b1) << 16) |
           (((unsigned long)b2) << 8) | b3;
  return offset;
}


x86 assembly (clang, -O0):
<find_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <fseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1166 <find_offset+0x46>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e7 <find_offset+0xc7>
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x1b(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x1a(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movzbl -0x19(%rbp),%eax
shl    $0x18,%rax
movzbl -0x1a(%rbp),%ecx
shl    $0x10,%rcx
or     %rcx,%rax
movzbl -0x1b(%rbp),%ecx
shl    $0x8,%rcx
or     %rcx,%rax
movzbl -0x1c(%rbp),%ecx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_offset>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <fseek@plt>
mov    %rax,%rcx
mov    $0xffffffffffffffff,%rax
test   %rcx,%rcx
jne    11d3 <find_offset+0xb3>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xd(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
movzbl 0xf(%rsp),%eax
shl    $0x18,%rax
movzbl 0xe(%rsp),%ecx
shl    $0x10,%rcx
or     %rax,%rcx
movzbl 0xd(%rsp),%edx
shl    $0x8,%rdx
or     %rcx,%rdx
movzbl 0xc(%rsp),%eax
or     %rdx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i64 @find_offset(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i32* %0, i32** %3
store i64 0, i64* %4
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_SET
%11 = call i64 @fseek(i32* %9, i32 20, i32 %10)
%12 = icmp ne i64 0, %11
br i1 %12, label %13, label %14
13: ; preds = %1
store i64 -1, i64* %2
br label %38
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %15)
%17 = load i32*, i32** %3
%18 = call i32 @fread(i8* %7, i32 1, i32 1, i32* %17)
%19 = load i32*, i32** %3
%20 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %19)
%21 = load i32*, i32** %3
%22 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %21)
%23 = load i8, i8* %5
%24 = zext i8 %23 to i64
%25 = shl i64 %24, 24
%26 = load i8, i8* %6
%27 = zext i8 %26 to i64
%28 = shl i64 %27, 16
%29 = or i64 %25, %28
%30 = load i8, i8* %7
%31 = zext i8 %30 to i64
%32 = shl i64 %31, 8
%33 = or i64 %29, %32
%34 = load i8, i8* %8
%35 = zext i8 %34 to i64
%36 = or i64 %33, %35
store i64 %36, i64* %4
%37 = load i64, i64* %4
store i64 %37, i64* %2
br label %38
38: ; preds = %14, %13
%39 = load i64, i64* %2
ret i64 %39
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i64 @find_offset(i32* nocapture %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @fseek(i32* %0, i32 20, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %0)
%11 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%12 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %0)
%13 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %0)
%14 = load i8, i8* %2
%15 = zext i8 %14 to i64
%16 = shl nuw nsw i64 %15, 24
%17 = load i8, i8* %3
%18 = zext i8 %17 to i64
%19 = shl nuw nsw i64 %18, 16
%20 = or i64 %19, %16
%21 = load i8, i8* %4
%22 = zext i8 %21 to i64
%23 = shl nuw nsw i64 %22, 8
%24 = or i64 %20, %23
%25 = load i8, i8* %5
%26 = zext i8 %25 to i64
%27 = or i64 %24, %26
br label %28
28: ; preds = %1, %9
%29 = phi i64 [ %27, %9 ], [ -1, %1 ]
ret i64 %29
}