#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;
scalar_t__ ftok(char *, char);
int msgget(int, int);
int /*<<< orphan*/ perror(char *);
int init_msq(void) {
  key_t key = ftok(".", 'a');
  if (key < 0) {
    perror("ftok");
    goto err;
  }
  int msg_id = msgget(0x12345, IPC_CREAT | 0600);
  if (msg_id < 0) {
    perror("msgget");
    goto err;
  }
  return msg_id;
err:
  return -1;
}


x86 assembly (clang, -O0):
<init_msq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
mov    $0x61,%esi
call   1050 <ftok@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1169 <init_msq+0x39>
lea    0xea3(%rip),%rdi
call   1040 <perror@plt>
jmp    11ab <init_msq+0x7b>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
or     $0x180,%esi
mov    $0x12345,%edi
call   1030 <msgget@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a0 <init_msq+0x70>
lea    0xe71(%rip),%rdi
call   1040 <perror@plt>
jmp    11ab <init_msq+0x7b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <init_msq+0x82>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_msq>:
push   %rax
lea    0xec8(%rip),%rdi
mov    $0x61,%esi
call   1050 <ftok@plt>
test   %rax,%rax
js     1165 <init_msq+0x35>
mov    0x2e92(%rip),%rax
mov    $0x180,%esi
or     (%rax),%esi
mov    $0x12345,%edi
call   1030 <msgget@plt>
test   %eax,%eax
js     116e <init_msq+0x3e>
pop    %rcx
ret
lea    0xe96(%rip),%rdi
jmp    1175 <init_msq+0x45>
lea    0xe92(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

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

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