#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 key_t;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ exit(int);
int ftok(char *, int);
int msgget(int, int);
int /*<<< orphan*/ printf(char *);
int CommInit(int id, int create_new) {
  key_t key;
  if ((key = ftok("/home/yuandong/.bashrc", id)) == -1) {
    printf("Error! generate key failed!\n");
    exit(1);
  }
  int channel_id = -1;
  int attr = 0644;
  if (create_new == 1)
    attr |= IPC_CREAT;
  if ((channel_id = msgget(key, attr)) == -1) {
    printf("Error! create message queue failed! \n");
    exit(1);
  }
  return channel_id;
}


x86 assembly (clang, -O0):
<CommInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
lea    0xea8(%rip),%rdi
call   1060 <ftok@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    117f <CommInit+0x3f>
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0xffffffff,-0x10(%rbp)
movl   $0x1a4,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a6 <CommInit+0x66>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <msgget@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11d3 <CommInit+0x93>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CommInit>:
push   %rbx
mov    %esi,%ebx
mov    %edi,%esi
lea    0xeb4(%rip),%rdi
call   1060 <ftok@plt>
cmp    $0xffffffff,%eax
je     117a <CommInit+0x3a>
mov    0x2e83(%rip),%rcx
mov    $0x1a4,%edx
mov    (%rcx),%esi
or     %edx,%esi
cmp    $0x1,%ebx
cmovne %edx,%esi
mov    %eax,%edi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     1183 <CommInit+0x43>
pop    %rbx
ret
lea    0xebb(%rip),%rdi
jmp    118a <CommInit+0x4a>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/home/yuandong/.bashrc\00"
@.str.1 = [29 x i8] c"Error! generate key failed!\0A\00"
@IPC_CREAT = global i32 0
@.str.2 = [38 x i8] c"Error! create message queue failed! \0A\00"
define i32 @CommInit(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = call i32 @ftok(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
store i32 -1, i32* %6
store i32 420, i32* %7
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @IPC_CREAT
%19 = load i32, i32* %7
%20 = or i32 %19, %18
store i32 %20, i32* %7
br label %21
21: ; preds = %17, %14
%22 = load i32, i32* %5
%23 = load i32, i32* %7
%24 = call i32 @msgget(i32 %22, i32 %23)
store i32 %24, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
@.str = [23 x i8] c"/home/yuandong/.bashrc\00"
@IPC_CREAT = global i32 0
@str = [37 x i8] c"Error! create message queue failed! \00"
@str.3 = [28 x i8] c"Error! generate key failed!\00"
define i32 @CommInit(i32 %0, i32 %1) {
%3 = tail call i32 @ftok(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.3, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = icmp eq i32 %1, 1
%10 = load i32, i32* @IPC_CREAT
%11 = or i32 %10, 420
%12 = select i1 %9, i32 %11, i32 420
%13 = tail call i32 @msgget(i32 %3, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %8
ret i32 %13
}