#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 /*<<< orphan*/ PTHREAD_SCOPE_SYSTEM;
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_attr_setdetachstate(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ pthread_attr_setscope(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/);
scalar_t__ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *, void *,
                          void *);
int new_thread_p(void *func, void *i) {
  pthread_t thread;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  if (pthread_create(&thread, &attr, func, i)) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<new_thread_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <pthread_attr_init@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1040 <pthread_attr_setscope@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1050 <pthread_attr_setdetachstate@plt>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <pthread_create@plt>
cmp    $0x0,%rax
je     11a8 <new_thread_p+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11af <new_thread_p+0x6f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_thread_p>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%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_setscope@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <pthread_attr_setdetachstate@plt>
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <pthread_create@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PTHREAD_SCOPE_SYSTEM = global i32 0
@PTHREAD_CREATE_DETACHED = global i32 0
define i32 @new_thread_p(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call i32 @pthread_attr_init(i32* %7)
%9 = load i32, i32* @PTHREAD_SCOPE_SYSTEM
%10 = call i32 @pthread_attr_setscope(i32* %7, i32 %9)
%11 = load i32, i32* @PTHREAD_CREATE_DETACHED
%12 = call i32 @pthread_attr_setdetachstate(i32* %7, i32 %11)
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = call i64 @pthread_create(i32* %6, i32* %7, i8* %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
br label %19
18: ; preds = %2
store i32 1, i32* %3
br label %19
19: ; preds = %18, %17
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@PTHREAD_SCOPE_SYSTEM = global i32 0
@PTHREAD_CREATE_DETACHED = global i32 0
define i32 @new_thread_p(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_SCOPE_SYSTEM
%9 = call i32 @pthread_attr_setscope(i32* %4, i32 %8)
%10 = load i32, i32* @PTHREAD_CREATE_DETACHED
%11 = call i32 @pthread_attr_setdetachstate(i32* %4, i32 %10)
%12 = call i64 @pthread_create(i32* %3, i32* %4, i8* %0, i8* %1)
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
ret i32 %14
}