#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char *);
int createf(void) {
  char destination[256];
  FILE *fp;
  char ch;
  printf("Enter file destination:\n");
  scanf("%s", destination);
  fp = fopen(destination, "w");
  printf("\nEnter data to be stored in to the file:\n");
  while ((ch = getchar()) != EOF)
    putc(ch, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<createf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x100(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x100(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x108(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x109(%rbp)
movsbl %al,%eax
mov    0x2e21(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11ec <createf+0x8c>
mov    -0x109(%rbp),%al
mov    -0x108(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
jmp    11b0 <createf+0x50>
mov    -0x108(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createf>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
lea    0xe83(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e34(%rip),%r14
cmp    (%r14),%al
je     11d7 <createf+0x77>
nopl   0x0(%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r14),%al
jne    11c0 <createf+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Enter file destination:\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [42 x i8] c"\0AEnter data to be stored in to the file:\0A\00"
@EOF = global i8 0
define i32 @createf() {
%1 = alloca [256 x i8]
%2 = alloca i32*
%3 = alloca i8
%4 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %16, %0
%11 = call signext i8 (...) @getchar()
store i8 %11, i8* %3
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i8, i8* %3
%18 = load i32*, i32** %2
%19 = call i32 @putc(i8 signext %17, i32* %18)
br label %10
20: ; preds = %10
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
@str = [24 x i8] c"Enter file destination:\00"
@str.4 = [41 x i8] c"\0AEnter data to be stored in to the file:\00"
define i32 @createf() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.4, i64 0, i64 0))
%7 = call signext i8 (...) @getchar()
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %16, label %10
10: ; preds = %0, %10
%11 = phi i8 [ %13, %10 ], [ %7, %0 ]
%12 = call i32 @putc(i8 signext %11, i32* %5)
%13 = call signext i8 (...) @getchar()
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %16, label %10
16: ; preds = %10, %0
%17 = call i32 @fclose(i32* %5)
ret i32 0
}