#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 */
struct WaitGroup {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ Done(struct WaitGroup *);
int /*<<< orphan*/ printf(char *, ...);
int pthread_self();
int /*<<< orphan*/ show_time();
int /*<<< orphan*/ sleep(int);
void *start_thread(void *arg) {
  if (NULL == arg) {
    do {
      show_time();
      printf(" -- [%lu]", (unsigned long int)pthread_self());
      printf("arg is NULL");
      printf("\n");
    } while (0);
    return NULL;
  }
  do {
    show_time();
    printf(" -- [%lu]", (unsigned long int)pthread_self());
    printf("aha~");
    printf("\n");
  } while (0);
  struct WaitGroup *wp = (struct WaitGroup *)arg;
  sleep(pthread_self() % 3);
  do {
    show_time();
    printf(" -- [%lu]", (unsigned long int)pthread_self());
    printf("aha done ~");
    printf("\n");
  } while (0);
  Done(wp);
  return NULL;
}


x86 assembly (clang, -O0):
<start_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11b5 <start_thread+0x65>
jmp    116d <start_thread+0x1d>
mov    $0x0,%al
call   1050 <show_time@plt>
mov    $0x0,%al
call   1060 <pthread_self@plt>
movslq %eax,%rsi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    125f <start_thread+0x10f>
jmp    11ba <start_thread+0x6a>
mov    $0x0,%al
call   1050 <show_time@plt>
mov    $0x0,%al
call   1060 <pthread_self@plt>
movslq %eax,%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1050 <show_time@plt>
mov    $0x0,%al
call   1060 <pthread_self@plt>
movslq %eax,%rsi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <Done@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_thread>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <show_time@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
movslq %eax,%rsi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbx,%rbx
je     120d <start_thread+0xad>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
movslq %eax,%rdi
imul   $0x55555556,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
call   1060 <show_time@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
movslq %eax,%rsi
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <Done@plt>
jmp    1225 <start_thread+0xc5>
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.WaitGroup = type { i32 }
@.str = [10 x i8] c" -- [%lu]\00"
@.str.1 = [12 x i8] c"arg is NULL\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [5 x i8] c"aha~\00"
@.str.4 = [11 x i8] c"aha done ~\00"
define i8* @start_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.WaitGroup*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* null, %5
br i1 %6, label %7, label %16
7: ; preds = %1
br label %8
8: ; preds = %7
%9 = call i32 (...) @show_time()
%10 = call i32 (...) @pthread_self()
%11 = sext i32 %10 to i64
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %8
store i8* null, i8** %2
br label %40
16: ; preds = %1
br label %17
17: ; preds = %16
%18 = call i32 (...) @show_time()
%19 = call i32 (...) @pthread_self()
%20 = sext i32 %19 to i64
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = bitcast i8* %25 to %struct.WaitGroup*
store %struct.WaitGroup* %26, %struct.WaitGroup** %4
%27 = call i32 (...) @pthread_self()
%28 = srem i32 %27, 3
%29 = call i32 @sleep(i32 %28)
br label %30
30: ; preds = %24
%31 = call i32 (...) @show_time()
%32 = call i32 (...) @pthread_self()
%33 = sext i32 %32 to i64
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %30
%38 = load %struct.WaitGroup*, %struct.WaitGroup** %4
%39 = call i32 @Done(%struct.WaitGroup* %38)
store i8* null, i8** %2
br label %40
40: ; preds = %37, %15
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
%struct.WaitGroup = type { i32 }
@.str = [10 x i8] c" -- [%lu]\00"
@.str.1 = [12 x i8] c"arg is NULL\00"
@.str.3 = [5 x i8] c"aha~\00"
@.str.4 = [11 x i8] c"aha done ~\00"
define noalias i8* @start_thread(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = tail call i32 (...) @show_time()
%4 = tail call i32 (...) @pthread_self()
%5 = sext i32 %4 to i64
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %5)
br i1 %2, label %7, label %10
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @putchar(i32 10)
br label %24
10: ; preds = %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @putchar(i32 10)
%13 = bitcast i8* %0 to %struct.WaitGroup*
%14 = tail call i32 (...) @pthread_self()
%15 = srem i32 %14, 3
%16 = tail call i32 @sleep(i32 %15)
%17 = tail call i32 (...) @show_time()
%18 = tail call i32 (...) @pthread_self()
%19 = sext i32 %18 to i64
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32 @putchar(i32 10)
%23 = tail call i32 @Done(%struct.WaitGroup* %13)
br label %24
24: ; preds = %10, %7
ret i8* null
}