#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 ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned long);
unsigned long read16(int /*<<< orphan*/ *);
int /*<<< orphan*/ readData(unsigned long, int /*<<< orphan*/ *);
int reloc16hunk(FILE *fp) {
  while (1) {
    unsigned long numoffs = read16(fp);
    if (numoffs == 0) {
      if (ftell(fp) % 4 != 0)
        read16(fp);
      return 0;
    }
    printf("Number of Offsets = %lu\n", numoffs);
    unsigned long numhunks = read16(fp);
    printf("Numbers of hunk = %lu\n", numhunks);
    readData(numoffs * 2, fp);
  }
}


x86 assembly (clang, -O0):
<reloc16hunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <read16@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118f <reloc16hunk+0x4f>
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1187 <reloc16hunk+0x47>
mov    -0x8(%rbp),%rdi
call   1040 <read16@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <read16@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
shl    $0x1,%rdi
mov    -0x8(%rbp),%rsi
call   1050 <readData@plt>
jmp    114c <reloc16hunk+0xc>

x86 assembly (clang, -O2):
<reloc16hunk>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1040 <read16@plt>
test   %rax,%rax
je     11ac <reloc16hunk+0x6c>
mov    %rax,%rbx
lea    0xea1(%rip),%r14
lea    0xeb3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r12,%rdi
call   1040 <read16@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    %rbx,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <readData@plt>
mov    %r12,%rdi
call   1040 <read16@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <reloc16hunk+0x30>
mov    %r12,%rdi
call   1060 <ftell@plt>
test   $0x3,%al
je     11c0 <reloc16hunk+0x80>
mov    %r12,%rdi
call   1040 <read16@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Number of Offsets = %lu\0A\00"
@.str.1 = [23 x i8] c"Numbers of hunk = %lu\0A\00"
define i32 @reloc16hunk(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
store i32* %0, i32** %2
br label %5
5: ; preds = %1, %19
%6 = load i32*, i32** %2
%7 = call i64 @read16(i32* %6)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i32*, i32** %2
%12 = call i32 @ftell(i32* %11)
%13 = srem i32 %12, 4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** %2
%17 = call i64 @read16(i32* %16)
br label %18
18: ; preds = %15, %10
ret i32 0
19: ; preds = %5
%20 = load i64, i64* %3
%21 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %20)
%22 = load i32*, i32** %2
%23 = call i64 @read16(i32* %22)
store i64 %23, i64* %4
%24 = load i64, i64* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%26 = load i64, i64* %3
%27 = mul i64 %26, 2
%28 = load i32*, i32** %2
%29 = call i32 @readData(i64 %27, i32* %28)
br label %5
}

LLVM IR (-O2):
@.str = [25 x i8] c"Number of Offsets = %lu\0A\00"
@.str.1 = [23 x i8] c"Numbers of hunk = %lu\0A\00"
define i32 @reloc16hunk(i32* %0) {
%2 = tail call i64 @read16(i32* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %10
4: ; preds = %10, %1
%5 = tail call i32 @ftell(i32* %0)
%6 = and i32 %5, 3
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %4
%9 = tail call i64 @read16(i32* %0)
br label %19
10: ; preds = %1, %10
%11 = phi i64 [ %17, %10 ], [ %2, %1 ]
%12 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = tail call i64 @read16(i32* %0)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %13)
%15 = shl i64 %11, 1
%16 = tail call i32 @readData(i64 %15, i32* %0)
%17 = tail call i64 @read16(i32* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %4, label %10
19: ; preds = %4, %8
ret i32 0
}