#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 EXIT_FAILURE;
int /*<<< orphan*/ do_child(char const *, char **);
int do_parent(char const *, char *, scalar_t__);
int /*<<< orphan*/ errno;
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int debug(char const *program_name, char **argv) {
  pid_t pid = fork();
  if (pid < 0) {
    fprintf(stderr, "%s: could not fork due to %s\n", program_name,
            strerror(errno));
    return EXIT_FAILURE;
  } else if (pid == 0) {
    do_child(program_name, argv);
    return EXIT_FAILURE;
  } else {
    return do_parent(program_name, argv[0], pid);
  }
}


x86 assembly (clang, -O0):
<debug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11bf <debug+0x6f>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <debug+0xaf>
cmpq   $0x0,-0x20(%rbp)
jne    11e8 <debug+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <do_child@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <debug+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <do_parent@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     117d <debug+0x2d>
je     11aa <debug+0x5a>
mov    (%rbx),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <do_parent@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe65(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
jmp    11b5 <debug+0x65>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <do_child@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"%s: could not fork due to %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @debug(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %4
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %32
17: ; preds = %2
%18 = load i64, i64* %6
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = load i8**, i8*** %5
%23 = call i32 @do_child(i8* %21, i8** %22)
%24 = load i32, i32* @EXIT_FAILURE
store i32 %24, i32* %3
br label %32
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i64, i64* %6
%31 = call i32 @do_parent(i8* %26, i8* %29, i64 %30)
store i32 %31, i32* %3
br label %32
32: ; preds = %25, %20, %10
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"%s: could not fork due to %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @debug(i8* %0, i8** %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
br label %19
11: ; preds = %2
%12 = icmp eq i64 %3, 0
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = tail call i32 @do_child(i8* %0, i8** %1)
%15 = load i32, i32* @EXIT_FAILURE
br label %19
16: ; preds = %11
%17 = load i8*, i8** %1
%18 = tail call i32 @do_parent(i8* %0, i8* %17, i64 %3)
br label %19
19: ; preds = %16, %13, %5
%20 = phi i32 [ %10, %5 ], [ %15, %13 ], [ %18, %16 ]
ret i32 %20
}