#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_out;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ save_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void save() {
  FILE *fopen(), *fp_out;
  char fn_out[30];
  printf("Enter name of output file: ");
  scanf("%s", fn_out);
  strcat(fn_out, ".q");
  fp_out = fopen(fn_out, "w");
  save_file(fp_out);
  printf("\nOutput in file: %s\n", fn_out);
  fclose(fp_out);
}


x86 assembly (clang, -O0):
<save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe9b(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x30(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <save_file@plt>
lea    -0x30(%rbp),%rsi
lea    0xe66(%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):
<save>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea0(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1050 <scanf@plt>
lea    0xe91(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <save_file@plt>
lea    0xe6d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter name of output file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c".q\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"\0AOutput in file: %s\0A\00"
@fp_out = global i32* null
define void @save() {
%1 = alloca i32*
%2 = alloca [30 x i8]
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 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 = call i32 @save_file(i32* %10)
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %1
%15 = call i32 @fclose(i32* %14)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter name of output file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c".q\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"\0AOutput in file: %s\0A\00"
@fp_out = global i32* null
define void @save() {
%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 ([28 x i8], [28 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 = call i32 @save_file(i32* %6)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%9 = call i32 @fclose(i32* %6)
ret void
}