#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strncat(char *, char *, int);
int main(int argc, char **argv) {
  FILE *example;
  char input;
  char typeinput[5];
  printf("File type: ");
  scanf("%s", &typeinput);
  char filetype[29] = "/home/example.";
  strncat(filetype, typeinput, 29);
  example = fopen(filetype, "w");
  if (!example) {
    printf("Error: Unable to open file\n");
    return EXIT_FAILURE;
  }
  while (input != '~') {
    scanf("%c", &input);
    fprintf(example, "%c", input);
  }
  fclose(example);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
lea    -0x1e(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    0xe95(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe92(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe8f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8d(%rip),%eax
mov    %eax,-0x28(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x24(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
mov    $0x1d,%edx
call   1050 <strncat@plt>
lea    -0x40(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1215 <main+0xb5>
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <main+0x107>
jmp    121a <main+0xba>
movsbl -0x19(%rbp),%eax
cmp    $0x7e,%eax
je     1252 <main+0xf2>
lea    0xdff(%rip),%rdi
lea    -0x19(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xde9(%rip),%rsi
movsbl -0x19(%rbp),%edx
call   1060 <fprintf@plt>
jmp    121a <main+0xba>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
lea    0xb(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movups 0xe9b(%rip),%xmm0
movups %xmm0,0x1d(%rsp)
movaps 0xe82(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1d,%edx
call   1060 <strncat@plt>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1222 <main+0xb2>
mov    %rax,%rbx
lea    0xe2b(%rip),%r14
lea    0xa(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movsbl 0xa(%rsp),%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
cmpb   $0x7e,0xa(%rsp)
jne    11f0 <main+0x80>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2db8(%rip),%rax
jmp    1235 <main+0xc5>
lea    0xdeb(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"File type: \00"
@.str.1 = [3 x i8] c"%s\00"
@__const.main.filetype = [29 x i8] c"/home/example.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"Error: Unable to open file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [3 x i8] c"%c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
%8 = alloca [5 x i8]
%9 = alloca [29 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [5 x i8]* %8)
%12 = bitcast [29 x i8]* %9 to i8*
%13 = getelementptr inbounds [29 x i8], [29 x i8]* %9, i64 0, i64 0
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%15 = call i32 @strncat(i8* %13, i8* %14, i32 29)
%16 = getelementptr inbounds [29 x i8], [29 x i8]* %9, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %37
23: ; preds = %2
br label %24
24: ; preds = %28, %23
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 126
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%30 = load i32*, i32** %6
%31 = load i8, i8* %7
%32 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8 signext %31)
br label %24
33: ; preds = %24
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* @EXIT_SUCCESS
store i32 %36, i32* %3
br label %37
37: ; preds = %33, %20
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [12 x i8] c"File type: \00"
@.str.1 = [3 x i8] c"%s\00"
@__const.main.filetype = [29 x i8] c"/home/example.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [2 x i8] c"w\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [3 x i8] c"%c\00"
@EXIT_SUCCESS = global i32 0
@str = [27 x i8] c"Error: Unable to open file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca [5 x i8]
%5 = alloca [29 x i8]
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [5 x i8]* %4)
%9 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%10 = call i32 @strncat(i8* %9, i8* %6, i32 29)
%11 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %24
15: ; preds = %2, %15
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = call i32 @fputc(i32 %18, i32* %11)
%20 = load i8, i8* %3
%21 = icmp eq i8 %20, 126
br i1 %21, label %22, label %15
22: ; preds = %15
%23 = call i32 @fclose(i32* %11)
br label %24
24: ; preds = %22, %13
%25 = phi i32* [ @EXIT_SUCCESS, %22 ], [ @EXIT_FAILURE, %13 ]
%26 = load i32, i32* %25
ret i32 %26
}