#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ *stdout;
int main() {
  int N = 100;
  FILE *fp = fopen("number.txt", "w");
  if (!fp) {
    perror("file open error");
    exit(10);
  }
  for (int i = 0; i <= N; i++) {
    fprintf(fp, "%d\n", i);
  }
  fclose(fp);
  fp = fopen("number.txt", "r");
  int s = 0;
  for (int i = 0; i <= N; i++) {
    int x;
    fscanf(fp, "%d", &x);
    s += x;
  }
  fclose(fp);
  printf("%d\n", s);
  int a[] = {1, 2, 3};
  fp = fopen("test.txt", "w");
  fwrite(a, sizeof(int), 3, fp);
  fclose(fp);
  fp = fopen("test.txt", "r");
  int b[3];
  fread(b, sizeof(int), 3, fp);
  fclose(fp);
  for (int i = 0; i < 3; i++) {
    fprintf(stdout, "%d\n", b[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
lea    0xe53(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11de <main+0x4e>
lea    0xe3e(%rip),%rdi
call   1090 <perror@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1212 <main+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe1e(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e5 <main+0x55>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdde(%rip),%rdi
lea    0xdf2(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1277 <main+0xe7>
mov    -0x10(%rbp),%rdi
lea    0xdca(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1240 <main+0xb0>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%esi
lea    0xd93(%rip),%rdi
call   1050 <printf@plt>
mov    0xd9a(%rip),%rax
mov    %rax,-0x2c(%rbp)
mov    0xd98(%rip),%eax
mov    %eax,-0x24(%rbp)
lea    0xd7a(%rip),%rdi
lea    0xd5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x2c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x3,%edx
call   10b0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd43(%rip),%rdi
lea    0xd33(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x3,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    134e <main+0x1be>
mov    0x2cb7(%rip),%rax
mov    (%rax),%rdi
movslq -0x3c(%rbp),%rax
mov    -0x38(%rbp,%rax,4),%edx
lea    0xce2(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1318 <main+0x188>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe5d(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1312 <main+0x182>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe59(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x65,%ebp
jne    11d0 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe0c(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
xor    %ebp,%ebp
mov    $0x65,%ebx
lea    0xe10(%rip),%r14
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
add    0x8(%rsp),%ebp
add    $0xffffffff,%ebx
jne    1220 <main+0x90>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xdd7(%rip),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    0xde2(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xdcf(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xdb7(%rip),%rbp
lea    0xd97(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x3,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd76(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0x14(%rsp),%rdi
mov    $0x4,%esi
mov    $0x3,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2d0a(%rip),%rbx
mov    (%rbx),%rdi
mov    0x14(%rsp),%edx
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%rdi
mov    0x18(%rsp),%edx
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%rdi
mov    0x1c(%rsp),%edx
mov    %r14,%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf4(%rip),%rdi
call   1090 <perror@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"number.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [16 x i8] c"file open error\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@__const.main.a = [3 x i32] [i32 1, i32 2, i32 3]
@.str.6 = [9 x i8] c"test.txt\00"
@stdout = global i32* null
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i32]
%9 = alloca [3 x i32]
%10 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %2
%11 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 10)
unreachable
17: ; preds = %0
store i32 0, i32* %4
br label %18
18: ; preds = %26, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load i32*, i32** %3
%24 = load i32, i32* %4
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %18
29: ; preds = %18
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
%32 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %32, i32** %3
store i32 0, i32* %5
store i32 0, i32* %6
br label %33
33: ; preds = %43, %29
%34 = load i32, i32* %6
%35 = load i32, i32* %2
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = load i32*, i32** %3
%39 = call i32 @fscanf(i32* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %7)
%40 = load i32, i32* %7
%41 = load i32, i32* %5
%42 = add nsw i32 %41, %40
store i32 %42, i32* %5
br label %43
43: ; preds = %37
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %33
46: ; preds = %33
%47 = load i32*, i32** %3
%48 = call i32 @fclose(i32* %47)
%49 = load i32, i32* %5
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%51 = bitcast [3 x i32]* %8 to i8*
%52 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %52, i32** %3
%53 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%54 = load i32*, i32** %3
%55 = call i32 @fwrite(i32* %53, i32 4, i32 3, i32* %54)
%56 = load i32*, i32** %3
%57 = call i32 @fclose(i32* %56)
%58 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %58, i32** %3
%59 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%60 = load i32*, i32** %3
%61 = call i32 @fread(i32* %59, i32 4, i32 3, i32* %60)
%62 = load i32*, i32** %3
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %10
br label %64
64: ; preds = %74, %46
%65 = load i32, i32* %10
%66 = icmp slt i32 %65, 3
br i1 %66, label %67, label %77
67: ; preds = %64
%68 = load i32*, i32** @stdout
%69 = load i32, i32* %10
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = call i32 @fprintf(i32* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %67
%75 = load i32, i32* %10
%76 = add nsw i32 %75, 1
store i32 %76, i32* %10
br label %64
77: ; preds = %64
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"number.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [16 x i8] c"file open error\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@__const.main.a = [3 x i32] [i32 1, i32 2, i32 3]
@.str.6 = [9 x i8] c"test.txt\00"
@stdout = global i32* null
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca [3 x i32]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 10)
unreachable
9: ; preds = %13
%10 = tail call i32 @fclose(i32* %4)
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = bitcast i32* %1 to i8*
br label %42
13: ; preds = %0, %13
%14 = phi i32 [ %16, %13 ], [ 0, %0 ]
%15 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i32 %14, 1
%17 = icmp eq i32 %16, 101
br i1 %17, label %9, label %13
18: ; preds = %42
%19 = call i32 @fclose(i32* %11)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%21 = bitcast [3 x i32]* %2 to i8*
%22 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%24 = call i32 @fwrite(i32* %23, i32 4, i32 3, i32* %22)
%25 = call i32 @fclose(i32* %22)
%26 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = bitcast [3 x i32]* %3 to i8*
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%29 = call i32 @fread(i32* %28, i32 4, i32 3, i32* %26)
%30 = call i32 @fclose(i32* %26)
%31 = load i32*, i32** @stdout
%32 = load i32, i32* %28
%33 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load i32*, i32** @stdout
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32*, i32** @stdout
%39 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
%40 = load i32, i32* %39
%41 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %40)
ret i32 0
42: ; preds = %9, %42
%43 = phi i32 [ 0, %9 ], [ %48, %42 ]
%44 = phi i32 [ 0, %9 ], [ %47, %42 ]
%45 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%46 = load i32, i32* %1
%47 = add nsw i32 %46, %44
%48 = add nuw nsw i32 %43, 1
%49 = icmp eq i32 %48, 101
br i1 %49, label %18, label %42
}