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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 2)
    return 1;
  FILE *fp = fopen(argv[1], "r");
  if (fp == NULL)
    return 1;
  fseek(fp, 2, SEEK_SET);
  uint32_t bfSize;
  fread(&bfSize, sizeof(bfSize), 1, fp);
  printf("\nbfSize: %d\n\n", bfSize);
  rewind(fp);
  uint8_t *buffer = malloc(14);
  fread(buffer, 1, 14, fp);
  printf("bfSize: %d\n\n", *((uint32_t *)(buffer + 2)));
  printf("bfSize:   %d   %d   %d   %d\n", buffer[2], buffer[3], buffer[4],
         buffer[5]);
  printf("bfSize: 0x%x 0x%x 0x%x 0x%x\n", buffer[2], buffer[3], buffer[4],
         buffer[5]);
  printf("bfSize: ");
  for (int i = 2; i < 6; i++) {
    for (int j = 7; j >= 0; j--) {
      int mask = 1 << j;
      if (buffer[i] & mask)
        printf("1");
      else
        printf("0");
    }
  }
  printf("\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1343 <main+0x1e3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bb <main+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    1343 <main+0x1e3>
mov    -0x18(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x1c(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    $0xe,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xe,%edx
call   1030 <fread@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x14(%rax),%r8d
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x14(%rax),%r8d
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x2c(%rbp)
cmpl   $0x6,-0x2c(%rbp)
jge    132e <main+0x1ce>
movl   $0x7,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     131b <main+0x1bb>
mov    -0x30(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    -0x34(%rbp),%eax
cmp    $0x0,%eax
je     12fa <main+0x19a>
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1308 <main+0x1a8>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130d <main+0x1ad>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    12b9 <main+0x159>
jmp    1320 <main+0x1c0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a8 <main+0x148>
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x2,%edi
jne    1344 <main+0x1c4>
mov    0x8(%rsi),%rdi
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1344 <main+0x1c4>
mov    %rax,%rbp
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x2,%esi
call   1090 <fseek@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    0x4(%rsp),%esi
lea    0xe15(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1070 <rewind@plt>
mov    $0xe,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0xe,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    0x8(%r13),%ebp
lea    0xdd8(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%r13),%r14d
mov    0x10(%r13),%r15d
mov    0x14(%r13),%r12d
lea    0xdc9(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdcd(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%eax
and    $0x80,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x40,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x20,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x10,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x8,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x4,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x2,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
and    $0x1,%ebp
or     $0x30,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
cmp    $0x3,%rbx
je     1336 <main+0x1b6>
mov    0xc(%r13,%rbx,4),%ebp
add    $0x1,%rbx
jmp    1280 <main+0x100>
lea    0xcd1(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.1 = [14 x i8] c"\0AbfSize: %d\0A\0A\00"
@.str.2 = [13 x i8] c"bfSize: %d\0A\0A\00"
@.str.3 = [29 x i8] c"bfSize: %d %d %d %d\0A\00"
@.str.4 = [29 x i8] c"bfSize: 0x%x 0x%x 0x%x 0x%x\0A\00"
@.str.5 = [9 x i8] c"bfSize: \00"
@.str.6 = [2 x i8] c"1\00"
@.str.7 = [2 x i8] c"0\00"
@.str.8 = [3 x i8] c"\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %100
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 1, i32* %3
br label %100
23: ; preds = %15
%24 = load i32*, i32** %6
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %24, i32 2, i32 %25)
%27 = load i32*, i32** %6
%28 = call i32 @fread(i32* %7, i32 4, i32 1, i32* %27)
%29 = load i32, i32* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %6
%32 = call i32 @rewind(i32* %31)
%33 = call i32* @malloc(i32 14)
store i32* %33, i32** %8
%34 = load i32*, i32** %8
%35 = load i32*, i32** %6
%36 = call i32 @fread(i32* %34, i32 1, i32 14, i32* %35)
%37 = load i32*, i32** %8
%38 = getelementptr inbounds i32, i32* %37, i64 2
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32*, i32** %8
%42 = getelementptr inbounds i32, i32* %41, i64 2
%43 = load i32, i32* %42
%44 = load i32*, i32** %8
%45 = getelementptr inbounds i32, i32* %44, i64 3
%46 = load i32, i32* %45
%47 = load i32*, i32** %8
%48 = getelementptr inbounds i32, i32* %47, i64 4
%49 = load i32, i32* %48
%50 = load i32*, i32** %8
%51 = getelementptr inbounds i32, i32* %50, i64 5
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %46, i32 %49, i32 %52)
%54 = load i32*, i32** %8
%55 = getelementptr inbounds i32, i32* %54, i64 2
%56 = load i32, i32* %55
%57 = load i32*, i32** %8
%58 = getelementptr inbounds i32, i32* %57, i64 3
%59 = load i32, i32* %58
%60 = load i32*, i32** %8
%61 = getelementptr inbounds i32, i32* %60, i64 4
%62 = load i32, i32* %61
%63 = load i32*, i32** %8
%64 = getelementptr inbounds i32, i32* %63, i64 5
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %56, i32 %59, i32 %62, i32 %65)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %9
br label %68
68: ; preds = %95, %23
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 6
br i1 %70, label %71, label %98
71: ; preds = %68
store i32 7, i32* %10
br label %72
72: ; preds = %91, %71
%73 = load i32, i32* %10
%74 = icmp sge i32 %73, 0
br i1 %74, label %75, label %94
75: ; preds = %72
%76 = load i32, i32* %10
%77 = shl i32 1, %76
store i32 %77, i32* %11
%78 = load i32*, i32** %8
%79 = load i32, i32* %9
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
%82 = load i32, i32* %81
%83 = load i32, i32* %11
%84 = and i32 %82, %83
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %75
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %90
88: ; preds = %75
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %90
90: ; preds = %88, %86
br label %91
91: ; preds = %90
%92 = load i32, i32* %10
%93 = add nsw i32 %92, -1
store i32 %93, i32* %10
br label %72
94: ; preds = %72
br label %95
95: ; preds = %94
%96 = load i32, i32* %9
%97 = add nsw i32 %96, 1
store i32 %97, i32* %9
br label %68
98: ; preds = %68
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %100
100: ; preds = %98, %22, %14
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.1 = [14 x i8] c"\0AbfSize: %d\0A\0A\00"
@.str.2 = [13 x i8] c"bfSize: %d\0A\0A\00"
@.str.3 = [29 x i8] c"bfSize: %d %d %d %d\0A\00"
@.str.4 = [29 x i8] c"bfSize: 0x%x 0x%x 0x%x 0x%x\0A\00"
@.str.5 = [9 x i8] c"bfSize: \00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %73
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %73, label %10
10: ; preds = %5
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %8, i32 2, i32 %11)
%13 = bitcast i32* %3 to i8*
%14 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %8)
%15 = load i32, i32* %3
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @rewind(i32* %8)
%18 = tail call i32* @malloc(i32 14)
%19 = tail call i32 @fread(i32* %18, i32 1, i32 14, i32* %8)
%20 = getelementptr inbounds i32, i32* %18, i64 2
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i32, i32* %18, i64 3
%24 = load i32, i32* %23
%25 = getelementptr inbounds i32, i32* %18, i64 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds i32, i32* %18, i64 5
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %24, i32 %26, i32 %28)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 %24, i32 %26, i32 %28)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %70, %10
%33 = phi i32 [ %21, %10 ], [ %72, %70 ]
%34 = phi i64 [ 2, %10 ], [ %66, %70 ]
%35 = and i32 %33, 128
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i32 48, i32 49
%38 = tail call i32 @putchar(i32 %37)
%39 = and i32 %33, 64
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, i32 48, i32 49
%42 = tail call i32 @putchar(i32 %41)
%43 = and i32 %33, 32
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 48, i32 49
%46 = tail call i32 @putchar(i32 %45)
%47 = and i32 %33, 16
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i32 48, i32 49
%50 = tail call i32 @putchar(i32 %49)
%51 = and i32 %33, 8
%52 = icmp eq i32 %51, 0
%53 = select i1 %52, i32 48, i32 49
%54 = tail call i32 @putchar(i32 %53)
%55 = and i32 %33, 4
%56 = icmp eq i32 %55, 0
%57 = select i1 %56, i32 48, i32 49
%58 = tail call i32 @putchar(i32 %57)
%59 = and i32 %33, 2
%60 = icmp eq i32 %59, 0
%61 = select i1 %60, i32 48, i32 49
%62 = tail call i32 @putchar(i32 %61)
%63 = and i32 %33, 1
%64 = or i32 %63, 48
%65 = tail call i32 @putchar(i32 %64)
%66 = add nuw nsw i64 %34, 1
%67 = icmp eq i64 %66, 6
br i1 %67, label %68, label %70
68: ; preds = %32
%69 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %73
70: ; preds = %32
%71 = getelementptr inbounds i32, i32* %18, i64 %66
%72 = load i32, i32* %71
br label %32
73: ; preds = %68, %5, %2
%74 = phi i32 [ 1, %2 ], [ 0, %68 ], [ 1, %5 ]
ret i32 %74
}