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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stack_free(void *, int);
int /*<<< orphan*/ stderr;
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void delete_thread(pid_t pid, void *stack) {
  pid_t result;
  fprintf(stderr, "Waiting for child to exit\n");
  result = waitpid(pid, NULL, 0);
  fprintf(stderr, "Child has exited\n");
  if (result == -1 || result != pid) {
  }
  stack_free(stack, (32 * 1024));
}


x86 assembly (clang, -O0):
<delete_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xeb1(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0xffffffff,-0x14(%rbp)
je     1190 <delete_thread+0x60>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     1195 <delete_thread+0x65>
jmp    1195 <delete_thread+0x65>
mov    -0x10(%rbp),%rdi
mov    $0x8000,%esi
call   1030 <stack_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_thread>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ea0(%rip),%r14
mov    (%r14),%edi
lea    0xeb6(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    (%r14),%edi
lea    0xeb7(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x8000,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <stack_free@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Waiting for child to exit\0A\00"
@.str.1 = [18 x i8] c"Child has exited\0A\00"
define void @delete_thread(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = call i32 @waitpid(i32 %8, i32* null, i32 0)
store i32 %9, i32* %5
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14, %2
br label %19
19: ; preds = %18, %14
%20 = load i8*, i8** %4
%21 = call i32 @stack_free(i8* %20, i32 32768)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Waiting for child to exit\0A\00"
@.str.1 = [18 x i8] c"Child has exited\0A\00"
define void @delete_thread(i32 %0, i8* %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @waitpid(i32 %0, i32* null, i32 0)
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @stack_free(i8* %1, i32 32768)
ret void
}