#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ smp4_main(int, char const **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/, int /*<<< orphan*/);
void run_test(int argc, const char **argv) {
  int fork_pid = fork();
  if (fork_pid == 0) {
    freopen("smp4.out", "w", stdout);
    exit(smp4_main(argc, argv));
    fclose(stdout);
  } else if (fork_pid > 0) {
    waitpid(fork_pid, 0, 0);
  } else {
    fprintf(stderr, "run_test: fork() error\n");
  }
}


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11b2 <run_test+0x52>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
lea    0xe6d(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1030 <freopen@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <smp4_main@plt>
mov    %eax,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11cd <run_test+0x6d>
mov    -0x14(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <waitpid@plt>
jmp    11e2 <run_test+0x82>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11e7 <run_test+0x87>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11a1 <run_test+0x41>
jle    1186 <run_test+0x26>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <waitpid@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    0xe4f(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1030 <freopen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <smp4_main@plt>
mov    %eax,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"smp4.out\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"run_test: fork() error\0A\00"
define void @run_test(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = call i32 (...) @fork()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stdout
%11 = call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = load i8**, i8*** %4
%14 = call i32 @smp4_main(i32 %12, i8** %13)
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %5
%21 = call i32 @waitpid(i32 %20, i32 0, i32 0)
br label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %25
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"smp4.out\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"run_test: fork() error\0A\00"
define void @run_test(i32 %0, i8** %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stdout
%7 = tail call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = tail call i32 @smp4_main(i32 %0, i8** %1)
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @waitpid(i32 %3, i32 0, i32 0)
br label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %12, %14
ret void
}