#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 semaphoreInit(int /*<<< orphan*/);
int /*<<< orphan*/ setCap(void *, int);
int /*<<< orphan*/ setReadLock(void *, int);
int /*<<< orphan*/ setSize(void *, int /*<<< orphan*/);
int /*<<< orphan*/ setWriteLock(void *, int);
int dsInit(void *mem, int cap) {
  int rsemid, wsemid;
  rsemid = semaphoreInit((0));
  if (rsemid == -1)
    return -1;
  wsemid = semaphoreInit((0));
  if (wsemid == -1)
    return -1;
  setSize(mem, 0);
  setCap(mem, cap);
  setReadLock(mem, rsemid);
  setWriteLock(mem, wsemid);
  return 0;
}


x86 assembly (clang, -O0):
<dsInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %edi,%edi
call   1070 <semaphoreInit@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    117f <dsInit+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <dsInit+0x85>
xor    %edi,%edi
call   1070 <semaphoreInit@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    119f <dsInit+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <dsInit+0x85>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <setSize@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <setCap@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <setReadLock@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <setWriteLock@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dsInit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
xor    %edi,%edi
call   1070 <semaphoreInit@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11ac <dsInit+0x5c>
mov    %eax,%ebp
xor    %edi,%edi
call   1070 <semaphoreInit@plt>
cmp    $0xffffffff,%eax
je     11ac <dsInit+0x5c>
mov    %eax,%r15d
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <setSize@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1030 <setCap@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   1060 <setReadLock@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1050 <setWriteLock@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dsInit(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = call i32 @semaphoreInit(i32 0)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %29
12: ; preds = %2
%13 = call i32 @semaphoreInit(i32 0)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %3
br label %29
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = call i32 @setSize(i8* %18, i32 0)
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = call i32 @setCap(i8* %20, i32 %21)
%23 = load i8*, i8** %4
%24 = load i32, i32* %6
%25 = call i32 @setReadLock(i8* %23, i32 %24)
%26 = load i8*, i8** %4
%27 = load i32, i32* %7
%28 = call i32 @setWriteLock(i8* %26, i32 %27)
store i32 0, i32* %3
br label %29
29: ; preds = %17, %16, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @dsInit(i8* %0, i32 %1) {
%3 = tail call i32 @semaphoreInit(i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32 @semaphoreInit(i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @setSize(i8* %0, i32 0)
%10 = tail call i32 @setCap(i8* %0, i32 %1)
%11 = tail call i32 @setReadLock(i8* %0, i32 %3)
%12 = tail call i32 @setWriteLock(i8* %0, i32 %6)
br label %13
13: ; preds = %5, %2, %8
%14 = phi i32 [ 0, %8 ], [ -1, %2 ], [ -1, %5 ]
ret i32 %14
}