#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 *, int);
int msgget(scalar_t__, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  key_t key = -1;
  int msgqid = 0;
  key = ftok(".", 111);
  if (key < 0) {
    perror("ftok");
  }
  msgqid = msgget(key, IPC_CREAT | 0666);
  if (msgqid < 0) {
    perror("msgget");
  }
  printf("msgqid = %d\n", msgqid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
movl   $0x0,-0x1c(%rbp)
lea    0xe94(%rip),%rdi
mov    $0x6f,%esi
call   1060 <ftok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1191 <main+0x51>
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c2 <main+0x82>
lea    0xe4a(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
mov    $0x6f,%esi
call   1060 <ftok@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1188 <main+0x48>
mov    0x2e7f(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1030 <msgget@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1196 <main+0x56>
lea    0xe91(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
jmp    115a <main+0x1a>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
jmp    1176 <main+0x36>

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"
@.str.3 = [13 x i8] c"msgqid = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -1, i64* %6
store i32 0, i32* %7
%8 = call i64 @ftok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 111)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i64, i64* %6
%15 = load i32, i32* @IPC_CREAT
%16 = or i32 %15, 438
%17 = call i32 @msgget(i64 %14, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %13
%23 = load i32, i32* %7
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %23)
ret i32 0
}

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"
@.str.3 = [13 x i8] c"msgqid = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @ftok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 111)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = load i32, i32* @IPC_CREAT
%9 = or i32 %8, 438
%10 = tail call i32 @msgget(i64 %3, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
%15 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %10)
ret i32 0
}