#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 *, char *);
int main() {
  char tmp[1000];
  FILE *read1 = fopen("read1.txt", "r");
  fscanf(read1, "%s", &tmp);
  printf("read1:%s\n", tmp);
  fclose(read1);
  tmp[0] = 0;
  FILE *read2 = fopen("read2.txt", "r");
  fscanf(read2, "%s", &tmp);
  printf("read2:%s\n", tmp);
  fclose(read2);
  FILE *write1 = fopen("write1.txt", "w");
  fprintf(write1, "write1 test\n");
  fclose(write1);
  FILE *write2 = fopen("write2.txt", "w");
  fprintf(write2, "write2 test\n");
  fclose(write2);
  FILE *write3 = fopen("write3.txt", "w");
  fprintf(write3, "write3 test\n");
  fclose(write3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x3f8(%rbp)
mov    -0x3f8(%rbp),%rdi
lea    -0x3f0(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3f8(%rbp),%rdi
call   1030 <fclose@plt>
movb   $0x0,-0x3f0(%rbp)
lea    0xe5d(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x400(%rbp)
mov    -0x400(%rbp),%rdi
lea    -0x3f0(%rbp),%rdx
lea    0xe28(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x400(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe1e(%rip),%rdi
lea    0xe22(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x408(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdff(%rip),%rdi
lea    0xde9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x410(%rbp)
mov    -0x410(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x410(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdde(%rip),%rdi
lea    0xdb0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3e8,%rsp
lea    0xe9b(%rip),%rdi
lea    0xe9e(%rip),%r14
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%r12
mov    %rsp,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
lea    0xe79(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movb   $0x0,(%rsp)
lea    0xe68(%rip),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
lea    0xe52(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe45(%rip),%rdi
lea    0xe49(%rip),%r14
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe39(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe25(%rip),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe1e(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe0a(%rip),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe03(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"read1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [10 x i8] c"read1:%s\0A\00"
@.str.4 = [10 x i8] c"read2.txt\00"
@.str.5 = [10 x i8] c"read2:%s\0A\00"
@.str.6 = [11 x i8] c"write1.txt\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [13 x i8] c"write1 test\0A\00"
@.str.9 = [11 x i8] c"write2.txt\00"
@.str.10 = [13 x i8] c"write2 test\0A\00"
@.str.11 = [11 x i8] c"write3.txt\00"
@.str.12 = [13 x i8] c"write3 test\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = bitcast [1000 x i8]* %1 to i8**
%10 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9)
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
store i8 0, i8* %15
%16 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = bitcast [1000 x i8]* %1 to i8**
%19 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %18)
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
%24 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %24, i32** %4
%25 = load i32*, i32** %4
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%27 = load i32*, i32** %4
%28 = call i32 @fclose(i32* %27)
%29 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %29, i32** %5
%30 = load i32*, i32** %5
%31 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%32 = load i32*, i32** %5
%33 = call i32 @fclose(i32* %32)
%34 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %34, i32** %6
%35 = load i32*, i32** %6
%36 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"read1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [10 x i8] c"read1:%s\0A\00"
@.str.4 = [10 x i8] c"read2.txt\00"
@.str.5 = [10 x i8] c"read2:%s\0A\00"
@.str.6 = [11 x i8] c"write1.txt\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [13 x i8] c"write1 test\0A\00"
@.str.9 = [11 x i8] c"write2.txt\00"
@.str.10 = [13 x i8] c"write2 test\0A\00"
@.str.11 = [11 x i8] c"write3.txt\00"
@.str.12 = [13 x i8] c"write3 test\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast [1000 x i8]* %1 to i8**
%5 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%6 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%7 = call i32 @fclose(i32* %3)
store i8 0, i8* %2
%8 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%10 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%11 = call i32 @fclose(i32* %8)
%12 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%13 = call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i64 12, i64 1, i32* %12)
%14 = call i32 @fclose(i32* %12)
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%16 = call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i64 12, i64 1, i32* %15)
%17 = call i32 @fclose(i32* %15)
%18 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%19 = call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i64 12, i64 1, i32* %18)
%20 = call i32 @fclose(i32* %18)
ret i32 0
}