#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 /*<<< orphan*/ SYS_gettid;
int /*<<< orphan*/ getchar();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int syscall(int /*<<< orphan*/);
void *thread_function(void *p) {
  printf("I am in thread function\n");
  printf("TGID --> %d\n", getpid());
  printf("PID --> %ld\n", syscall(SYS_gettid));
  getchar();
  return NULL;
}


x86 assembly (clang, -O0):
<thread_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1060 <syscall@plt>
mov    %eax,%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_function>:
push   %rax
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe95(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1070 <syscall@plt>
lea    0xe84(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"I am in thread function\0A\00"
@.str.1 = [13 x i8] c"TGID --> %d\0A\00"
@.str.2 = [13 x i8] c"PID --> %ld\0A\00"
@SYS_gettid = global i32 0
define i8* @thread_function(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (...) @getpid()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @SYS_gettid
%7 = call i32 @syscall(i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @getchar()
ret i8* null
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"TGID --> %d\0A\00"
@.str.2 = [13 x i8] c"PID --> %ld\0A\00"
@SYS_gettid = global i32 0
@str = [24 x i8] c"I am in thread function\00"
define noalias i8* @thread_function(i8* nocapture readnone %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @SYS_gettid
%6 = tail call i32 @syscall(i32 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = tail call i32 (...) @getchar()
ret i8* null
}