#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fp_in;
int /*<<< orphan*/ load_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void load() {
  FILE *fopen(), *fp_in;
  char fn_in[30];
  printf("Enter name of input file: ");
  scanf("%s", fn_in);
  strcat(fn_in, ".q");
  fp_in = fopen(fn_in, "r");
  if (fp_in == NULL) {
    printf("No input file %s\n", fn_in);
    goto out;
  }
  load_file(fp_in);
  printf("\nInput in file: %s\n", fn_in);
  fclose(fp_in);
out:;
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe9a(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x30(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11cc <load+0x6c>
lea    -0x30(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f0 <load+0x90>
mov    -0x8(%rbp),%rdi
call   1050 <load_file@plt>
lea    -0x30(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %rbx
sub    $0x20,%rsp
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea1(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ce <load+0x6e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <load_file@plt>
lea    0xe7b(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11df <load+0x7f>
lea    0xe4e(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter name of input file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c".q\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [18 x i8] c"No input file %s\0A\00"
@.str.5 = [20 x i8] c"\0AInput in file: %s\0A\00"
@fp_in = global i32* null
define void @load() {
%1 = alloca i32*
%2 = alloca [30 x i8]
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%7 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %1
%10 = load i32*, i32** %1
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %22
15: ; preds = %0
%16 = load i32*, i32** %1
%17 = call i32 @load_file(i32* %16)
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %15, %12
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter name of input file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c".q\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [18 x i8] c"No input file %s\0A\00"
@.str.5 = [20 x i8] c"\0AInput in file: %s\0A\00"
@fp_in = global i32* null
define void @load() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %14
10: ; preds = %0
%11 = call i32 @load_file(i32* %6)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%13 = call i32 @fclose(i32* %6)
br label %14
14: ; preds = %10, %8
ret void
}