#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_DETACHED;
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setdetachstate(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), void *const);
int sst_create_thread(void *(*thread_routine)(void *), void *const thread_arg) {
  pthread_t thr;
  pthread_attr_t attr;
  int ret = pthread_attr_init(&attr);
  ret = ret ? ret : pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  ret = ret ? ret : pthread_create(&thr, &attr, thread_routine, thread_arg);
  return ret;
}


x86 assembly (clang, -O0):
<sst_create_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <pthread_attr_init@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1161 <sst_create_thread+0x31>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1176 <sst_create_thread+0x46>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1040 <pthread_attr_setdetachstate@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1191 <sst_create_thread+0x61>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11a9 <sst_create_thread+0x79>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <pthread_create@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sst_create_thread>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1030 <pthread_attr_init@plt>
test   %eax,%eax
jne    116e <sst_create_thread+0x3e>
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1040 <pthread_attr_setdetachstate@plt>
test   %eax,%eax
jne    116e <sst_create_thread+0x3e>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <pthread_create@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PTHREAD_CREATE_DETACHED = global i32 0
define i32 @sst_create_thread(i8* (i8*)* %0, i8* %1) {
%3 = alloca i8* (i8*)*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* (i8*)* %0, i8* (i8*)** %3
store i8* %1, i8** %4
%8 = call i32 @pthread_attr_init(i32* %6)
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %7
br label %16
13: ; preds = %2
%14 = load i32, i32* @PTHREAD_CREATE_DETACHED
%15 = call i32 @pthread_attr_setdetachstate(i32* %6, i32 %14)
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ %12, %11 ], [ %15, %13 ]
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* %7
br label %26
22: ; preds = %16
%23 = load i8* (i8*)*, i8* (i8*)** %3
%24 = load i8*, i8** %4
%25 = call i32 @pthread_create(i32* %5, i32* %6, i8* (i8*)* %23, i8* %24)
br label %26
26: ; preds = %22, %20
%27 = phi i32 [ %21, %20 ], [ %25, %22 ]
store i32 %27, i32* %7
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
@PTHREAD_CREATE_DETACHED = global i32 0
define i32 @sst_create_thread(i8* (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 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @PTHREAD_CREATE_DETACHED
%11 = call i32 @pthread_attr_setdetachstate(i32* %4, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @pthread_create(i32* %3, i32* %4, i8* (i8*)* %0, i8* %1)
br label %15
15: ; preds = %2, %9, %13
%16 = phi i32 [ %14, %13 ], [ %11, %9 ], [ %7, %2 ]
ret i32 %16
}