#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);
scalar_t__ start_member(int, int, int);
int start(int total, int shmsz) {
  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))
      return -1;
  } else {
    if (start_member(id, total, shmsz))
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1170 <start+0x30>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <start+0xcd>
mov    -0x8(%rbp),%edi
call   1040 <barrier_init@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1191 <start+0x51>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11a9 <start+0x69>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <start+0xcd>
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
jne    11dd <start+0x9d>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <start_leader@plt>
cmp    $0x0,%rax
je     11d8 <start+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <start+0xcd>
jmp    1206 <start+0xc6>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <start_member@plt>
cmp    $0x0,%rax
je     1201 <start+0xc1>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <start+0xcd>
jmp    1206 <start+0xc6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    1169 <start+0x29>
mov    %esi,%ebx
mov    %edi,%ebp
call   1040 <barrier_init@plt>
test   %eax,%eax
js     1172 <start+0x32>
cmp    %ebp,%eax
jge    1172 <start+0x32>
test   %eax,%eax
je     1185 <start+0x45>
mov    %eax,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <start_member@plt>
jmp    1190 <start+0x50>
lea    0xe9b(%rip),%rdi
jmp    1179 <start+0x39>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    119f <start+0x5f>
xor    %edi,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1060 <start_leader@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    119f <start+0x5f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
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) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
11: ; preds = %2
%12 = load i32, i32* %4
%13 = call i32 @barrier_init(i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp sge i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16, %11
%21 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
22: ; preds = %16
%23 = load i32, i32* %6
%24 = icmp eq i32 0, %23
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = call i64 @start_leader(i32 %26, i32 %27, i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 -1, i32* %3
br label %42
32: ; preds = %25
br label %41
33: ; preds = %22
%34 = load i32, i32* %6
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i64 @start_member(i32 %34, i32 %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 -1, i32* %3
br label %42
40: ; preds = %33
br label %41
41: ; preds = %40, %32
store i32 0, i32* %3
br label %42
42: ; preds = %41, %39, %31, %20, %9
%43 = load i32, i32* %3
ret i32 %43
}

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) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = tail call i32 @barrier_init(i32 %0)
%8 = icmp sgt i32 %7, -1
%9 = icmp slt i32 %7, %0
%10 = and i1 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %22
13: ; preds = %6
%14 = icmp eq i32 %7, 0
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = tail call i64 @start_leader(i32 0, i32 %0, i32 %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %22
18: ; preds = %13
%19 = tail call i64 @start_member(i32 %7, i32 %0, i32 %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18, %15
br label %22
22: ; preds = %18, %15, %21, %11, %4
%23 = phi i32 [ -1, %4 ], [ -1, %11 ], [ 0, %21 ], [ -1, %15 ], [ -1, %18 ]
ret i32 %23
}