#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*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ parse_header(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
FILE *load_bit_file(char *ifile) {
  FILE *temp;
  temp = fopen(ifile, "r");
  if (!temp) {
    fprintf(stderr,
            "RpiJtag: could not open bitstream file %s for read, aborting.\n",
            ifile);
    exit(1);
  } else {
    fprintf(stderr, "RpiJtag: bitstream file %s has been read, continuing.\n",
            ifile);
  }
  parse_header(temp);
  return temp;
}


x86 assembly (clang, -O0):
<load_bit_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118e <load_bit_file+0x4e>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe9f(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <parse_header@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_bit_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
test   %rbx,%rbx
je     1186 <load_bit_file+0x46>
lea    0xed6(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <parse_header@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe75(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [63 x i8] c"RpiJtag: could not open bitstream file %s for read, aborting.\0A\00"
@.str.2 = [55 x i8] c"RpiJtag: bitstream file %s has been read, continuing.\0A\00"
define i32* @load_bit_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13
%18 = load i32*, i32** %3
%19 = call i32 @parse_header(i32* %18)
%20 = load i32*, i32** %3
ret i32* %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [63 x i8] c"RpiJtag: could not open bitstream file %s for read, aborting.\0A\00"
@.str.2 = [55 x i8] c"RpiJtag: bitstream file %s has been read, continuing.\0A\00"
define i32* @load_bit_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
%4 = load i32, i32* @stderr
br i1 %3, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%10 = tail call i32 @parse_header(i32* %2)
ret i32* %2
}