#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;
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_CREATE_JOINABLE;
int /*<<< orphan*/ pthread_attr_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_attr_setdetachstate(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  void *(*)(void *), void *);
pthread_t CreateThread(int (*ThreadFn)(void *args), void *args) {
  pthread_t thread;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  pthread_create(&thread, &attr, (void *(*)(void *))ThreadFn, args);
  pthread_attr_destroy(&attr);
  return thread;
}


x86 assembly (clang, -O0):
<CreateThread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <pthread_attr_init@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1040 <pthread_attr_setdetachstate@plt>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <pthread_create@plt>
lea    -0x18(%rbp),%rdi
call   1060 <pthread_attr_destroy@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateThread>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <pthread_attr_init@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <pthread_attr_setdetachstate@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <pthread_create@plt>
mov    %rbx,%rdi
call   1060 <pthread_attr_destroy@plt>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PTHREAD_CREATE_JOINABLE = global i32 0
define i32 @CreateThread(i32 (i8*)* %0, i8* %1) {
%3 = alloca i32 (i8*)*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 (i8*)* %0, i32 (i8*)** %3
store i8* %1, i8** %4
%7 = call i32 @pthread_attr_init(i32* %6)
%8 = load i32, i32* @PTHREAD_CREATE_JOINABLE
%9 = call i32 @pthread_attr_setdetachstate(i32* %6, i32 %8)
%10 = load i32 (i8*)*, i32 (i8*)** %3
%11 = bitcast i32 (i8*)* %10 to i8* (i8*)*
%12 = load i8*, i8** %4
%13 = call i32 @pthread_create(i32* %5, i32* %6, i8* (i8*)* %11, i8* %12)
%14 = call i32 @pthread_attr_destroy(i32* %6)
%15 = load i32, i32* %5
ret i32 %15
}

LLVM IR (-O2):
@PTHREAD_CREATE_JOINABLE = global i32 0
define i32 @CreateThread(i32 (i8*)* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @pthread_attr_init(i32* %4)
%8 = load i32, i32* @PTHREAD_CREATE_JOINABLE
%9 = call i32 @pthread_attr_setdetachstate(i32* %4, i32 %8)
%10 = bitcast i32 (i8*)* %0 to i8* (i8*)*
%11 = call i32 @pthread_create(i32* %3, i32* %4, i8* (i8*)* %10, i8* %1)
%12 = call i32 @pthread_attr_destroy(i32* %4)
%13 = load i32, i32* %3
ret i32 %13
}