#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*/ fputc(char, int /*<<< orphan*/ *);
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  FILE *fp;
  char ch, filename[10];
  printf("Please open a file");
  scanf("%s", filename);
  if ((fp = fopen(filename, "w")) == NULL) {
    printf("can non't open this file");
    exit(0);
  }
  ch = getchar();
  printf("please enter a String that ready store in disk");
  ch = getchar();
  while (ch != '#') {
    fputc(ch, fp);
    putchar(ch);
    ch = getchar();
  }
  fclose(fp);
  putchar(10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1b(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x1b(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11dc <main+0x5c>
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x11(%rbp)
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x23,%eax
je     1230 <main+0xb0>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x11(%rbp)
jmp    11fc <main+0x7c>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe73(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    0xe(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     120c <main+0x8c>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x23,%al
je     11f1 <main+0x71>
movsbl %al,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe05(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Please open a file\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [25 x i8] c"can non't open this file\00"
@.str.4 = [47 x i8] c"please enter a String that ready store in disk\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca [10 x i8]
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %0
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%17 = call signext i8 (...) @getchar()
store i8 %17, i8* %3
br label %18
18: ; preds = %22, %14
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 35
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i8, i8* %3
%24 = load i32*, i32** %2
%25 = call i32 @fputc(i8 signext %23, i32* %24)
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = call i32 @putchar(i32 %27)
%29 = call signext i8 (...) @getchar()
store i8 %29, i8* %3
br label %18
30: ; preds = %18
%31 = load i32*, i32** %2
%32 = call i32 @fclose(i32* %31)
%33 = call i32 @putchar(i32 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Please open a file\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [25 x i8] c"can non't open this file\00"
@.str.4 = [47 x i8] c"please enter a String that ready store in disk\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 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 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %0
%11 = call signext i8 (...) @getchar()
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%13 = call signext i8 (...) @getchar()
%14 = icmp eq i8 %13, 35
br i1 %14, label %22, label %15
15: ; preds = %10, %15
%16 = phi i8 [ %20, %15 ], [ %13, %10 ]
%17 = sext i8 %16 to i32
%18 = call i32 @fputc(i8 signext %16, i32* %5)
%19 = call i32 @putchar(i32 %17)
%20 = call signext i8 (...) @getchar()
%21 = icmp eq i8 %20, 35
br i1 %21, label %22, label %15
22: ; preds = %15, %10
%23 = call i32 @fclose(i32* %5)
%24 = call i32 @putchar(i32 10)
ret i32 0
}