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


x86 assembly (clang, -O0):
<reloc32hunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <read32@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115c <reloc32hunk+0x2c>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <read32@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
shl    $0x2,%rdi
mov    -0x8(%rbp),%rsi
call   1040 <readData@plt>
jmp    113c <reloc32hunk+0xc>

x86 assembly (clang, -O2):
<reloc32hunk>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1050 <read32@plt>
test   %rax,%rax
je     119d <reloc32hunk+0x6d>
mov    %rax,%rbx
lea    0xeb1(%rip),%r14
lea    0xec3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r12,%rdi
call   1050 <read32@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
shl    $0x2,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <readData@plt>
mov    %r12,%rdi
call   1050 <read32@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <reloc32hunk+0x30>
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 @reloc32hunk(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
store i32* %0, i32** %2
br label %5
5: ; preds = %1, %11
%6 = load i32*, i32** %2
%7 = call i64 @read32(i32* %6)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %5
ret i32 0
11: ; preds = %5
%12 = load i64, i64* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = load i32*, i32** %2
%15 = call i64 @read32(i32* %14)
store i64 %15, i64* %4
%16 = load i64, i64* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%18 = load i64, i64* %3
%19 = mul i64 %18, 4
%20 = load i32*, i32** %2
%21 = call i32 @readData(i64 %19, i32* %20)
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 @reloc32hunk(i32* %0) {
%2 = tail call i64 @read32(i32* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %11, %4 ], [ %2, %1 ]
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = tail call i64 @read32(i32* %0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%9 = shl i64 %5, 2
%10 = tail call i32 @readData(i64 %9, i32* %0)
%11 = tail call i64 @read32(i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4, %1
ret i32 0
}