#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *load(int /*<<< orphan*/ *);
scalar_t__ run(char *, char const *);
int brainfuck(FILE *fin, const char *filename) {
  int status = 0;
  char *text = load(fin);
  if (fclose(fin) || run(text, filename))
    status = 1;
  if (text)
    free(text);
  return status;
}


x86 assembly (clang, -O0):
<brainfuck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <load@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
jne    118e <brainfuck+0x4e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <run@plt>
cmp    $0x0,%rax
je     1195 <brainfuck+0x55>
movl   $0x1,-0x14(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a9 <brainfuck+0x69>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brainfuck>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbp
call   1060 <load@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    116f <brainfuck+0x2f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <run@plt>
test   %rax,%rax
je     1188 <brainfuck+0x48>
mov    $0x1,%ebp
test   %rbx,%rbx
je     1181 <brainfuck+0x41>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
test   %rbx,%rbx
jne    1179 <brainfuck+0x39>
jmp    1181 <brainfuck+0x41>

LLVM IR (-O0):
define i32 @brainfuck(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i32*, i32** %3
%8 = call i8* @load(i32* %7)
store i8* %8, i8** %6
%9 = load i32*, i32** %3
%10 = call i64 @fclose(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i8*, i8** %4
%15 = call i64 @run(i8* %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12, %2
store i32 1, i32* %5
br label %18
18: ; preds = %17, %12
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
define i32 @brainfuck(i32* %0, i8* %1) {
%3 = tail call i8* @load(i32* %0)
%4 = tail call i64 @fclose(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @run(i8* %3, i8* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %6, %2
br label %10
10: ; preds = %9, %6
%11 = phi i32 [ 1, %9 ], [ 0, %6 ]
%12 = icmp eq i8* %3, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @free(i8* %3)
br label %15
15: ; preds = %13, %10
ret i32 %11
}