#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 DivideWork(void **job_inputs, void *(*start_routine)(void *), int jobs) {
  pthread_t workthreads[jobs];
  for (int i = 0; i < jobs; i++) {
    pthread_create(workthreads + i, NULL, start_routine, job_inputs[i]);
  }
  for (int i = 0; i < jobs; i++) {
    pthread_join(workthreads[i], NULL);
  }
}


x86 assembly (clang, -O0):
<DivideWork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <DivideWork+0x83>
mov    -0x38(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <pthread_create@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1161 <DivideWork+0x41>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d8 <DivideWork+0xb8>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_join@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11aa <DivideWork+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DivideWork>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ecx
mov    %rsp,%r15
lea    0xf(,%rcx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %edx,%edx
jle    11b4 <DivideWork+0x94>
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %edx,-0x2c(%rbp)
mov    %rcx,-0x38(%rbp)
lea    0x0(,%rcx,4),%r14
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%r12,1),%rdi
mov    0x0(%r13,%r12,2),%rcx
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <pthread_create@plt>
add    $0x4,%r12
cmp    %r12,%r14
jne    1170 <DivideWork+0x50>
cmpl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%r14
jle    11b4 <DivideWork+0x94>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11a0 <DivideWork+0x80>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @DivideWork(i8** %0, i8* (i8*)* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8* (i8*)*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %4
store i8* (i8*)* %1, i8* (i8*)** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i32, i64 %12
store i64 %12, i64* %8
store i32 0, i32* %9
br label %15
15: ; preds = %30, %3
%16 = load i32, i32* %9
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %14, i64 %21
%23 = load i8* (i8*)*, i8* (i8*)** %5
%24 = load i8**, i8*** %4
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @pthread_create(i32* %22, i32* null, i8* (i8*)* %23, i8* %28)
br label %30
30: ; preds = %19
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %15
33: ; preds = %15
store i32 0, i32* %10
br label %34
34: ; preds = %44, %33
%35 = load i32, i32* %10
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %14, i64 %40
%42 = load i32, i32* %41
%43 = call i32 @pthread_join(i32 %42, i32* null)
br label %44
44: ; preds = %38
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %34
47: ; preds = %34
%48 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
define void @DivideWork(i8** nocapture %0, i8* (i8*)* %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca i32, i64 %4
%6 = icmp sgt i32 %2, 0
br i1 %6, label %8, label %16
7: ; preds = %8
br i1 %6, label %17, label %16
8: ; preds = %3, %8
%9 = phi i64 [ %14, %8 ], [ 0, %3 ]
%10 = getelementptr inbounds i32, i32* %5, i64 %9
%11 = getelementptr inbounds i8*, i8** %0, i64 %9
%12 = load i8*, i8** %11
%13 = call i32 @pthread_create(i32* %10, i32* null, i8* (i8*)* %1, i8* %12)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %4
br i1 %15, label %7, label %8
16: ; preds = %17, %3, %7
ret void
17: ; preds = %7, %17
%18 = phi i64 [ %22, %17 ], [ 0, %7 ]
%19 = getelementptr inbounds i32, i32* %5, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @pthread_join(i32 %20, i32* null)
%22 = add nuw nsw i64 %18, 1
%23 = icmp eq i64 %22, %4
br i1 %23, label %16, label %17
}