#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 pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), void *);
int /*<<< orphan*/ pthread_detach(int /*<<< orphan*/);
int Task_Start(pthread_t *thrid, void *(*start_routine)(void *), void *arg) {
  pthread_t slave_tid;
  int ret =
      pthread_create(thrid ? thrid : &slave_tid, NULL, start_routine, arg);
  if (ret == 0 && !thrid)
    pthread_detach(slave_tid);
  return ret == 0 ? 0 : -1;
}


x86 assembly (clang, -O0):
<Task_Start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114c <Task_Start+0x2c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1159 <Task_Start+0x39>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1159 <Task_Start+0x39>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_create@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    118e <Task_Start+0x6e>
cmpq   $0x0,-0x8(%rbp)
jne    118e <Task_Start+0x6e>
mov    -0x1c(%rbp),%edi
call   1030 <pthread_detach@plt>
mov    -0x20(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Task_Start>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0x4(%rsp),%rdi
cmovne %rbx,%rdi
xor    %esi,%esi
call   1040 <pthread_create@plt>
mov    %eax,%ebp
test   %rbx,%rbx
jne    1153 <Task_Start+0x33>
test   %ebp,%ebp
jne    1153 <Task_Start+0x33>
mov    0x4(%rsp),%edi
call   1030 <pthread_detach@plt>
neg    %ebp
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Task_Start(i32* %0, i8* (i8*)* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8* (i8*)*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* (i8*)* %1, i8* (i8*)** %5
store i8* %2, i8** %6
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i32*, i32** %4
br label %14
13: ; preds = %3
br label %14
14: ; preds = %13, %11
%15 = phi i32* [ %12, %11 ], [ %7, %13 ]
%16 = load i8* (i8*)*, i8* (i8*)** %5
%17 = load i8*, i8** %6
%18 = call i32 @pthread_create(i32* %15, i32* null, i8* (i8*)* %16, i8* %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i32*, i32** %4
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %7
%26 = call i32 @pthread_detach(i32 %25)
br label %27
27: ; preds = %24, %21, %14
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 0, i32 -1
ret i32 %31
}

LLVM IR (-O2):
define i32 @Task_Start(i32* %0, i8* (i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp ne i32* %0, null
%7 = select i1 %6, i32* %0, i32* %4
%8 = call i32 @pthread_create(i32* %7, i32* null, i8* (i8*)* %1, i8* %2)
%9 = icmp ne i32 %8, 0
%10 = or i1 %6, %9
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %4
%13 = call i32 @pthread_detach(i32 %12)
br label %14
14: ; preds = %11, %3
%15 = sext i1 %9 to i32
ret i32 %15
}