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

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_exit(void *);
int /*<<< orphan*/ sleep(int);
void *handler1(void *arg) {
  int *num = (int *)arg;
  printf("handler1 arg = %p\n", arg);
  while (1) {
    if (*num >= 10) {
      break;
    }
    (*num)++;
    printf("hangdler1 num = %d\n", *num);
    sleep(1);
  }
  int *date = (int *)malloc(sizeof(int));
  *date = 666;
  pthread_exit((void *)date);
  return NULL;
}


x86 assembly (clang, -O0):
<handler1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0xa,(%rax)
jl     1178 <handler1+0x38>
jmp    11a4 <handler1+0x64>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1166 <handler1+0x26>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x29a,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <pthread_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler1>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    (%rbx),%esi
cmp    $0x9,%esi
jg     118e <handler1+0x4e>
lea    0xeb0(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%esi
mov    %esi,(%rbx)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%esi
cmp    $0xa,%esi
jl     1170 <handler1+0x30>
mov    $0x4,%edi
call   1050 <malloc@plt>
movl   $0x29a,(%rax)
mov    %rax,%rdi
call   1040 <pthread_exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"handler1 arg = %p\0A\00"
@.str.1 = [20 x i8] c"hangdler1 num = %d\0A\00"
define i8* @handler1(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %3
%7 = load i8*, i8** %2
%8 = ptrtoint i8* %7 to i32
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %1, %15
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = icmp sge i32 %12, 10
br i1 %13, label %14, label %15
14: ; preds = %10
br label %23
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1
store i32 %18, i32* %16
%19 = load i32*, i32** %3
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @sleep(i32 1)
br label %10
23: ; preds = %14
%24 = call i64 @malloc(i32 4)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %4
%26 = load i32*, i32** %4
store i32 666, i32* %26
%27 = load i32*, i32** %4
%28 = bitcast i32* %27 to i8*
%29 = call i32 @pthread_exit(i8* %28)
ret i8* null
}

LLVM IR (-O2):
@.str = [19 x i8] c"handler1 arg = %p\0A\00"
@.str.1 = [20 x i8] c"hangdler1 num = %d\0A\00"
define noalias i8* @handler1(i8* %0) {
%2 = bitcast i8* %0 to i32*
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 9
br i1 %7, label %15, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %13, %8 ], [ %6, %1 ]
%10 = add nsw i32 %9, 1
store i32 %10, i32* %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 @sleep(i32 1)
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 9
br i1 %14, label %15, label %8
15: ; preds = %8, %1
%16 = tail call i64 @malloc(i32 4)
%17 = inttoptr i64 %16 to i32*
store i32 666, i32* %17
%18 = inttoptr i64 %16 to i8*
%19 = tail call i32 @pthread_exit(i8* %18)
ret i8* null
}