#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 IPC_CREAT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ SETVAL;
int /*<<< orphan*/ handle_fatal_error(char *);
scalar_t__ semctl(int, int, int /*<<< orphan*/, int);
int semget(int /*<<< orphan*/, int, int);
int initialize_semaphores(void) {
  int semid;
  if ((semid = semget(IPC_PRIVATE, 2, IPC_CREAT | 0600)) < 0) {
    handle_fatal_error("Error when creating semaphores!\n");
  }
  if (semctl(semid, 1, SETVAL, 5) < 0) {
    handle_fatal_error("Error during initialization of the first semaphore.\n");
  }
  if (semctl(semid, 0, SETVAL, 0) < 0) {
    handle_fatal_error(
        "Error during initialization of the second semaphore.\n");
  }
  return semid;
}


x86 assembly (clang, -O0):
<initialize_semaphores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0x2,%esi
call   1030 <semget@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1172 <initialize_semaphores+0x42>
lea    0xe93(%rip),%rdi
call   1040 <handle_fatal_error@plt>
mov    -0x4(%rbp),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
mov    $0x5,%ecx
call   1050 <semctl@plt>
cmp    $0x0,%rax
jge    11a3 <initialize_semaphores+0x73>
lea    0xe83(%rip),%rdi
call   1040 <handle_fatal_error@plt>
mov    -0x4(%rbp),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
mov    %ecx,%esi
call   1050 <semctl@plt>
cmp    $0x0,%rax
jge    11ce <initialize_semaphores+0x9e>
lea    0xe8d(%rip),%rdi
call   1040 <handle_fatal_error@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialize_semaphores>:
push   %r14
push   %rbx
push   %rax
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    0x2e94(%rip),%rax
mov    $0x180,%edx
or     (%rax),%edx
mov    $0x2,%esi
call   1030 <semget@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1167 <initialize_semaphores+0x37>
lea    0xe9e(%rip),%rdi
call   1040 <handle_fatal_error@plt>
mov    0x2e62(%rip),%r14
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x5,%ecx
call   1050 <semctl@plt>
test   %rax,%rax
jns    1193 <initialize_semaphores+0x63>
lea    0xe93(%rip),%rdi
call   1040 <handle_fatal_error@plt>
mov    (%r14),%edx
mov    %ebx,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <semctl@plt>
test   %rax,%rax
jns    11b2 <initialize_semaphores+0x82>
lea    0xea9(%rip),%rdi
call   1040 <handle_fatal_error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [33 x i8] c"Error when creating semaphores!\0A\00"
@SETVAL = global i32 0
@.str.1 = [53 x i8] c"Error during initialization of the first semaphore.\0A\00"
@.str.2 = [54 x i8] c"Error during initialization of the second semaphore.\0A\00"
define i32 @initialize_semaphores() {
%1 = alloca i32
%2 = load i32, i32* @IPC_PRIVATE
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 384
%5 = call i32 @semget(i32 %2, i32 2, i32 %4)
store i32 %5, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* %1
%11 = load i32, i32* @SETVAL
%12 = call i64 @semctl(i32 %10, i32 1, i32 %11, i32 5)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = load i32, i32* %1
%18 = load i32, i32* @SETVAL
%19 = call i64 @semctl(i32 %17, i32 0, i32 %18, i32 0)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [33 x i8] c"Error when creating semaphores!\0A\00"
@SETVAL = global i32 0
@.str.1 = [53 x i8] c"Error during initialization of the first semaphore.\0A\00"
@.str.2 = [54 x i8] c"Error during initialization of the second semaphore.\0A\00"
define i32 @initialize_semaphores() {
%1 = load i32, i32* @IPC_PRIVATE
%2 = load i32, i32* @IPC_CREAT
%3 = or i32 %2, 384
%4 = tail call i32 @semget(i32 %1, i32 2, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @handle_fatal_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i32, i32* @SETVAL
%10 = tail call i64 @semctl(i32 %4, i32 1, i32 %9, i32 5)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @handle_fatal_error(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* @SETVAL
%16 = tail call i64 @semctl(i32 %4, i32 0, i32 %15, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @handle_fatal_error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
ret i32 %4
}