#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 */
int getpid();
int /*<<< orphan*/ printf(char *, int, unsigned long);
scalar_t__ pthread_self();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sleep(int);
void *thread_handler(void *arg) {
  int s = *((int *)arg);
  static int excode;
  printf("process id: %d\tthread id: %lu\n", getpid(),
         (unsigned long)pthread_self());
  sleep(s);
  scanf("%d", &excode);
  return (void *)(&excode);
}


x86 assembly (clang, -O0):
<thread_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rdx
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <sleep@plt>
lea    0xe88(%rip),%rdi
lea    0x2eae(%rip),%rsi
call   1050 <scanf@plt>
lea    0x2ea2(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_handler>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <pthread_self@plt>
lea    0xe94(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %ebx,%edi
call   1070 <sleep@plt>
lea    0xe9b(%rip),%rdi
lea    0x2ec1(%rip),%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@thread_handler.excode = internal global i32 0
@.str = [31 x i8] c"process id: %d\09thread id: %lu\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @thread_handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = bitcast i8* %4 to i32*
%6 = load i32, i32* %5
store i32 %6, i32* %3
%7 = call i32 (...) @getpid()
%8 = call i64 (...) @pthread_self()
%9 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %7, i64 %8)
%10 = load i32, i32* %3
%11 = call i32 @sleep(i32 %10)
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* @thread_handler.excode)
ret i8* bitcast (i32* @thread_handler.excode to i8*)
}

LLVM IR (-O2):
@thread_handler.excode = internal global i32 0
@.str = [31 x i8] c"process id: %d\09thread id: %lu\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @thread_handler(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 (...) @getpid()
%5 = tail call i64 (...) @pthread_self()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %4, i64 %5)
%7 = tail call i32 @sleep(i32 %3)
%8 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* @thread_handler.excode)
ret i8* bitcast (i32* @thread_handler.excode to i8*)
}