#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int main(void) {
  FILE *filep;
  filep = fopen("input.txt", "r");
  if (filep != NULL) {
    FILE *outfile;
    outfile = fopen("output.txt", "w");
    if (outfile != NULL) {
      char line[100];
      while (fgets(line, 100, filep) != NULL) {
        fprintf(outfile, "fprintf line = %s\n", line);
      }
      fclose(outfile);
    }
    fclose(filep);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e2 <main+0xa2>
lea    0xe91(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d9 <main+0x99>
jmp    119b <main+0x5b>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11d0 <main+0x90>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
jmp    119b <main+0x5b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d3 <main+0x93>
mov    %rax,%r14
lea    0xe9f(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11cb <main+0x8b>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c3 <main+0x83>
lea    0xe7c(%rip),%r15
mov    %rsp,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x60>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"fprintf line = %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %19, label %4
4: ; preds = %0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 100, i32* %2)
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %7, %11
%12 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%13 = call i32* @fgets(i8* %8, i32 100, i32* %2)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %11
15: ; preds = %11, %7
%16 = call i32 @fclose(i32* %5)
br label %17
17: ; preds = %15, %4
%18 = call i32 @fclose(i32* %2)
br label %19
19: ; preds = %17, %0
ret i32 0
}