#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exec(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, char *);
int wait(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buffer[128];
  pid_t pid;
  int retval = 0;
  if (argc != 4) {
    printf("usage: recursor <string> <depth> <waitp>\n");
    exit(1);
  }
  printf("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
  if (atoi(argv[2]) != 0) {
    snprintf(buffer, sizeof buffer, "recursor %s %d %s", argv[1],
             atoi(argv[2]) - 1, argv[3]);
    pid = exec(buffer);
    if (atoi(argv[3]))
      retval = wait(pid);
  }
  printf("%s %s: dying, retval=%d\n", argv[1], argv[2], retval);
  exit(retval);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x98(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11a5 <main+0x45>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r8
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x0,%eax
je     127e <main+0x11e>
lea    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    -0xa8(%rbp),%rdi
mov    -0xa0(%rbp),%rcx
mov    %eax,%r8d
sub    $0x1,%r8d
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r9
mov    $0x80,%esi
lea    0xdfc(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x90(%rbp),%rdi
call   1070 <exec@plt>
mov    %eax,-0x94(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x0,%eax
je     1279 <main+0x119>
mov    -0x94(%rbp),%edi
call   1080 <wait@plt>
mov    %eax,-0x98(%rbp)
jmp    127e <main+0x11e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x98(%rbp),%ecx
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x98(%rbp),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
cmp    $0x4,%edi
jne    1219 <main+0xa9>
mov    %rsi,%rbx
mov    (%rsi),%rsi
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
mov    0x18(%rbx),%r8
lea    0xe63(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
je     11fa <main+0x8a>
add    $0xffffffff,%eax
mov    0x8(%rbx),%rcx
mov    0x18(%rbx),%r9
lea    0xe48(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x80,%esi
mov    %eax,%r8d
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1080 <exec@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
je     11fa <main+0x8a>
mov    %r14d,%edi
call   1090 <wait@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdx
lea    0xe16(%rip),%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <exit@plt>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"usage: recursor <string> <depth> <waitp>\0A\00"
@.str.1 = [13 x i8] c"%s %s %s %s\0A\00"
@.str.2 = [18 x i8] c"recursor %s %d %s\00"
@.str.3 = [25 x i8] c"%s %s: dying, retval=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %20, i8* %23, i8* %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %58
33: ; preds = %14
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = sub nsw i32 %41, 1
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i32 @snprintf(i8* %34, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32 %42, i8* %45)
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%48 = call i32 @exec(i8* %47)
store i32 %48, i32* %7
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %33
%55 = load i32, i32* %7
%56 = call i32 @wait(i32 %55)
store i32 %56, i32* %8
br label %57
57: ; preds = %54, %33
br label %58
58: ; preds = %57, %14
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = load i32, i32* %8
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %61, i8* %64, i32 %65)
%67 = load i32, i32* %8
%68 = call i32 @exit(i32 %67)
unreachable
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"%s %s %s %s\0A\00"
@.str.2 = [18 x i8] c"recursor %s %d %s\00"
@.str.3 = [25 x i8] c"%s %s: dying, retval=%d\0A\00"
@str = [41 x i8] c"usage: recursor <string> <depth> <waitp>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %12, i8* %14, i8* %16)
%18 = load i8*, i8** %13
%19 = tail call i32 @atoi(i8* %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %32, label %21
21: ; preds = %9
%22 = load i8*, i8** %11
%23 = add nsw i32 %19, -1
%24 = load i8*, i8** %15
%25 = call i32 @snprintf(i8* %4, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %22, i32 %23, i8* %24)
%26 = call i32 @exec(i8* %4)
%27 = load i8*, i8** %15
%28 = call i32 @atoi(i8* %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %21
%31 = call i32 @wait(i32 %26)
br label %32
32: ; preds = %21, %30, %9
%33 = phi i32 [ %31, %30 ], [ 0, %21 ], [ 0, %9 ]
%34 = load i8*, i8** %11
%35 = load i8*, i8** %13
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %35, i32 %33)
%37 = call i32 @exit(i32 %33)
unreachable
}