#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strlen(char *);
void main() {
  FILE *fp;
  char str[81], filename[80];
  gets(filename);
  if ((fp = fopen(filename, "w")) == NULL) {
    printf("Can not open this file!\n");
    exit(0);
  }
  gets(str);
  while (strlen(str) > 0) {
    fputs(str, fp);
    fputs("\n", fp);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    -0xb0(%rbp),%rdi
call   1070 <gets@plt>
lea    -0xb0(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11bb <main+0x4b>
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    -0x60(%rbp),%rdi
call   1070 <gets@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11f9 <main+0x89>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1060 <fputs@plt>
jmp    11c4 <main+0x54>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <gets@plt>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1208 <main+0x88>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1080 <gets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jle    11f5 <main+0x75>
mov    %rsp,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fputs@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jg     11d0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [25 x i8] c"Can not open this file!\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca i32*
%2 = alloca [81 x i8]
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = call i32 @gets(i8* %4)
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %1
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%14 = call i32 @gets(i8* %13)
br label %15
15: ; preds = %19, %12
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%21 = load i32*, i32** %1
%22 = call i32 @fputs(i8* %20, i32* %21)
%23 = load i32*, i32** %1
%24 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32* %23)
br label %15
25: ; preds = %15
%26 = load i32*, i32** %1
%27 = call i32 @fclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@str = [24 x i8] c"Can not open this file!\00"
define void @main() {
%1 = alloca [81 x i8]
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = call i32 @gets(i8* %4)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = call i32 @gets(i8* %3)
%13 = call i64 @strlen(i8* %3)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11, %15
%16 = call i32 @fputs(i8* %3, i32* %6)
%17 = call i32 @fputc(i32 10, i32* %6)
%18 = call i64 @strlen(i8* %3)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %11
%21 = call i32 @fclose(i32* %6)
ret void
}