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

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, char const *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__);
int main(int argc, char const *argv[]) {
  const char *filename = argv[1];
  pid_t cpid;
  if ((cpid = fork()) == 0) {
    execl("/bin/cat", "cat", argv[1], (char *)0);
  } else if (cpid > 0) {
    printf("Hello, this is %d's dad\n", cpid);
  } else {
    perror("fork() failed");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ab <main+0x5b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe6a(%rip),%rdi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <execl@plt>
jmp    11dc <main+0x8c>
cmpq   $0x0,-0x20(%rbp)
jle    11cb <main+0x7b>
mov    -0x20(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <main+0x87>
lea    0xe50(%rip),%rdi
call   1040 <perror@plt>
jmp    11dc <main+0x8c>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1175 <main+0x25>
jg     1195 <main+0x45>
lea    0xeb9(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x8(%rbx),%rdx
lea    0xe80(%rip),%rdi
lea    0xe7e(%rip),%rsi
xor    %ecx,%ecx
call   1060 <execl@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe6d(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/bin/cat\00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [25 x i8] c"Hello, this is %d's dad\0A\00"
@.str.3 = [14 x i8] c"fork() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
store i8* %10, i8** %6
%11 = call i64 (...) @fork()
store i64 %11, i64* %7
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* null)
br label %27
18: ; preds = %2
%19 = load i64, i64* %7
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i64, i64* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %26
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
br label %27
27: ; preds = %26, %13
%28 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [9 x i8] c"/bin/cat\00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [25 x i8] c"Hello, this is %d's dad\0A\00"
@.str.3 = [14 x i8] c"fork() failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* null)
br label %15
9: ; preds = %2
%10 = icmp sgt i64 %3, 0
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %3)
br label %15
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %11, %13, %5
%16 = tail call i32 @exit(i32 0)
unreachable
}