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

/* Variables and functions */
int /*<<< orphan*/ sem_init(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
void initializeSemaphores(sem_t *lock, sem_t *forks, int nForks) {
  int i;
  for (i = 0; i < nForks; i++) {
    sem_init(&forks[i], 0, 1);
  }
  sem_init(lock, 0, nForks - 1);
}


x86 assembly (clang, -O0):
<initializeSemaphores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    115f <initializeSemaphores+0x4f>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <sem_init@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <initializeSemaphores+0x1a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <sem_init@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initializeSemaphores>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rdi,%r14
test   %edx,%edx
jle    1149 <initializeSemaphores+0x39>
mov    %rsi,%rbx
mov    %r15d,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <sem_init@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1130 <initializeSemaphores+0x20>
add    $0xffffffff,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sem_init@plt>

LLVM IR (-O0):
define void @initializeSemaphores(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %18, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i32*, i32** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = call i32 @sem_init(i32* %16, i32 0, i32 1)
br label %18
18: ; preds = %12
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %8
21: ; preds = %8
%22 = load i32*, i32** %4
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
%25 = call i32 @sem_init(i32* %22, i32 0, i32 %24)
ret void
}

LLVM IR (-O2):
define void @initializeSemaphores(i32* %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %11, %7 ]
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = tail call i32 @sem_init(i32* %9, i32 0, i32 1)
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, %6
br i1 %12, label %13, label %7
13: ; preds = %7, %3
%14 = add nsw i32 %2, -1
%15 = tail call i32 @sem_init(i32* %0, i32 0, i32 %14)
ret void
}