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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  FILE *f = fopen(argv[1], "rb");
  if (!f)
    return -1;
  uint8_t byte, n[3];
  while (!feof(f)) {
    fread(&byte, 1, 1, f);
    int p;
    if (byte) {
      p = 8 * (int)byte;
    } else {
      fread(n, 1, 3, f);
      p = (int)n[0] + (((int)n[1]) << 8) + (((int)n[2]) << 16);
    }
    printf("%d\n", p);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <main+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <main+0xe3>
jmp    119a <main+0x4a>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b8 <main+0x68>
jmp    122a <main+0xda>
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmpq   $0x0,-0x20(%rbp)
je     11e6 <main+0x96>
mov    -0x20(%rbp),%rax
shl    $0x3,%eax
mov    %eax,-0x44(%rbp)
jmp    1216 <main+0xc6>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x30(%rbp),%rcx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xde3(%rip),%rdi
call   1050 <printf@plt>
jmp    119a <main+0x4a>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     118b <main+0x3b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     119c <main+0x4c>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1190 <main+0x40>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe56(%rip),%r12
jmp    11ed <main+0x9d>
nop
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x18(%rsp),%eax
mov    0x20(%rsp),%esi
shl    $0x8,%eax
add    0x10(%rsp),%eax
shl    $0x10,%esi
add    %eax,%esi
mov    %r12,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    117f <main+0x2f>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     11b0 <main+0x60>
shl    $0x3,%esi
jmp    11d9 <main+0x89>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca [3 x i64]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i32 -1, i32* %3
br label %55
17: ; preds = %2
br label %18
18: ; preds = %49, %17
%19 = load i32*, i32** %6
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %52
23: ; preds = %18
%24 = load i32*, i32** %6
%25 = call i32 @fread(i64* %7, i32 1, i32 1, i32* %24)
%26 = load i64, i64* %7
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i64, i64* %7
%30 = trunc i64 %29 to i32
%31 = mul nsw i32 8, %30
store i32 %31, i32* %9
br label %49
32: ; preds = %23
%33 = getelementptr inbounds [3 x i64], [3 x i64]* %8, i64 0, i64 0
%34 = load i32*, i32** %6
%35 = call i32 @fread(i64* %33, i32 1, i32 3, i32* %34)
%36 = getelementptr inbounds [3 x i64], [3 x i64]* %8, i64 0, i64 0
%37 = load i64, i64* %36
%38 = trunc i64 %37 to i32
%39 = getelementptr inbounds [3 x i64], [3 x i64]* %8, i64 0, i64 1
%40 = load i64, i64* %39
%41 = trunc i64 %40 to i32
%42 = shl i32 %41, 8
%43 = add nsw i32 %38, %42
%44 = getelementptr inbounds [3 x i64], [3 x i64]* %8, i64 0, i64 2
%45 = load i64, i64* %44
%46 = trunc i64 %45 to i32
%47 = shl i32 %46, 16
%48 = add nsw i32 %43, %47
store i32 %48, i32* %9
br label %49
49: ; preds = %32, %28
%50 = load i32, i32* %9
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %18
52: ; preds = %18
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
br label %55
55: ; preds = %52, %16
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca [3 x i64]
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %44, label %9
9: ; preds = %2
%10 = bitcast i64* %3 to i8*
%11 = bitcast [3 x i64]* %4 to i8*
%12 = tail call i32 @feof(i32* %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %42
14: ; preds = %9
%15 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 0
%16 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 1
%17 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 2
br label %18
18: ; preds = %14, %37
%19 = call i32 @fread(i64* %3, i32 1, i32 1, i32* %7)
%20 = load i64, i64* %3
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = trunc i64 %20 to i32
%24 = shl nsw i32 %23, 3
br label %37
25: ; preds = %18
%26 = call i32 @fread(i64* %15, i32 1, i32 3, i32* %7)
%27 = load i64, i64* %15
%28 = trunc i64 %27 to i32
%29 = load i64, i64* %16
%30 = trunc i64 %29 to i32
%31 = shl i32 %30, 8
%32 = add nsw i32 %31, %28
%33 = load i64, i64* %17
%34 = trunc i64 %33 to i32
%35 = shl i32 %34, 16
%36 = add nsw i32 %32, %35
br label %37
37: ; preds = %25, %22
%38 = phi i32 [ %24, %22 ], [ %36, %25 ]
%39 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = tail call i32 @feof(i32* %7)
%41 = icmp eq i32 %40, 0
br i1 %41, label %18, label %42
42: ; preds = %37, %9
%43 = tail call i32 @fclose(i32* %7)
br label %44
44: ; preds = %2, %42
%45 = phi i32 [ 0, %42 ], [ -1, %2 ]
ret i32 %45
}