#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*/ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  void *(*)(void *), void *);
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, int /*<<< orphan*/ *);
void spawn_threads(void *(*thread_ptr)(void *), void *ptr) {
  size_t i;
  pthread_t threads[16];
  for (i = 0; i < 16; ++i)
    pthread_create(&threads[i], NULL, thread_ptr, ptr);
  for (i = 0; i < 16; ++i)
    pthread_join(threads[i], NULL);
}


x86 assembly (clang, -O0):
<spawn_threads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x10,-0x18(%rbp)
jae    1174 <spawn_threads+0x54>
mov    -0x18(%rbp),%rax
lea    -0x60(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <pthread_create@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <spawn_threads+0x18>
movq   $0x0,-0x18(%rbp)
cmpq   $0x10,-0x18(%rbp)
jae    11a9 <spawn_threads+0x89>
mov    -0x18(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_join@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117c <spawn_threads+0x5c>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawn_threads>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x4(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x14(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x1c(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x24(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x28(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x2c(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x34(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x38(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
lea    0x3c(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <pthread_create@plt>
mov    (%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x4(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x10(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x14(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x18(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x1c(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x20(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x24(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x28(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x2c(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x30(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x34(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x38(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0x3c(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @spawn_threads(i8* (i8*)* %0, i8* %1) {
%3 = alloca [16 x i32]
%4 = bitcast [16 x i32]* %3 to i8*
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%6 = call i32 @pthread_create(i32* %5, i32* null, i8* (i8*)* %0, i8* %1)
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 1
%8 = call i32 @pthread_create(i32* %7, i32* null, i8* (i8*)* %0, i8* %1)
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 2
%10 = call i32 @pthread_create(i32* %9, i32* null, i8* (i8*)* %0, i8* %1)
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 3
%12 = call i32 @pthread_create(i32* %11, i32* null, i8* (i8*)* %0, i8* %1)
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 4
%14 = call i32 @pthread_create(i32* %13, i32* null, i8* (i8*)* %0, i8* %1)
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 5
%16 = call i32 @pthread_create(i32* %15, i32* null, i8* (i8*)* %0, i8* %1)
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 6
%18 = call i32 @pthread_create(i32* %17, i32* null, i8* (i8*)* %0, i8* %1)
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 7
%20 = call i32 @pthread_create(i32* %19, i32* null, i8* (i8*)* %0, i8* %1)
%21 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 8
%22 = call i32 @pthread_create(i32* %21, i32* null, i8* (i8*)* %0, i8* %1)
%23 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 9
%24 = call i32 @pthread_create(i32* %23, i32* null, i8* (i8*)* %0, i8* %1)
%25 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 10
%26 = call i32 @pthread_create(i32* %25, i32* null, i8* (i8*)* %0, i8* %1)
%27 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 11
%28 = call i32 @pthread_create(i32* %27, i32* null, i8* (i8*)* %0, i8* %1)
%29 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 12
%30 = call i32 @pthread_create(i32* %29, i32* null, i8* (i8*)* %0, i8* %1)
%31 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 13
%32 = call i32 @pthread_create(i32* %31, i32* null, i8* (i8*)* %0, i8* %1)
%33 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 14
%34 = call i32 @pthread_create(i32* %33, i32* null, i8* (i8*)* %0, i8* %1)
%35 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 15
%36 = call i32 @pthread_create(i32* %35, i32* null, i8* (i8*)* %0, i8* %1)
%37 = load i32, i32* %5
%38 = call i32 @pthread_join(i32 %37, i32* null)
%39 = load i32, i32* %7
%40 = call i32 @pthread_join(i32 %39, i32* null)
%41 = load i32, i32* %9
%42 = call i32 @pthread_join(i32 %41, i32* null)
%43 = load i32, i32* %11
%44 = call i32 @pthread_join(i32 %43, i32* null)
%45 = load i32, i32* %13
%46 = call i32 @pthread_join(i32 %45, i32* null)
%47 = load i32, i32* %15
%48 = call i32 @pthread_join(i32 %47, i32* null)
%49 = load i32, i32* %17
%50 = call i32 @pthread_join(i32 %49, i32* null)
%51 = load i32, i32* %19
%52 = call i32 @pthread_join(i32 %51, i32* null)
%53 = load i32, i32* %21
%54 = call i32 @pthread_join(i32 %53, i32* null)
%55 = load i32, i32* %23
%56 = call i32 @pthread_join(i32 %55, i32* null)
%57 = load i32, i32* %25
%58 = call i32 @pthread_join(i32 %57, i32* null)
%59 = load i32, i32* %27
%60 = call i32 @pthread_join(i32 %59, i32* null)
%61 = load i32, i32* %29
%62 = call i32 @pthread_join(i32 %61, i32* null)
%63 = load i32, i32* %31
%64 = call i32 @pthread_join(i32 %63, i32* null)
%65 = load i32, i32* %33
%66 = call i32 @pthread_join(i32 %65, i32* null)
%67 = load i32, i32* %35
%68 = call i32 @pthread_join(i32 %67, i32* null)
ret void
}