#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 */
char EOF;
int /*<<< orphan*/ assert(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main() {
  for (int i = 0; i < 2; i++) {
    FILE *file = fopen("/sandbox/input.txt", "r");
    assert(file != NULL);
    char c = fgetc(file);
    while (c != EOF) {
      int wrote = fputc(c, stdout);
      assert(wrote != EOF);
      c = fgetc(file);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1202 <main+0xc2>
lea    0xe99(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2e48(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11ef <main+0xaf>
mov    -0x11(%rbp),%al
mov    0x2e23(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e1c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
jmp    1195 <main+0x55>
jmp    11f4 <main+0xb4>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    0x2e70(%rip),%rbx
cmp    (%rbx),%al
je     11b7 <main+0x77>
mov    0x2e55(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
movsbl (%rbx),%ecx
xor    %edi,%edi
cmp    %ecx,%eax
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%rbx),%al
jne    1190 <main+0x50>
lea    0xe42(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%rbx),%al
je     1217 <main+0xd7>
mov    0x2dea(%rip),%r15
xchg   %ax,%ax
mov    (%r15),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
movsbl (%rbx),%ecx
xor    %edi,%edi
cmp    %ecx,%eax
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%rbx),%al
jne    11f0 <main+0xb0>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/sandbox/input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %6
6: ; preds = %36, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %39
9: ; preds = %6
%10 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32*, i32** %3
%16 = call signext i8 @fgetc(i32* %15)
store i8 %16, i8* %4
br label %17
17: ; preds = %23, %9
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %35
23: ; preds = %17
%24 = load i8, i8* %4
%25 = load i32, i32* @stdout
%26 = call i32 @fputc(i8 signext %24, i32 %25)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = load i8, i8* @EOF
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %27, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32*, i32** %3
%34 = call signext i8 @fgetc(i32* %33)
store i8 %34, i8* %4
br label %17
35: ; preds = %17
br label %36
36: ; preds = %35
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %6
39: ; preds = %6
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [19 x i8] c"/sandbox/input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@stdout = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp ne i32* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call signext i8 @fgetc(i32* %1)
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %20, label %8
8: ; preds = %0, %8
%9 = phi i8 [ %17, %8 ], [ %5, %0 ]
%10 = load i32, i32* @stdout
%11 = tail call i32 @fputc(i8 signext %9, i32 %10)
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call signext i8 @fgetc(i32* %1)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %20, label %8
20: ; preds = %8, %0
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i32* %21, null
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call signext i8 @fgetc(i32* %21)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %40, label %28
28: ; preds = %20, %28
%29 = phi i8 [ %37, %28 ], [ %25, %20 ]
%30 = load i32, i32* @stdout
%31 = tail call i32 @fputc(i8 signext %29, i32 %30)
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %31, %33
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
%37 = tail call signext i8 @fgetc(i32* %21)
%38 = load i8, i8* @EOF
%39 = icmp eq i8 %37, %38
br i1 %39, label %40, label %28
40: ; preds = %28, %20
ret i32 0
}