#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 */

/* Variables and functions */
int countThreads();
int /*<<< orphan*/ findAndMakeThread(int, void (*)(int, void *), void *);
int /*<<< orphan*/ sleep(int);
void handelRequest(int sessionSock, void (*f)(int, void *), void *ptr) {
  if (countThreads() < 16) {
    findAndMakeThread(sessionSock, f, ptr);
  } else {
    while (countThreads() >= 16) {
      sleep(150);
    }
    findAndMakeThread(sessionSock, f, ptr);
  }
}


x86 assembly (clang, -O0):
<handelRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <countThreads@plt>
cmp    $0x10,%eax
jge    1168 <handelRequest+0x38>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <findAndMakeThread@plt>
jmp    119c <handelRequest+0x6c>
jmp    116d <handelRequest+0x3d>
mov    $0x0,%al
call   1030 <countThreads@plt>
cmp    $0x10,%eax
jl     118c <handelRequest+0x5c>
mov    $0x96,%edi
call   1050 <sleep@plt>
jmp    116d <handelRequest+0x3d>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <findAndMakeThread@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handelRequest>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <countThreads@plt>
cmp    $0x10,%eax
jl     1176 <handelRequest+0x46>
xor    %eax,%eax
call   1030 <countThreads@plt>
cmp    $0x10,%eax
jl     1176 <handelRequest+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x96,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <countThreads@plt>
cmp    $0xf,%eax
jg     1160 <handelRequest+0x30>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <findAndMakeThread@plt>

LLVM IR (-O0):
define void @handelRequest(i32 %0, void (i32, i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = alloca void (i32, i8*)*
%6 = alloca i8*
store i32 %0, i32* %4
store void (i32, i8*)* %1, void (i32, i8*)** %5
store i8* %2, i8** %6
%7 = call i32 (...) @countThreads()
%8 = icmp slt i32 %7, 16
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* %4
%11 = load void (i32, i8*)*, void (i32, i8*)** %5
%12 = load i8*, i8** %6
%13 = call i32 @findAndMakeThread(i32 %10, void (i32, i8*)* %11, i8* %12)
br label %25
14: ; preds = %3
br label %15
15: ; preds = %18, %14
%16 = call i32 (...) @countThreads()
%17 = icmp sge i32 %16, 16
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @sleep(i32 150)
br label %15
20: ; preds = %15
%21 = load i32, i32* %4
%22 = load void (i32, i8*)*, void (i32, i8*)** %5
%23 = load i8*, i8** %6
%24 = call i32 @findAndMakeThread(i32 %21, void (i32, i8*)* %22, i8* %23)
br label %25
25: ; preds = %20, %9
ret void
}

LLVM IR (-O2):
define void @handelRequest(i32 %0, void (i32, i8*)* %1, i8* %2) {
%4 = tail call i32 (...) @countThreads()
%5 = icmp slt i32 %4, 16
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i32 (...) @countThreads()
%8 = icmp sgt i32 %7, 15
br i1 %8, label %9, label %13
9: ; preds = %6, %9
%10 = tail call i32 @sleep(i32 150)
%11 = tail call i32 (...) @countThreads()
%12 = icmp sgt i32 %11, 15
br i1 %12, label %9, label %13
13: ; preds = %9, %6, %3
%14 = tail call i32 @findAndMakeThread(i32 %0, void (i32, i8*)* %1, i8* %2)
ret void
}