#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ftok(char *, int);
int msgget(int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int init_qmsg(int identifier) {
  int q_id;
  key_t q_key;
  q_key = ftok("/dev/random", identifier);
  q_id = msgget(q_key, IPC_CREAT | 0660);
  if (q_id < 0) {
    perror("msgget");
    exit(EXIT_FAILURE);
  }
  return q_id;
}


x86 assembly (clang, -O0):
<init_qmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1060 <ftok@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
or     $0x1b0,%esi
call   1030 <msgget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119b <init_qmsg+0x5b>
lea    0xe84(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_qmsg>:
push   %rax
mov    %edi,%esi
lea    0xeb6(%rip),%rdi
call   1060 <ftok@plt>
mov    0x2e82(%rip),%rcx
mov    $0x1b0,%esi
or     (%rcx),%esi
mov    %eax,%edi
call   1030 <msgget@plt>
test   %eax,%eax
js     116a <init_qmsg+0x2a>
pop    %rcx
ret
lea    0xe9b(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@IPC_CREAT = global i32 0
@.str.1 = [7 x i8] c"msgget\00"
@EXIT_FAILURE = global i32 0
define i32 @init_qmsg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @ftok(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @IPC_CREAT
%9 = or i32 %8, 432
%10 = call i32 @msgget(i32 %7, i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@IPC_CREAT = global i32 0
@.str.1 = [7 x i8] c"msgget\00"
@EXIT_FAILURE = global i32 0
define i32 @init_qmsg(i32 %0) {
%2 = tail call i32 @ftok(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 432
%5 = tail call i32 @msgget(i32 %2, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
ret i32 %5
}