#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*/ abort();
int errno;
int /*<<< orphan*/ printf(char *);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), int /*<<< orphan*/ *);
void create_threads(pthread_t *threads, size_t count, void *(*func)(void *)) {
  for (size_t i = 0; i < count; ++i) {
    int ret = pthread_create(threads + i, NULL, func, NULL);
    if (ret != 0) {
      errno = ret;
      printf("error: pthread_create: %m\n");
      abort();
    }
  }
}


x86 assembly (clang, -O0):
<create_threads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11bb <create_threads+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
call   1050 <pthread_create@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11a5 <create_threads+0x75>
mov    -0x24(%rbp),%ecx
mov    0x2e50(%rip),%rax
mov    %ecx,(%rax)
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11aa <create_threads+0x7a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114c <create_threads+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_threads>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     116d <create_threads+0x3d>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1050 <pthread_create@plt>
test   %eax,%eax
jne    1173 <create_threads+0x43>
add    $0x4,%rbx
add    $0xffffffffffffffff,%r15
jne    1150 <create_threads+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e66(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [27 x i8] c"error: pthread_create: %m\0A\00"
define void @create_threads(i32* %0, i64 %1, i8* (i8*)* %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8* (i8*)*
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
store i8* (i8*)* %2, i8* (i8*)** %6
store i64 0, i64* %7
br label %9
9: ; preds = %26, %3
%10 = load i64, i64* %7
%11 = load i64, i64* %5
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = load i64, i64* %7
%16 = getelementptr inbounds i32, i32* %14, i64 %15
%17 = load i8* (i8*)*, i8* (i8*)** %6
%18 = call i32 @pthread_create(i32* %16, i32* null, i8* (i8*)* %17, i32* null)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i32, i32* %8
store i32 %22, i32* @errno
%23 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %13
br label %26
26: ; preds = %25
%27 = load i64, i64* %7
%28 = add i64 %27, 1
store i64 %28, i64* %7
br label %9
29: ; preds = %9
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [27 x i8] c"error: pthread_create: %m\0A\00"
define void @create_threads(i32* %0, i64 %1, i8* (i8*)* %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %7, label %8
5: ; preds = %8
%6 = icmp eq i64 %13, %1
br i1 %6, label %7, label %8
7: ; preds = %5, %3
ret void
8: ; preds = %3, %5
%9 = phi i64 [ %13, %5 ], [ 0, %3 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = tail call i32 @pthread_create(i32* %10, i32* null, i8* (i8*)* %2, i32* null)
%12 = icmp eq i32 %11, 0
%13 = add nuw i64 %9, 1
br i1 %12, label %5, label %14
14: ; preds = %8
store i32 %11, i32* @errno
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 (...) @abort()
unreachable
}