#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fstat(int /*<<< orphan*/, struct stat *);
int /*<<< orphan*/ interpret_brainfuck(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strip_source(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  FILE *source;
  struct stat filstat;
  char *bf_code;
  if (argc <= 1) {
    puts("Specify brainfuck source file.");
  } else {
    source = fopen(argv[1], "r");
    if (!source) {
      char err_info[strlen("brickfuck: ") + 1 + strlen(argv[1]) + 1];
      strcpy(err_info, "brickfuck: ");
      strcat(err_info, argv[1]);
      perror(err_info);
    } else {
      fstat(fileno(source), &filstat);
      bf_code = strip_source(source, filstat.st_size);
      fclose(source);
      interpret_brainfuck(bf_code);
      free(bf_code);
    }
  }
  return 0;
}


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)
cmpl   $0x1,-0x8(%rbp)
jg     11f1 <main+0x31>
lea    0xe19(%rip),%rdi
call   1050 <puts@plt>
jmp    12d4 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1290 <main+0xd0>
lea    0xe06(%rip),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,%rdx
lea    0x2(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x30(%rbp)
lea    0x11(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
lea    0xdbc(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10b0 <strcat@plt>
mov    -0x40(%rbp),%rdi
call   10a0 <perror@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    12cf <main+0x10f>
mov    -0x18(%rbp),%rdi
call   1080 <fileno@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   10e0 <fstat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   10c0 <strip_source@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <interpret_brainfuck@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    12d4 <main+0x114>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11dd <main+0x1d>
lea    0xe2a(%rip),%rdi
call   1050 <puts@plt>
jmp    1231 <main+0x71>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe34(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     123e <main+0x7e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <fileno@plt>
lea    -0x20(%rbp),%rsi
mov    %eax,%edi
call   10e0 <fstat@plt>
mov    -0x20(%rbp),%esi
mov    %rbx,%rdi
call   10c0 <strip_source@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   10d0 <interpret_brainfuck@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r14),%rdi
call   1070 <strlen@plt>
mov    %rsp,%r15
mov    %rsp,%rbx
add    $0x1c,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xdbf(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
call   10a0 <perror@plt>
mov    %r15,%rsp
jmp    1231 <main+0x71>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [31 x i8] c"Specify brainfuck source file.\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"brickfuck: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %55
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.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %40, label %22
22: ; preds = %15
%23 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%24 = add nsw i64 %23, 1
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %24, %28
%30 = add nsw i64 %29, 1
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %9
%32 = alloca i8, i64 %30
store i64 %30, i64* %10
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strcat(i8* %32, i8* %36)
%38 = call i32 @perror(i8* %32)
%39 = load i8*, i8** %9
br label %54
40: ; preds = %15
%41 = load i32*, i32** %6
%42 = call i32 @fileno(i32* %41)
%43 = call i32 @fstat(i32 %42, %struct.stat* %7)
%44 = load i32*, i32** %6
%45 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i8* @strip_source(i32* %44, i32 %46)
store i8* %47, i8** %8
%48 = load i32*, i32** %6
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %8
%51 = call i32 @interpret_brainfuck(i8* %50)
%52 = load i8*, i8** %8
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %40, %22
br label %55
55: ; preds = %54, %13
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [31 x i8] c"Specify brainfuck source file.\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"brickfuck: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %32
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 %23
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%16 = add nsw i64 %15, 13
%17 = tail call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %9
%21 = call i32 @strcat(i8* %18, i8* %20)
%22 = call i32 @perror(i8* %18)
br label %32
23: ; preds = %8
%24 = tail call i32 @fileno(i32* %11)
%25 = call i32 @fstat(i32 %24, %struct.stat* %3)
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%27 = load i32, i32* %26
%28 = tail call i8* @strip_source(i32* %11, i32 %27)
%29 = tail call i32 @fclose(i32* %11)
%30 = tail call i32 @interpret_brainfuck(i8* %28)
%31 = tail call i32 @free(i8* %28)
br label %32
32: ; preds = %13, %23, %6
ret i32 0
}