#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncat(char *, char *, int);
int main(int argc, char *argv[]) {
  FILE *fp;
  char c, str[32], buf[64] = "The name of this file is ";
  int i;
  printf("\n\n Enter the file name: ");
  gets(str);
  if (!(fp = fopen(str, "w"))) {
    fprintf(stderr, "Could not open file %s.\n", str);
    exit(-1);
  }
  strncat(buf, str, 64);
  for (i = 0; buf[i]; i++)
    fputc(buf[i], fp);
  fclose(fp);
  fp = fopen(str, "r");
  while (!feof(fp)) {
    c = fgetc(fp);
    printf("%c", c);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x40,%edx
call   10a0 <memcpy@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   10b0 <gets@plt>
lea    -0x40(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1236 <main+0x86>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x40,%edx
call   1050 <strncat@plt>
movl   $0x0,-0x84(%rbp)
movslq -0x84(%rbp),%rax
cmpb   $0x0,-0x80(%rbp,%rax,1)
je     128f <main+0xdf>
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1252 <main+0xa2>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x40(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12ca <main+0x11a>
jmp    12ed <main+0x13d>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ac <main+0xfc>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movaps 0xe72(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe56(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe3a(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe1e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10b0 <gets@plt>
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12b0 <main+0x100>
mov    %rax,%r14
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x40,%edx
call   1060 <strncat@plt>
mov    0x20(%rsp),%al
test   %al,%al
je     1256 <main+0xa6>
lea    0x21(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1080 <fputc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1240 <main+0x90>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe0f(%rip),%rsi
mov    %rsp,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   10a0 <feof@plt>
test   %eax,%eax
jne    129e <main+0xee>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
jmp    1280 <main+0xd0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
mov    %rsp,%rdx
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@__const.main.buf = [64 x i8] c"The name of this file is \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [25 x i8] c"\0A\0A Enter the file name: \00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Could not open file %s.\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
%8 = alloca [32 x i8]
%9 = alloca [64 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [64 x i8]* %9 to i8*
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%14 = call i32 @gets(i8* %13)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%26 = call i32 @strncat(i8* %24, i8* %25, i32 64)
store i32 0, i32* %10
br label %27
27: ; preds = %40, %23
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %27
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = load i32*, i32** %6
%39 = call i32 @fputc(i8 signext %37, i32* %38)
br label %40
40: ; preds = %33
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %27
43: ; preds = %27
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %47, i32** %6
br label %48
48: ; preds = %53, %43
%49 = load i32*, i32** %6
%50 = call i32 @feof(i32* %49)
%51 = icmp ne i32 %50, 0
%52 = xor i1 %51, true
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i32*, i32** %6
%55 = call signext i8 @fgetc(i32* %54)
store i8 %55, i8* %7
%56 = load i8, i8* %7
%57 = sext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %57)
br label %48
59: ; preds = %48
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [64 x i8] c"The name of this file is \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [25 x i8] c"\0A\0A Enter the file name: \00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Could not open file %s.\0A\00"
@.str.3 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @gets(i8* %5)
%9 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = call i32 @strncat(i8* %6, i8* %5, i32 64)
%17 = load i8, i8* %6
%18 = icmp eq i8 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %15, %19
%20 = phi i64 [ %23, %19 ], [ 0, %15 ]
%21 = phi i8 [ %25, %19 ], [ %17, %15 ]
%22 = call i32 @fputc(i8 signext %21, i32* %9)
%23 = add nuw i64 %20, 1
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %19
27: ; preds = %19, %15
%28 = call i32 @fclose(i32* %9)
%29 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @feof(i32* %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %27, %32
%33 = call signext i8 @fgetc(i32* %29)
%34 = sext i8 %33 to i32
%35 = call i32 @putchar(i32 %34)
%36 = call i32 @feof(i32* %29)
%37 = icmp eq i32 %36, 0
br i1 %37, label %32, label %38
38: ; preds = %32, %27
%39 = call i32 @fclose(i32* %29)
ret i32 0
}