#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 int /*<<< orphan*/ key_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int semget(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int sem_create(key_t key) {
  int semid;
  semid = semget(key, 1, IPC_CREAT | IPC_EXCL | 0666);
  if (semid == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0b/semcreat.c",
              34, "semget", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  return semid;
}


x86 assembly (clang, -O0):
<sem_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    0x2e92(%rip),%rax
or     (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cf <sem_create+0x8f>
jmp    1182 <sem_create+0x42>
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%r9
lea    0xe57(%rip),%rsi
lea    0xe60(%rip),%rdx
mov    $0x22,%ecx
lea    0xeeb(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sem_create>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
mov    0x2e9f(%rip),%rax
or     (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%esi
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
je     116a <sem_create+0x2a>
pop    %rbx
ret
mov    0x2e67(%rip),%rax
mov    (%rax),%ebx
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe78(%rip),%rsi
lea    0xe81(%rip),%rdx
lea    0xf11(%rip),%r8
mov    %ebx,%edi
mov    $0x22,%ecx
mov    %rax,%r9
call   1040 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0b/semcreat.c\00"
@.str.2 = [7 x i8] c"semget\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @sem_create(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @IPC_CREAT
%6 = load i32, i32* @IPC_EXCL
%7 = or i32 %5, %6
%8 = or i32 %7, 438
%9 = call i32 @semget(i32 %4, i32 1, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %21
12: ; preds = %1
br label %13
13: ; preds = %12
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; No predecessors!
br label %21
21: ; preds = %20, %1
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0b/semcreat.c\00"
@.str.2 = [7 x i8] c"semget\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @sem_create(i32 %0) {
%2 = load i32, i32* @IPC_CREAT
%3 = load i32, i32* @IPC_EXCL
%4 = or i32 %2, %3
%5 = or i32 %4, 438
%6 = tail call i32 @semget(i32 %0, i32 1, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
ret i32 %6
}