#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 */
scalar_t__ close_queue(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ftok(char *, int);
int open_queue(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int qid;
  key_t msgkey;
  struct serial_msg {
    long mtype;
    char serial_char;
  } msg;
  msgkey = ftok(".", 1203);
  if ((qid = open_queue(msgkey)) == -1) {
    perror("open_queue");
    exit(1);
  }
  if (close_queue(qid) == 0) {
    printf("Closed queue %d", qid);
  }
  printf("Message queue id: %d\n", qid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x4b3,%esi
call   1080 <ftok@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <open_queue@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11ad <main+0x4d>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <close_queue@plt>
cmp    $0x0,%rax
jne    11ce <main+0x6e>
mov    -0x8(%rbp),%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
mov    $0x4b3,%esi
call   1080 <ftok@plt>
mov    %eax,%edi
call   1040 <open_queue@plt>
cmp    $0xffffffff,%eax
je     11ac <main+0x4c>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <close_queue@plt>
test   %rax,%rax
jne    119a <main+0x3a>
lea    0xe7a(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe4f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.serial_msg = type { i64, i8 }
@.str = [2 x i8] c".\00"
@.str.1 = [11 x i8] c"open_queue\00"
@.str.2 = [16 x i8] c"Closed queue %d\00"
@.str.3 = [22 x i8] c"Message queue id: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.serial_msg
store i32 0, i32* %1
%5 = call i32 @ftok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1203)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @open_queue(i32 %6)
store i32 %7, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i64 @close_queue(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %12
%20 = load i32, i32* %2
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %20)
ret i32 0
}

LLVM IR (-O2):
%struct.serial_msg = type { i64, i8 }
@.str = [2 x i8] c".\00"
@.str.1 = [11 x i8] c"open_queue\00"
@.str.2 = [16 x i8] c"Closed queue %d\00"
@.str.3 = [22 x i8] c"Message queue id: %d\0A\00"
define i32 @main() {
%1 = tail call i32 @ftok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1203)
%2 = tail call i32 @open_queue(i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i64 @close_queue(i32 %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %2)
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %2)
ret i32 0
}