#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*/ EXIT_FAILURE;
scalar_t__ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/ *);
scalar_t__ main(int, char **);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
void run_test(const char *input, int argc, char **argv) {
  FILE *in = fopen("test.in", "w");
  fprintf(in, input);
  fclose(in);
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
  freopen("test.err", "w", stderr);
  do {
    if (main(argc, argv) != EXIT_SUCCESS)
      exit(EXIT_FAILURE);
  } while (0);
  fclose(stdout);
  fclose(stderr);
}


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%rdx
lea    0xe4f(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1040 <freopen@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%rdx
lea    0xe3c(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1040 <freopen@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rdi
lea    0xe16(%rip),%rsi
call   1040 <freopen@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <main@plt>
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%rax
je     1221 <run_test+0xc1>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1226 <run_test+0xc6>
mov    0x2d9b(%rip),%rax
mov    (%rax),%rdi
call   1030 <fclose@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0xe85(%rip),%r13
lea    0xe86(%rip),%r12
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
mov    %r13,%rdi
call   1040 <freopen@plt>
mov    0x2e05(%rip),%rbx
mov    (%rbx),%rdx
lea    0xe3d(%rip),%rdi
mov    %r12,%rsi
call   1040 <freopen@plt>
mov    0x2dfc(%rip),%rbp
mov    0x0(%rbp),%rdx
lea    0xe2c(%rip),%rdi
mov    %r12,%rsi
call   1040 <freopen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1060 <main@plt>
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%rax
jne    1225 <run_test+0xc5>
mov    (%rbx),%rdi
call   1030 <fclose@plt>
mov    0x0(%rbp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"test.in\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.3 = [9 x i8] c"test.out\00"
@stdout = global i32* null
@.str.4 = [9 x i8] c"test.err\00"
@stderr = global i32* null
@EXIT_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
define void @run_test(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%8 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = load i8*, i8** %4
%11 = call i32 @fprintf(i32* %9, i8* %10)
%12 = load i32*, i32** %7
%13 = call i32 @fclose(i32* %12)
%14 = load i32*, i32** @stdin
%15 = call i32 @freopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32* %14)
%16 = load i32*, i32** @stdout
%17 = call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = load i32*, i32** @stderr
%19 = call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %18)
br label %20
20: ; preds = %3
%21 = load i32, i32* %5
%22 = load i8**, i8*** %6
%23 = call i64 @main(i32 %21, i8** %22)
%24 = load i64, i64* @EXIT_SUCCESS
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %20
br label %30
30: ; preds = %29
%31 = load i32*, i32** @stdout
%32 = call i32 @fclose(i32* %31)
%33 = load i32*, i32** @stderr
%34 = call i32 @fclose(i32* %33)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"test.in\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.3 = [9 x i8] c"test.out\00"
@stdout = global i32* null
@.str.4 = [9 x i8] c"test.err\00"
@stderr = global i32* null
@EXIT_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
define void @run_test(i8* nocapture %0, i32 %1, i8** %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @fprintf(i32* %4, i8* %0)
%6 = tail call i32 @fclose(i32* %4)
%7 = load i32*, i32** @stdin
%8 = tail call i32 @freopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%9 = load i32*, i32** @stdout
%10 = tail call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%11 = load i32*, i32** @stderr
%12 = tail call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %11)
%13 = tail call i64 @main(i32 %1, i8** %2)
%14 = load i64, i64* @EXIT_SUCCESS
%15 = icmp eq i64 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %3
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
%20 = load i32*, i32** @stdout
%21 = tail call i32 @fclose(i32* %20)
%22 = load i32*, i32** @stderr
%23 = tail call i32 @fclose(i32* %22)
ret void
}