#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*/ *);
int threaded_test(void *(*func)(void *args)) {
  pthread_t thread[50];
  for (int i = 0; i < 50; i++) {
    pthread_create(&thread[i], NULL, func, (void *)NULL);
  }
  for (int i = 0; i < 50; i++) {
    pthread_join(thread[i], NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<threaded_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xd4(%rbp)
cmpl   $0x32,-0xd4(%rbp)
jge    117f <threaded_test+0x5f>
movslq -0xd4(%rbp),%rax
lea    -0xd0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
call   1030 <pthread_create@plt>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1139 <threaded_test+0x19>
movl   $0x0,-0xd8(%rbp)
cmpl   $0x32,-0xd8(%rbp)
jge    11c1 <threaded_test+0xa1>
movslq -0xd8(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_join@plt>
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    1189 <threaded_test+0x69>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threaded_test>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
nop
lea    (%rsp,%rbx,1),%rdi
xor    %esi,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1030 <pthread_create@plt>
add    $0x4,%rbx
cmp    $0xc8,%rbx
jne    1130 <threaded_test+0x10>
xor    %ebx,%ebx
nop
mov    (%rsp,%rbx,4),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1150 <threaded_test+0x30>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

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

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