#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fi = fopen("fio.c", "r");
  if (fi == NULL) {
    printf("打開文件失敗!");
    return 1;
  }
  char str[3000];
  fscanf(fi, "%s", str);
  fscanf(fi, "%s", str);
  fclose(fi);
  printf("--%s\n", str);
  FILE *fo = fopen("out", "w");
  if (fo == NULL) {
    printf("打開文件失敗!");
    return 1;
  }
  fprintf(fo, "向文件寫數據\n");
  fprintf(fo, "%s", str);
  fclose(fo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbe0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <main+0x4e>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1270 <main+0x120>
mov    -0x10(%rbp),%rdi
lea    -0xbd0(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0xbd0(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0xbd0(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe34(%rip),%rdi
lea    0xe31(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xbd8(%rbp)
cmpq   $0x0,-0xbd8(%rbp)
jne    122c <main+0xdc>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1270 <main+0x120>
mov    -0xbd8(%rbp),%rdi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xbd8(%rbp),%rdi
lea    -0xbd0(%rbp),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xbd8(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xbe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xbc0,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1214 <main+0xb4>
mov    %rax,%rbx
lea    0xe8b(%rip),%rbp
mov    %rsp,%r14
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1060 <fscanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe60(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1214 <main+0xb4>
mov    %rax,%rbx
lea    0xe3e(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1227 <main+0xc7>
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0xbc0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"fio.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"\E6\89\93\E9\96\8B\E6\96\87\E4\BB\B6\E5\A4\B1\E6\95\97!\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [6 x i8] c"--%s\0A\00"
@.str.5 = [4 x i8] c"out\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [20 x i8] c"\E5\90\91\E6\96\87\E4\BB\B6\E5\AF\AB\E6\95\B8\E6\93\9A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [3000 x i8]
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %34
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = getelementptr inbounds [3000 x i8], [3000 x i8]* %3, i64 0, i64 0
%13 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %2
%15 = getelementptr inbounds [3000 x i8], [3000 x i8]* %3, i64 0, i64 0
%16 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
%19 = getelementptr inbounds [3000 x i8], [3000 x i8]* %3, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %21, i32** %4
%22 = load i32*, i32** %4
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %10
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %34
26: ; preds = %10
%27 = load i32*, i32** %4
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%29 = load i32*, i32** %4
%30 = getelementptr inbounds [3000 x i8], [3000 x i8]* %3, i64 0, i64 0
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %26, %24, %8
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"fio.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"\E6\89\93\E9\96\8B\E6\96\87\E4\BB\B6\E5\A4\B1\E6\95\97!\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [6 x i8] c"--%s\0A\00"
@.str.5 = [4 x i8] c"out\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [20 x i8] c"\E5\90\91\E6\96\87\E4\BB\B6\E5\AF\AB\E6\95\B8\E6\93\9A\0A\00"
define i32 @main() {
%1 = alloca [3000 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %22
6: ; preds = %0
%7 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 0
%8 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%10 = call i32 @fclose(i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%12 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %20
16: ; preds = %6
%17 = call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64 19, i64 1, i32* %12)
%18 = call i32 @fputs(i8* %7, i32* %12)
%19 = call i32 @fclose(i32* %12)
br label %20
20: ; preds = %16, %14
%21 = phi i32 [ 1, %14 ], [ 0, %16 ]
br label %22
22: ; preds = %20, %4
%23 = phi i32 [ 1, %4 ], [ %21, %20 ]
ret i32 %23
}