#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  pid_t proc_id = fork();
  if (proc_id == -1) {
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (proc_id == 0) {
    execl("/bin/cat", "cat", "/proc/loadavg", NULL);
    perror("execl");
    exit(EXIT_FAILURE);
  } else {
    wait(NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118d <main+0x3d>
lea    0xe86(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11cf <main+0x7f>
lea    0xe67(%rip),%rdi
lea    0xe65(%rip),%rsi
lea    0xe62(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <execl@plt>
lea    0xe60(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     116c <main+0x1c>
cmp    $0xffffffff,%eax
je     1191 <main+0x41>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe92(%rip),%rdi
lea    0xe90(%rip),%rsi
lea    0xe8d(%rip),%rdx
xor    %ecx,%ecx
call   1050 <execl@plt>
lea    0xe8d(%rip),%rdi
jmp    1198 <main+0x48>
lea    0xe68(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/bin/cat\00"
@.str.2 = [4 x i8] c"cat\00"
@.str.3 = [14 x i8] c"/proc/loadavg\00"
@.str.4 = [6 x i8] c"execl\00"
define i32 @main(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, -1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* null)
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %13
%22 = call i32 @wait(i32* null)
br label %23
23: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/bin/cat\00"
@.str.2 = [4 x i8] c"cat\00"
@.str.3 = [14 x i8] c"/proc/loadavg\00"
@.str.4 = [6 x i8] c"execl\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %13 [
i32 -1, label %4
i32 0, label %8
]
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = tail call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* null)
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = tail call i32 @wait(i32* null)
ret i32 0
}