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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdx
lea    0xe82(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1030 <freopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%eax
je     1214 <main+0xc4>
mov    -0x1c(%rbp),%eax
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
jmp    11c1 <main+0x71>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
lea    0xeb0(%rip),%r14
mov    %r14,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
lea    0xe92(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <freopen@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e3a(%rip),%rbx
cmp    (%rbx),%eax
je     11e4 <main+0x94>
mov    0x2e1f(%rip),%r15
nopl   0x0(%rax)
mov    (%r15),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
xor    %edi,%edi
cmp    (%rbx),%eax
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%rbx),%eax
jne    11c0 <main+0x70>
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"
@.str.2 = [20 x i8] c"/sandbox/input2.txt\00"
@EOF = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = 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* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32*, i32** %2
%12 = call i32* @freopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %11)
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32*, i32** %3
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %4
br label %19
19: ; preds = %23, %0
%20 = load i32, i32* %4
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i32, i32* %4
%25 = trunc i32 %24 to i8
%26 = load i32, i32* @stdout
%27 = call i32 @fputc(i8 signext %25, i32 %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = load i32, i32* @EOF
%30 = icmp ne i32 %28, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32*, i32** %3
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %4
br label %19
35: ; preds = %19
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [19 x i8] c"/sandbox/input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"/sandbox/input2.txt\00"
@EOF = global i32 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 i32* @freopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = icmp ne i32* %5, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @fgetc(i32* %5)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %24, label %12
12: ; preds = %0, %12
%13 = phi i32 [ %21, %12 ], [ %9, %0 ]
%14 = trunc i32 %13 to i8
%15 = load i32, i32* @stdout
%16 = tail call i32 @fputc(i8 signext %14, i32 %15)
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i32 @fgetc(i32* %5)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %12
24: ; preds = %12, %0
ret i32 0
}