#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execlp(char *, char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ open(char *, int, int);
int /*<<< orphan*/ wait();
int main(int argc, char *argv[]) {
  if (!fork()) {
    close(1);
    open("fout", O_WRONLY | O_CREAT, 0666);
    execlp(argv[1], argv[1], (char *)NULL);
  }
  wait();
  execlp(argv[2], argv[2], (char *)NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%eax
jne    11bc <main+0x6c>
mov    $0x1,%edi
call   1030 <close@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
lea    0xe67(%rip),%rdi
mov    $0x1b6,%edx
call   1040 <open@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execlp@plt>
mov    $0x0,%al
call   1060 <wait@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execlp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    119a <main+0x4a>
mov    $0x1,%edi
call   1030 <close@plt>
mov    0x2e60(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe7e(%rip),%rdi
mov    $0x1b6,%edx
call   1040 <open@plt>
mov    0x8(%rbx),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1050 <execlp@plt>
xor    %eax,%eax
call   1060 <wait@plt>
mov    0x10(%rbx),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1050 <execlp@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"fout\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 (...) @fork()
%7 = icmp ne i32 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %2
%9 = call i32 @close(i32 1)
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12, i32 438)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @execlp(i8* %16, i8* %19, i8* null)
br label %21
21: ; preds = %8, %2
%22 = call i32 (...) @wait()
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @execlp(i8* %25, i8* %28, i8* null)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fout\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i32 @close(i32 1)
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9, i32 438)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @execlp(i8* %12, i8* %12, i8* null)
br label %14
14: ; preds = %5, %2
%15 = tail call i32 (...) @wait()
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @execlp(i8* %17, i8* %17, i8* null)
ret i32 0
}