#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 /*<<< orphan*/ wait(int /*<<< orphan*/ *);
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) {
    wait(NULL);
    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   1080 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11bb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5a(%rip),%rdi
lea    0xe58(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <execl@plt>
jmp    11f5 <main+0x95>
cmpq   $0x0,-0x20(%rbp)
jle    11e4 <main+0x84>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    -0x20(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
jmp    11f0 <main+0x90>
lea    0xe37(%rip),%rdi
call   1040 <perror@plt>
jmp    11f5 <main+0x95>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1188 <main+0x28>
jg     11a8 <main+0x48>
lea    0xea6(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x8(%r14),%rdx
lea    0xe6d(%rip),%rdi
lea    0xe6b(%rip),%rsi
xor    %ecx,%ecx
call   1060 <execl@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe50(%rip),%rdi
mov    %rbx,%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 %28
18: ; preds = %2
%19 = load i64, i64* %7
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = call i32 @wait(i32* null)
%23 = load i64, i64* %7
%24 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %23)
br label %27
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
br label %28
28: ; preds = %27, %13
%29 = 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 %16
9: ; preds = %2
%10 = icmp sgt i64 %3, 0
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @wait(i32* null)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %3)
br label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %11, %14, %5
%17 = tail call i32 @exit(i32 0)
unreachable
}