#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 scalar_t__ key_t;

/* Variables and functions */
int IPC_CREAT;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int randomlyChoosePit();
int semget(scalar_t__, int, int);
int be_a_lion(key_t *sKey) {
  int semid = 0;
  int pitChoice = -1;
  if ((semid = semget(*sKey, 3 * 2,
                      IPC_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
                          S_IROTH | S_IWOTH)) == -1) {
    perror("semget : ");
    return -1;
  } else {
    printf("Ranger : Semaphore set got = %d, key = %d\n", semid, (int)*sKey);
  }
  pitChoice = randomlyChoosePit();
}


x86 assembly (clang, -O0):
<be_a_lion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    0x2e4f(%rip),%rax
or     (%rax),%edx
mov    0x2e66(%rip),%rax
or     (%rax),%edx
mov    0x2e4d(%rip),%rax
or     (%rax),%edx
mov    0x2e5c(%rip),%rax
or     (%rax),%edx
mov    0x2e33(%rip),%rax
or     (%rax),%edx
mov    0x2e0a(%rip),%rax
or     (%rax),%edx
mov    $0x6,%esi
call   1030 <semget@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ce <be_a_lion+0x8e>
lea    0xe43(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <be_a_lion+0xb0>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%edx
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <randomlyChoosePit@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<be_a_lion>:
push   %rbx
mov    0x2e70(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e86(%rip),%rax
or     (%rax),%edx
mov    0x2e6d(%rip),%rax
or     (%rax),%edx
mov    0x2e7c(%rip),%rax
or     (%rax),%edx
mov    %rdi,%rbx
mov    0x2e50(%rip),%rax
or     (%rax),%edx
mov    (%rdi),%rdi
mov    0x2e24(%rip),%rax
or     (%rax),%edx
mov    $0x6,%esi
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
je     11b3 <be_a_lion+0x73>
mov    (%rbx),%edx
lea    0xe6c(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <randomlyChoosePit@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
jmp    11ac <be_a_lion+0x6c>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str = [10 x i8] c"semget : \00"
@.str.1 = [43 x i8] c"Ranger : Semaphore set got = %d, key = %d\0A\00"
define i32 @be_a_lion(i64* %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i32
store i64* %0, i64** %3
store i32 0, i32* %4
store i32 -1, i32* %5
%6 = load i64*, i64** %3
%7 = load i64, i64* %6
%8 = load i32, i32* @IPC_CREAT
%9 = load i32, i32* @S_IRUSR
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IWGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IROTH
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IWOTH
%20 = or i32 %18, %19
%21 = call i32 @semget(i64 %7, i32 6, i32 %20)
store i32 %21, i32* %4
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %1
%24 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %33
25: ; preds = %1
%26 = load i32, i32* %4
%27 = load i64*, i64** %3
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %29)
br label %31
31: ; preds = %25
%32 = call i32 (...) @randomlyChoosePit()
store i32 %32, i32* %5
br label %33
33: ; preds = %31, %23
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str = [10 x i8] c"semget : \00"
@.str.1 = [43 x i8] c"Ranger : Semaphore set got = %d, key = %d\0A\00"
define i32 @be_a_lion(i64* nocapture %0) {
%2 = load i64, i64* %0
%3 = load i32, i32* @IPC_CREAT
%4 = load i32, i32* @S_IRUSR
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRGRP
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IWGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IWOTH
%15 = or i32 %13, %14
%16 = tail call i32 @semget(i64 %2, i32 6, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %25
20: ; preds = %1
%21 = load i64, i64* %0
%22 = trunc i64 %21 to i32
%23 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %22)
%24 = tail call i32 (...) @randomlyChoosePit()
br label %25
25: ; preds = %20, %18
ret i32 -1
}