#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*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(void) {
  int pid;
  int fd;
  if ((pid = fork()) == -1) {
    perror("fork");
    exit(1);
  } else if (pid == 0) {
    close(1);
    fd = creat("ll.txt", 0644);
    execlp("ls", "ls", "-alF", NULL);
    perror("execlp");
    exit(1);
  } else {
    wait(0);
    printf("finish parent\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11b8 <main+0x38>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1210 <main+0x90>
mov    $0x1,%edi
call   1040 <close@plt>
lea    0xe32(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0xc(%rbp)
lea    0xe25(%rip),%rsi
lea    0xe21(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
lea    0xe13(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1090 <wait@plt>
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11a8 <main+0x28>
cmp    $0xffffffff,%eax
je     11e4 <main+0x64>
xor    %edi,%edi
call   1090 <wait@plt>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x1,%edi
call   1040 <close@plt>
lea    0xe4c(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
lea    0xe42(%rip),%rdi
lea    0xe3e(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1080 <execlp@plt>
lea    0xe32(%rip),%rdi
jmp    11eb <main+0x6b>
lea    0xe15(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [7 x i8] c"ll.txt\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [5 x i8] c"-alF\00"
@.str.4 = [7 x i8] c"execlp\00"
@.str.5 = [15 x i8] c"finish parent\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i32 @close(i32 1)
%14 = call i32 @creat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 420)
store i32 %14, i32* %3
%15 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* null)
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = call i32 @wait(i32 0)
%20 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [7 x i8] c"ll.txt\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [5 x i8] c"-alF\00"
@.str.4 = [7 x i8] c"execlp\00"
@str = [14 x i8] c"finish parent\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %11 [
i32 -1, label %2
i32 0, label %5
]
2: ; preds = %0
%3 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @exit(i32 1)
unreachable
5: ; preds = %0
%6 = tail call i32 @close(i32 1)
%7 = tail call i32 @creat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 420)
%8 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* null)
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32 @wait(i32 0)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
ret i32 0
}