#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 /*<<< orphan*/ assert(int);
scalar_t__ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *, void *,
                          char *);
scalar_t__ pthread_join(int /*<<< orphan*/, void **);
int work_with_thread(void *data) {
  void *status = NULL;
  pthread_t thread;
  assert(0 == pthread_create(&thread, NULL, data, "work in thread"));
  assert(0 == pthread_join(thread, &status));
  return (int)status;
}


x86 assembly (clang, -O0):
<work_with_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x14(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    0xea9(%rip),%rcx
call   1040 <pthread_create@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <pthread_join@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work_with_thread>:
sub    $0x18,%rsp
mov    %rdi,%rdx
movq   $0x0,0x10(%rsp)
lea    0xeb9(%rip),%rcx
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1040 <pthread_create@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
call   1050 <pthread_join@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
mov    0x10(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"work in thread\00"
define i32 @work_with_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = call i64 @pthread_create(i32* %4, i32* null, i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 0, %6
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %4
%11 = call i64 @pthread_join(i32 %10, i8** %3)
%12 = icmp eq i64 0, %11
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %3
%16 = ptrtoint i8* %15 to i32
ret i32 %16
}

LLVM IR (-O2):
@.str = [15 x i8] c"work in thread\00"
define i32 @work_with_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i32* %3 to i8*
%6 = call i64 @pthread_create(i32* %3, i32* null, i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %3
%11 = call i64 @pthread_join(i32 %10, i8** %2)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %2
%16 = ptrtoint i8* %15 to i64
%17 = trunc i64 %16 to i32
ret i32 %17
}