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


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe66(%rip),%rdi
lea    0xe67(%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    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    125e <run_test+0xde>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
lea    0xe1c(%rip),%rdi
lea    0xe2f(%rip),%rsi
call   1040 <freopen@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
lea    0xe0a(%rip),%rdi
lea    0xe01(%rip),%rsi
call   1040 <freopen@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
lea    0xdf7(%rip),%rdi
lea    0xde5(%rip),%rsi
call   1040 <freopen@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <smp2_main@plt>
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%rax
je     1252 <run_test+0xd2>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1257 <run_test+0xd7>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xe69(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11dd <run_test+0x5d>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
lea    0xe13(%rip),%rdi
lea    0xe26(%rip),%rsi
call   1040 <freopen@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
lea    0xe01(%rip),%rdi
lea    0xdf8(%rip),%rbx
mov    %rbx,%rsi
call   1040 <freopen@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
lea    0xdeb(%rip),%rdi
mov    %rbx,%rsi
call   1040 <freopen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1090 <smp2_main@plt>
mov    0x2d7e(%rip),%rcx
cmp    (%rcx),%rax
jne    124e <run_test+0xce>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"smp2.in\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [9 x i8] c"smp2.out\00"
@stdout = global i32 0
@.str.4 = [9 x i8] c"smp2.err\00"
@stderr = global i32 0
@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*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%10 = 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* %10, i32** %7
%11 = load i32*, i32** %7
%12 = load i8*, i8** %4
%13 = call i32 @fprintf(i32* %11, i8* %12)
%14 = load i32*, i32** %7
%15 = call i32 @fclose(i32* %14)
%16 = call i32 (...) @fork()
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %3
%20 = load i32, i32* @stdin
%21 = 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 %20)
%22 = load i32, i32* @stdout
%23 = 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 %22)
%24 = load i32, i32* @stderr
%25 = 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 %24)
br label %26
26: ; preds = %19
%27 = load i32, i32* %5
%28 = load i8**, i8*** %6
%29 = call i64 @smp2_main(i32 %27, i8** %28)
%30 = load i64, i64* @EXIT_SUCCESS
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %3
%39 = load i32, i32* %8
%40 = call i32 @waitpid(i32 %39, i32* %9, i32 0)
br label %41
41: ; preds = %38
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"smp2.in\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [9 x i8] c"smp2.out\00"
@stdout = global i32 0
@.str.4 = [9 x i8] c"smp2.err\00"
@stderr = global i32 0
@EXIT_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
define void @run_test(i8* nocapture %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = 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))
%6 = tail call i32 @fprintf(i32* %5, i8* %0)
%7 = tail call i32 @fclose(i32* %5)
%8 = tail call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %3
%11 = load i32, i32* @stdin
%12 = 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 %11)
%13 = load i32, i32* @stdout
%14 = 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 %13)
%15 = load i32, i32* @stderr
%16 = 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 %15)
%17 = tail call i64 @smp2_main(i32 %1, i8** %2)
%18 = load i64, i64* @EXIT_SUCCESS
%19 = icmp eq i64 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %10
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %10
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %3
%26 = bitcast i32* %4 to i8*
%27 = call i32 @waitpid(i32 %8, i32* %4, i32 0)
ret void
}