#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 */
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(int *);
int shmget(int, int, int);
int get_semaphore_id() {
  int shmid;
  int *semarray, semid;
  shmid = shmget(
      ((22 << 25) | (12 << 20) | (13 << 15) | (11 << 10) | (5 << 5) | 25),
      sizeof(int), 0666);
  if (shmid == -1) {
    return -1;
  }
  semarray = (int *)shmat(shmid, NULL, 0);
  if (semarray == (int *)-1) {
    return -1;
  }
  semid = *semarray;
  shmdt(semarray);
  return semid;
}


x86 assembly (clang, -O0):
<get_semaphore_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x2cc6acb9,%edi
mov    $0x4,%esi
mov    $0x1b6,%edx
call   1050 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1165 <get_semaphore_id+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <get_semaphore_id+0x7c>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
jne    1194 <get_semaphore_id+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <get_semaphore_id+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <shmdt@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_semaphore_id>:
push   %rbx
mov    $0x2cc6acb9,%edi
mov    $0x4,%esi
mov    $0x1b6,%edx
call   1050 <shmget@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     116a <get_semaphore_id+0x3a>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     116a <get_semaphore_id+0x3a>
mov    (%rax),%ebx
mov    %rax,%rdi
call   1030 <shmdt@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @get_semaphore_id() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = call i32 @shmget(i32 751217849, i32 4, i32 438)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %22
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i64 @shmat(i32 %10, i32* null, i32 0)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp eq i32* %13, inttoptr (i64 -1 to i32*)
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 -1, i32* %1
br label %22
16: ; preds = %9
%17 = load i32*, i32** %3
%18 = load i32, i32* %17
store i32 %18, i32* %4
%19 = load i32*, i32** %3
%20 = call i32 @shmdt(i32* %19)
%21 = load i32, i32* %4
store i32 %21, i32* %1
br label %22
22: ; preds = %16, %15, %8
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
define i32 @get_semaphore_id() {
%1 = tail call i32 @shmget(i32 751217849, i32 4, i32 438)
%2 = icmp eq i32 %1, -1
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i64 @shmat(i32 %1, i32* null, i32 0)
%5 = inttoptr i64 %4 to i32*
%6 = icmp eq i32* %5, inttoptr (i64 -1 to i32*)
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i32, i32* %5
%9 = tail call i32 @shmdt(i32* %5)
br label %10
10: ; preds = %3, %0, %7
%11 = phi i32 [ %8, %7 ], [ -1, %0 ], [ -1, %3 ]
ret i32 %11
}