#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*/ assign_thread_id_to_conn_buffer_group(unsigned int,
                                                         int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ pthread_attr_init(int /*<<< orphan*/ *);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), void *);
int /*<<< orphan*/ stderr;
char *strerror(int);
void create_worker(unsigned worker_num, void *(*func)(void *), void *arg) {
  pthread_t thread;
  pthread_attr_t attr;
  int ret;
  pthread_attr_init(&attr);
  if ((ret = pthread_create(&thread, &attr, func, arg)) != 0) {
    fprintf(stderr, "Can't create thread: %s\n", strerror(ret));
    exit(1);
  }
  assign_thread_id_to_conn_buffer_group(worker_num - 1, thread);
}


x86 assembly (clang, -O0):
<create_worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <pthread_attr_init@plt>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <pthread_create@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11cd <create_worker+0x6d>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe42(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x1c(%rbp),%esi
call   1080 <assign_thread_id_to_conn_buffer_group@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_worker>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x4(%rsp),%r12
mov    %r12,%rdi
call   1030 <pthread_attr_init@plt>
mov    %rsp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <pthread_create@plt>
test   %eax,%eax
jne    11ab <create_worker+0x4b>
add    $0xffffffff,%ebx
mov    (%rsp),%esi
mov    %ebx,%edi
call   1080 <assign_thread_id_to_conn_buffer_group@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e2e(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe3e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Can't create thread: %s\0A\00"
define void @create_worker(i32 %0, i8* (i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8* (i8*)*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* (i8*)* %1, i8* (i8*)** %5
store i8* %2, i8** %6
%10 = call i32 @pthread_attr_init(i32* %8)
%11 = load i8* (i8*)*, i8* (i8*)** %5
%12 = load i8*, i8** %6
%13 = call i32 @pthread_create(i32* %7, i32* %8, i8* (i8*)* %11, i8* %12)
store i32 %13, i32* %9
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i32, i32* %9
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = load i32, i32* %4
%23 = sub i32 %22, 1
%24 = load i32, i32* %7
%25 = call i32 @assign_thread_id_to_conn_buffer_group(i32 %23, i32 %24)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Can't create thread: %s\0A\00"
define void @create_worker(i32 %0, i8* (i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = call i32 @pthread_attr_init(i32* %5)
%9 = call i32 @pthread_create(i32* %4, i32* %5, i8* (i8*)* %1, i8* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = call i8* @strerror(i32 %9)
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = add i32 %0, -1
%18 = load i32, i32* %4
%19 = call i32 @assign_thread_id_to_conn_buffer_group(i32 %17, i32 %18)
ret void
}