#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_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ bf_run(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  long sz;
  char *program;
  FILE *fp;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s INFILE.bf\n", argv[0]);
    return 1;
  }
  fp = fopen(argv[1], "r");
  if (!fp) {
    fprintf(stderr, "Can't open file '%s'\n", argv[1]);
    return 1;
  }
  fseek(fp, 0, SEEK_END);
  sz = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  program = (char *)malloc(sz + 1);
  program[fread(program, 1, sz, fp)] = 0;
  fclose(fp);
  bf_run(program);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c8 <main+0x48>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x11c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1214 <main+0x94>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe14(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x11c>
mov    -0x28(%rbp),%rdi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d90(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <bf_run@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    1219 <main+0x99>
mov    0x8(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     122f <main+0xaf>
mov    %rax,%rbx
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r14
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x1(%r14),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   10a0 <bf_run@plt>
jmp    124e <main+0xce>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdd3(%rip),%rsi
jmp    1243 <main+0xc3>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xdd4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s INFILE.bf\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Can't open file '%s'\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %53
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp ne i32* %22, null
br i1 %23, label %30, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 1, i32* %3
br label %53
30: ; preds = %17
%31 = load i32*, i32** %8
%32 = load i32, i32* @SEEK_END
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32*, i32** %8
%35 = call i64 @ftell(i32* %34)
store i64 %35, i64* %6
%36 = load i32*, i32** %8
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @fseek(i32* %36, i32 0, i32 %37)
%39 = load i64, i64* %6
%40 = add nsw i64 %39, 1
%41 = call i64 @malloc(i64 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %7
%43 = load i8*, i8** %7
%44 = load i8*, i8** %7
%45 = load i64, i64* %6
%46 = load i32*, i32** %8
%47 = call i64 @fread(i8* %44, i32 1, i64 %45, i32* %46)
%48 = getelementptr inbounds i8, i8* %43, i64 %47
store i8 0, i8* %48
%49 = load i32*, i32** %8
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %7
%52 = call i32 @bf_run(i8* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %30, %24, %11
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s INFILE.bf\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Can't open file '%s'\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %30
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %30
17: ; preds = %8
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %11, i32 0, i32 %18)
%20 = tail call i64 @ftell(i32* %11)
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %11, i32 0, i32 %21)
%23 = add nsw i64 %20, 1
%24 = tail call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
%26 = tail call i64 @fread(i8* %25, i32 1, i64 %20, i32* %11)
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
%28 = tail call i32 @fclose(i32* %11)
%29 = tail call i32 @bf_run(i8* %25)
br label %30
30: ; preds = %17, %13, %4
%31 = phi i32 [ 1, %4 ], [ 0, %17 ], [ 1, %13 ]
ret i32 %31
}