#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main() {
  FILE *fp;
  char filename[200];
  char str[200];
  printf("Please enter the name of the file you wish to open: ");
  gets(filename);
  printf("Opening %s", filename);
  fp = fopen(filename, "a");
  if (fp == NULL) {
    printf("\nError opening the file");
    getchar();
    exit(1);
  }
  printf("\nEnter new text, type exit() to save and quit\n");
  while (strcmp(gets(str), "exit()") != 0) {
    fprintf(fp, "\n%s", str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe0(%rbp),%rdi
call   1070 <gets@plt>
lea    -0xe0(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f2 <main+0x82>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1b0(%rbp),%rdi
call   1070 <gets@plt>
mov    %eax,%edi
lea    0xe74(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1240 <main+0xd0>
mov    -0x10(%rbp),%rdi
lea    -0x1b0(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1200 <main+0x90>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x198,%rsp
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd0(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <gets@plt>
lea    0xe82(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1246 <main+0xc6>
mov    %rax,%r15
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1080 <gets@plt>
lea    0xe6b(%rip),%rsi
mov    %eax,%edi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1235 <main+0xb5>
lea    0xe5f(%rip),%r14
mov    %rsp,%rbx
lea    0xe4e(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <gets@plt>
mov    %eax,%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1210 <main+0x90>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [53 x i8] c"Please enter the name of the file you wish to open: \00"
@.str.1 = [11 x i8] c"Opening %s\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [24 x i8] c"\0AError opening the file\00"
@.str.4 = [47 x i8] c"\0AEnter new text, type exit() to save and quit\0A\00"
@.str.5 = [7 x i8] c"exit()\00"
@.str.6 = [4 x i8] c"\0A%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [200 x i8]
%4 = alloca [200 x i8]
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (...) @getchar()
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %25, %18
%21 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%22 = call i32 @gets(i8* %21)
%23 = call i64 @strcmp(i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32*, i32** %2
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%28 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %27)
br label %20
29: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [53 x i8] c"Please enter the name of the file you wish to open: \00"
@.str.1 = [11 x i8] c"Opening %s\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [24 x i8] c"\0AError opening the file\00"
@.str.5 = [7 x i8] c"exit()\00"
@.str.6 = [4 x i8] c"\0A%s\00"
@str = [46 x i8] c"\0AEnter new text, type exit() to save and quit\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = alloca [200 x i8]
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @gets(i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%8 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (...) @getchar()
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%16 = call i32 @gets(i8* %4)
%17 = call i64 @strcmp(i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14, %19
%20 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%21 = call i32 @gets(i8* %4)
%22 = call i64 @strcmp(i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %19
24: ; preds = %19, %14
ret i32 0
}