#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
int main() {
  FILE *in = fopen("test.img", "rb");
  unsigned int i, start_sector, length_sectors;
  fseek(in, 0x1BE, SEEK_SET);
  for (i = 0; i < 4; i++) {
    printf("Partition entry %d: First byte %02X\n", i, fgetc(in));
    printf("  Partition start in CHS: %02X:%02X:%02X\n", fgetc(in), fgetc(in),
           fgetc(in));
    printf("  Partition type 0x%02X\n", fgetc(in));
    printf("  Partition end in CHS: %02X:%02X:%02X\n", fgetc(in), fgetc(in),
           fgetc(in));
    fread(&start_sector, 4, 1, in);
    fread(&length_sectors, 4, 1, in);
    printf("  Relative LBA address 0x%08X, %d sectors long\n", start_sector,
           length_sectors);
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    $0x1be,%esi
call   1070 <fseek@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jae    12a7 <main+0x147>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <main+0x44>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x1be,%esi
call   1070 <fseek@plt>
mov    %rsp,%r14
lea    0xefb(%rip),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <fgetc@plt>
lea    0xe4d(%rip),%rdi
mov    %r12d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fgetc@plt>
lea    0xe42(%rip),%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
lea    0xe4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fgetc@plt>
lea    0xe3b(%rip),%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r12d
cmp    $0x4,%r12d
jne    11b0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.img\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@.str.2 = [37 x i8] c"Partition entry %d: First byte %02X\0A\00"
@.str.3 = [42 x i8] c" Partition start in CHS: %02X:%02X:%02X\0A\00"
@.str.4 = [25 x i8] c" Partition type 0x%02X\0A\00"
@.str.5 = [40 x i8] c" Partition end in CHS: %02X:%02X:%02X\0A\00"
@.str.6 = [48 x i8] c" Relative LBA address 0x%08X, %d sectors long\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = load i32, i32* @SEEK_SET
%9 = call i32 @fseek(i32* %7, i32 446, i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %42, %0
%11 = load i32, i32* %3
%12 = icmp ult i32 %11, 4
br i1 %12, label %13, label %45
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i32*, i32** %2
%16 = call i32 @fgetc(i32* %15)
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %16)
%18 = load i32*, i32** %2
%19 = call i32 @fgetc(i32* %18)
%20 = load i32*, i32** %2
%21 = call i32 @fgetc(i32* %20)
%22 = load i32*, i32** %2
%23 = call i32 @fgetc(i32* %22)
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %21, i32 %23)
%25 = load i32*, i32** %2
%26 = call i32 @fgetc(i32* %25)
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %2
%29 = call i32 @fgetc(i32* %28)
%30 = load i32*, i32** %2
%31 = call i32 @fgetc(i32* %30)
%32 = load i32*, i32** %2
%33 = call i32 @fgetc(i32* %32)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %29, i32 %31, i32 %33)
%35 = load i32*, i32** %2
%36 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %35)
%37 = load i32*, i32** %2
%38 = call i32 @fread(i32* %5, i32 4, i32 1, i32* %37)
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %39, i32 %40)
br label %42
42: ; preds = %13
%43 = load i32, i32* %3
%44 = add i32 %43, 1
store i32 %44, i32* %3
br label %10
45: ; preds = %10
%46 = load i32*, i32** %2
%47 = call i32 @fclose(i32* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.img\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@.str.2 = [37 x i8] c"Partition entry %d: First byte %02X\0A\00"
@.str.3 = [42 x i8] c" Partition start in CHS: %02X:%02X:%02X\0A\00"
@.str.4 = [25 x i8] c" Partition type 0x%02X\0A\00"
@.str.5 = [40 x i8] c" Partition end in CHS: %02X:%02X:%02X\0A\00"
@.str.6 = [48 x i8] c" Relative LBA address 0x%08X, %d sectors long\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %3, i32 446, i32 %6)
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %27, %8 ]
%10 = tail call i32 @fgetc(i32* %3)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10)
%12 = tail call i32 @fgetc(i32* %3)
%13 = tail call i32 @fgetc(i32* %3)
%14 = tail call i32 @fgetc(i32* %3)
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %13, i32 %14)
%16 = tail call i32 @fgetc(i32* %3)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = tail call i32 @fgetc(i32* %3)
%19 = tail call i32 @fgetc(i32* %3)
%20 = tail call i32 @fgetc(i32* %3)
%21 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %18, i32 %19, i32 %20)
%22 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %3)
%23 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %3)
%24 = load i32, i32* %1
%25 = load i32, i32* %2
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 %25)
%27 = add nuw nsw i32 %9, 1
%28 = icmp eq i32 %27, 4
br i1 %28, label %29, label %8
29: ; preds = %8
%30 = tail call i32 @fclose(i32* %3)
ret i32 0
}