#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 */
scalar_t__ bufferCompleteInit(int);
scalar_t__ newServerThreadsArray(int);
scalar_t__ newShardArray(int, int);
int kos_init(int num_server_threads, int buf_size, int num_shards) {
  if (num_shards <= 0)
    return -1;
  if (num_server_threads <= 0)
    return -1;
  if (buf_size <= 0)
    return -1;
  if (num_server_threads != buf_size) {
    if (num_server_threads < buf_size) {
      buf_size = num_server_threads;
    } else {
      num_server_threads = buf_size;
    }
  }
  if (bufferCompleteInit(buf_size) != 0)
    return -1;
  if (newShardArray(num_shards, 10) != 0)
    return -1;
  if (newServerThreadsArray(num_server_threads) != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<kos_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     1157 <kos_init+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <kos_init+0xe7>
cmpl   $0x0,-0x8(%rbp)
jg     116d <kos_init+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <kos_init+0xe7>
cmpl   $0x0,-0xc(%rbp)
jg     1183 <kos_init+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <kos_init+0xe7>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11b1 <kos_init+0x81>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a6 <kos_init+0x76>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <kos_init+0x7c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11b1 <kos_init+0x81>
mov    -0xc(%rbp),%edi
call   1030 <bufferCompleteInit@plt>
cmp    $0x0,%rax
je     11cf <kos_init+0x9f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <kos_init+0xe7>
mov    -0x10(%rbp),%edi
mov    $0xa,%esi
call   1040 <newShardArray@plt>
cmp    $0x0,%rax
je     11f2 <kos_init+0xc2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <kos_init+0xe7>
mov    -0x8(%rbp),%edi
call   1050 <newServerThreadsArray@plt>
cmp    $0x0,%rax
je     1210 <kos_init+0xe0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <kos_init+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kos_init>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
test   %esi,%esi
jle    117f <kos_init+0x4f>
mov    %edi,%ebp
test   %edi,%edi
jle    117f <kos_init+0x4f>
mov    %edx,%ebx
test   %edx,%edx
jle    117f <kos_init+0x4f>
cmp    %esi,%ebp
mov    %esi,%edi
cmovb  %ebp,%edi
cmovne %edi,%ebp
cmove  %esi,%edi
call   1030 <bufferCompleteInit@plt>
test   %rax,%rax
jne    117f <kos_init+0x4f>
mov    %ebx,%edi
mov    $0xa,%esi
call   1040 <newShardArray@plt>
test   %rax,%rax
jne    117f <kos_init+0x4f>
mov    %ebp,%edi
call   1050 <newServerThreadsArray@plt>
neg    %rax
sbb    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @kos_init(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp sle i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 -1, i32* %4
br label %48
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 -1, i32* %4
br label %48
15: ; preds = %11
%16 = load i32, i32* %6
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -1, i32* %4
br label %48
19: ; preds = %15
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32, i32* %5
store i32 %28, i32* %6
br label %31
29: ; preds = %23
%30 = load i32, i32* %6
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %27
br label %32
32: ; preds = %31, %19
%33 = load i32, i32* %6
%34 = call i64 @bufferCompleteInit(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 -1, i32* %4
br label %48
37: ; preds = %32
%38 = load i32, i32* %7
%39 = call i64 @newShardArray(i32 %38, i32 10)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 -1, i32* %4
br label %48
42: ; preds = %37
%43 = load i32, i32* %5
%44 = call i64 @newServerThreadsArray(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 -1, i32* %4
br label %48
47: ; preds = %42
store i32 0, i32* %4
br label %48
48: ; preds = %47, %46, %41, %36, %18, %14, %10
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
define i32 @kos_init(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 1
%5 = icmp slt i32 %0, 1
%6 = or i1 %5, %4
%7 = icmp slt i32 %1, 1
%8 = or i1 %7, %6
br i1 %8, label %24, label %9
9: ; preds = %3
%10 = icmp eq i32 %0, %1
%11 = icmp ult i32 %0, %1
%12 = select i1 %11, i32 %0, i32 %1
%13 = select i1 %10, i32 %0, i32 %12
%14 = select i1 %10, i32 %1, i32 %12
%15 = tail call i64 @bufferCompleteInit(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %9
%18 = tail call i64 @newShardArray(i32 %2, i32 10)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = tail call i64 @newServerThreadsArray(i32 %13)
%22 = icmp ne i64 %21, 0
%23 = sext i1 %22 to i32
br label %24
24: ; preds = %20, %17, %9, %3
%25 = phi i32 [ -1, %3 ], [ -1, %9 ], [ -1, %17 ], [ %23, %20 ]
ret i32 %25
}