#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 barrier_init(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ start_leader(int, int, int, int);
scalar_t__ start_member(int, int, int, int);
int start(int total, int shmsz, int flags) {
  int id;
  if (total <= 0) {
    printf("Invalid patameters\n");
    return -1;
  }
  id = barrier_init(total);
  if ((id < 0) || (id >= total)) {
    printf("Invalid ID\n");
    return -1;
  }
  if (0 == id) {
    if (start_leader(id, total, shmsz, flags))
      return -1;
  } else {
    if (start_member(id, total, shmsz, flags))
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1173 <start+0x33>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <start+0xd6>
mov    -0x8(%rbp),%edi
call   1040 <barrier_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1194 <start+0x54>
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11ac <start+0x6c>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <start+0xd6>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11e3 <start+0xa3>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1060 <start_leader@plt>
cmp    $0x0,%rax
je     11de <start+0x9e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <start+0xd6>
jmp    120f <start+0xcf>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <start_member@plt>
cmp    $0x0,%rax
je     120a <start+0xca>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <start+0xd6>
jmp    120f <start+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
jle    1170 <start+0x30>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
call   1040 <barrier_init@plt>
test   %eax,%eax
js     1179 <start+0x39>
cmp    %ebx,%eax
jge    1179 <start+0x39>
test   %eax,%eax
je     118c <start+0x4c>
mov    %eax,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1050 <start_member@plt>
jmp    119a <start+0x5a>
lea    0xe94(%rip),%rdi
jmp    1180 <start+0x40>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    11a9 <start+0x69>
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1060 <start_leader@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11a9 <start+0x69>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Invalid patameters\0A\00"
@.str.1 = [12 x i8] c"Invalid ID\0A\00"
define i32 @start(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %46
13: ; preds = %3
%14 = load i32, i32* %5
%15 = call i32 @barrier_init(i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = icmp sge i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18, %13
%23 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %46
24: ; preds = %18
%25 = load i32, i32* %8
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32, i32* %8
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i64 @start_leader(i32 %28, i32 %29, i32 %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 -1, i32* %4
br label %46
35: ; preds = %27
br label %45
36: ; preds = %24
%37 = load i32, i32* %8
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = call i64 @start_member(i32 %37, i32 %38, i32 %39, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %36
store i32 -1, i32* %4
br label %46
44: ; preds = %36
br label %45
45: ; preds = %44, %35
store i32 0, i32* %4
br label %46
46: ; preds = %45, %43, %34, %22, %11
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@str = [11 x i8] c"Invalid ID\00"
@str.2 = [19 x i8] c"Invalid patameters\00"
define i32 @start(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %0, 1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
br label %23
7: ; preds = %3
%8 = tail call i32 @barrier_init(i32 %0)
%9 = icmp sgt i32 %8, -1
%10 = icmp slt i32 %8, %0
%11 = and i1 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %23
14: ; preds = %7
%15 = icmp eq i32 %8, 0
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = tail call i64 @start_leader(i32 0, i32 %0, i32 %1, i32 %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %23
19: ; preds = %14
%20 = tail call i64 @start_member(i32 %8, i32 %0, i32 %1, i32 %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19, %16
br label %23
23: ; preds = %19, %16, %22, %12, %5
%24 = phi i32 [ -1, %5 ], [ -1, %12 ], [ 0, %22 ], [ -1, %16 ], [ -1, %19 ]
ret i32 %24
}