#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
int load_brain(char const *, char *);
char *malloc(int);
scalar_t__ sprintf(char *, char *, char const *);
int strlen(char const *);
int input_brain(const char *name, const char *prefix) {
  char *filename;
  int ret;
  filename = malloc((strlen(prefix) + 1 + 3 + 1) * sizeof(char));
  if (filename == NULL)
    return -6;
  if (sprintf(filename, "%s.brn", prefix) <= 0) {
    free(filename);
    assert(!(1));
  }
  ret = load_brain(name, filename);
  free(filename);
  return ret;
}


x86 assembly (clang, -O0):
<input_brain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
add    $0x3,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11aa <input_brain+0x4a>
movl   $0xfffffffa,-0x4(%rbp)
jmp    11f7 <input_brain+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe47(%rip),%rsi
call   1080 <sprintf@plt>
cmp    $0x0,%rax
jg     11d8 <input_brain+0x78>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <load_brain@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_brain>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x5(%rax),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11c4 <input_brain+0x64>
mov    %rax,%rbx
lea    0xe74(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1080 <sprintf@plt>
test   %rax,%rax
jg     11ab <input_brain+0x4b>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1050 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <load_brain@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    11c9 <input_brain+0x69>
mov    $0xfffffffa,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s.brn\00"
define i32 @input_brain(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = add nsw i32 %10, 3
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 -6, i32* %3
br label %36
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = call i64 @sprintf(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
%28 = call i32 @assert(i32 0)
br label %29
29: ; preds = %25, %20
%30 = load i8*, i8** %4
%31 = load i8*, i8** %6
%32 = call i32 @load_brain(i8* %30, i8* %31)
store i32 %32, i32* %7
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %36
36: ; preds = %29, %19
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s.brn\00"
define i32 @input_brain(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 5
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = tail call i64 @sprintf(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = icmp slt i64 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @free(i8* %5)
%12 = tail call i32 @assert(i32 0)
br label %13
13: ; preds = %10, %7
%14 = tail call i32 @load_brain(i8* %0, i8* %5)
%15 = tail call i32 @free(i8* %5)
br label %16
16: ; preds = %2, %13
%17 = phi i32 [ %14, %13 ], [ -6, %2 ]
ret i32 %17
}