#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 /*<<< orphan*/ exit(int);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), int /*<<< orphan*/ *);
void create_threads(int number, pthread_t thread[], void *(*start)(void *)) {
  int i, status;
  for (i = 0; i < number; ++i) {
    status = pthread_create(&(thread[i]), NULL, start, NULL);
    if (status != 0)
      exit(status);
  }
}


x86 assembly (clang, -O0):
<create_threads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118d <create_threads+0x6d>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
call   1030 <pthread_create@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     117a <create_threads+0x5a>
mov    -0x20(%rbp),%edi
call   1040 <exit@plt>
jmp    117f <create_threads+0x5f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <create_threads+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_threads>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
jle    115d <create_threads+0x3d>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1030 <pthread_create@plt>
test   %eax,%eax
jne    1163 <create_threads+0x43>
add    $0x4,%rbx
add    $0xffffffffffffffff,%r15
jne    1140 <create_threads+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %eax,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
define void @create_threads(i32 %0, i32* %1, i8* (i8*)* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8* (i8*)*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* (i8*)* %2, i8* (i8*)** %6
store i32 0, i32* %7
br label %9
9: ; preds = %26, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load i32*, i32** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i8* (i8*)*, i8* (i8*)** %6
%19 = call i32 @pthread_create(i32* %17, i32* null, i8* (i8*)* %18, i32* null)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* %8
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %13
br label %26
26: ; preds = %25
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %9
29: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @create_threads(i32 %0, i32* %1, i8* (i8*)* %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %9
7: ; preds = %9
%8 = icmp eq i64 %14, %6
br i1 %8, label %17, label %9
9: ; preds = %5, %7
%10 = phi i64 [ 0, %5 ], [ %14, %7 ]
%11 = getelementptr inbounds i32, i32* %1, i64 %10
%12 = tail call i32 @pthread_create(i32* %11, i32* null, i8* (i8*)* %2, i32* null)
%13 = icmp eq i32 %12, 0
%14 = add nuw nsw i64 %10, 1
br i1 %13, label %7, label %15
15: ; preds = %9
%16 = tail call i32 @exit(i32 %12)
unreachable
17: ; preds = %7, %3
ret void
}