#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 *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *fin_ptr = fopen("./input.txt", "r");
  if (!fin_ptr)
    printf("input.txt not exist\n");
  FILE *fout_ptr = fopen("./output.txt", "w");
  if (!fout_ptr)
    printf("open output.txt error\n");
  char str[256];
  fscanf(fin_ptr, " %s", str);
  fprintf(fout_ptr, "file read: %s\n", str);
  fclose(fin_ptr);
  fclose(fout_ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <main+0x40>
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <main+0x6e>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe9d(%rip),%rdi
lea    0xeec(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1183 <main+0x33>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe82(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11aa <main+0x5a>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rsi
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rdx
call   1050 <fscanf@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"./input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"input.txt not exist\0A\00"
@.str.3 = [13 x i8] c"./output.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [23 x i8] c"open output.txt error\0A\00"
@.str.6 = [4 x i8] c" %s\00"
@.str.7 = [15 x i8] c"file read: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [256 x i8]
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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 ne i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = load i32*, i32** %2
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %3
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%22 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"./input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [13 x i8] c"./output.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c" %s\00"
@.str.7 = [15 x i8] c"file read: %s\0A\00"
@str = [20 x i8] c"input.txt not exist\00"
@str.8 = [22 x i8] c"open output.txt error\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%13 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%14 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %12)
%15 = call i32 @fclose(i32* %2)
%16 = call i32 @fclose(i32* %7)
ret i32 0
}