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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          void *(*)(void *), void *);
int /*<<< orphan*/ sleep(int);
void *doit(void *arg) {
  unsigned long depth = (unsigned long)arg;
  depth--;
  if (depth == 0) {
    while (1)
      ;
  } else {
    pthread_t tid;
    if (pthread_create(&tid, NULL, doit, (void *)depth)) {
      perror("pthread_create");
      exit(1);
    }
    sleep(60);
  }
}


x86 assembly (clang, -O0):
<doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1175 <doit+0x35>
jmp    1170 <doit+0x30>
jmp    1170 <doit+0x30>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    0x2e60(%rip),%rdx
call   1030 <pthread_create@plt>
cmp    $0x0,%rax
je     11ad <doit+0x6d>
lea    0xe62(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    $0x3c,%edi
call   1060 <sleep@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doit>:
push   %rax
mov    %rdi,%rcx
add    $0xffffffffffffffff,%rcx
je     1170 <doit+0x30>
mov    0x2e97(%rip),%rdx
lea    0x4(%rsp),%rdi
xor    %esi,%esi
call   1030 <pthread_create@plt>
test   %rax,%rax
jne    1172 <doit+0x32>
mov    $0x3c,%edi
call   1060 <sleep@plt>
pop    %rcx
ret
xchg   %ax,%ax
jmp    1170 <doit+0x30>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"pthread_create\00"
define i8* @doit(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = ptrtoint i8* %6 to i64
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = add i64 %8, -1
store i64 %9, i64* %4
%10 = load i64, i64* %4
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
br label %13
13: ; preds = %12, %13
br label %13
14: ; preds = %1
%15 = load i64, i64* %4
%16 = inttoptr i64 %15 to i8*
%17 = call i64 @pthread_create(i32* %5, i32* null, i8* (i8*)* @doit, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = call i32 @sleep(i32 60)
br label %24
24: ; preds = %22
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [15 x i8] c"pthread_create\00"
define noalias i8* @doit(i8* %0) {
%2 = alloca i32
%3 = ptrtoint i8* %0 to i64
%4 = add i64 %3, -1
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1, %6
br label %6
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = inttoptr i64 %4 to i8*
%10 = call i64 @pthread_create(i32* %2, i32* null, i8* (i8*)* @doit, i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = call i32 @sleep(i32 60)
ret i8* undef
}