#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 /*<<< orphan*/ pthread_t;

/* Variables and functions */
int getpid();
int /*<<< orphan*/ printf(char *, int, void *, ...);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ sleep(int);
void *pth_rtn(void *p) {
  int c = 0;
  pthread_t pt = pthread_self();
  while (c < 11) {
    printf("%d: pthread_self = %p\n", getpid(), (void *)&pt);
    sleep(1);
    c++;
  }
  printf("%d: pthread_self[exit](%p) = %p\n", getpid(), p, (void *)&pt);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<pth_rtn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xb,-0x14(%rbp)
jge    11aa <pth_rtn+0x5a>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <pth_rtn+0x1d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pth_rtn>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe8b(%rip),%rbx
lea    0xc(%rsp),%r15
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd36(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <pthread_exit@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"%d: pthread_self = %p\0A\00"
@.str.1 = [33 x i8] c"%d: pthread_self[exit](%p) = %p\0A\00"
define i8* @pth_rtn(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = call i32 (...) @pthread_self()
store i32 %6, i32* %5
br label %7
7: ; preds = %10, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 11
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = call i32 (...) @getpid()
%12 = bitcast i32* %5 to i8*
%13 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %12)
%14 = call i32 @sleep(i32 1)
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %7
17: ; preds = %7
%18 = call i32 (...) @getpid()
%19 = load i8*, i8** %3
%20 = bitcast i32* %5 to i8*
%21 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %19, i8* %20)
%22 = call i32 @pthread_exit(i32* null)
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [23 x i8] c"%d: pthread_self = %p\0A\00"
@.str.1 = [33 x i8] c"%d: pthread_self[exit](%p) = %p\0A\00"
define noalias i8* @pth_rtn(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @pthread_self()
store i32 %4, i32* %2
%5 = call i32 (...) @getpid()
%6 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %3)
%7 = call i32 @sleep(i32 1)
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %3)
%10 = call i32 @sleep(i32 1)
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %3)
%13 = call i32 @sleep(i32 1)
%14 = call i32 (...) @getpid()
%15 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %3)
%16 = call i32 @sleep(i32 1)
%17 = call i32 (...) @getpid()
%18 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %3)
%19 = call i32 @sleep(i32 1)
%20 = call i32 (...) @getpid()
%21 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %3)
%22 = call i32 @sleep(i32 1)
%23 = call i32 (...) @getpid()
%24 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %23, i8* %3)
%25 = call i32 @sleep(i32 1)
%26 = call i32 (...) @getpid()
%27 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %26, i8* %3)
%28 = call i32 @sleep(i32 1)
%29 = call i32 (...) @getpid()
%30 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %29, i8* %3)
%31 = call i32 @sleep(i32 1)
%32 = call i32 (...) @getpid()
%33 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %32, i8* %3)
%34 = call i32 @sleep(i32 1)
%35 = call i32 (...) @getpid()
%36 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %35, i8* %3)
%37 = call i32 @sleep(i32 1)
%38 = call i32 (...) @getpid()
%39 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %0, i32* %2)
%40 = call i32 @pthread_exit(i32* null)
ret i8* undef
}