#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 /*<<< orphan*/ errExit(char *);
int ftok(char *, int const);
int shmget(int, int /*<<< orphan*/, int);
int init_msg(const int ext_key) {
  int shm_id = 0;
  key_t key;
  if ((key = ftok("/tmp", ext_key)) == -1)
    errExit("ftok()failed\n");
  if ((shm_id = shmget(key, 0, 0600)) == -1)
    errExit("shmget()failed\n");
  return (shm_id);
}


x86 assembly (clang, -O0):
<init_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
call   1050 <ftok@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1169 <init_msg+0x39>
lea    0xea1(%rip),%rdi
call   1030 <errExit@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x180,%edx
call   1040 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1190 <init_msg+0x60>
lea    0xe88(%rip),%rdi
call   1030 <errExit@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_msg>:
push   %rbx
mov    %edi,%esi
lea    0xec6(%rip),%rdi
call   1050 <ftok@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1152 <init_msg+0x22>
lea    0xeb8(%rip),%rdi
call   1030 <errExit@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x180,%edx
call   1040 <shmget@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1173 <init_msg+0x43>
lea    0xea5(%rip),%rdi
call   1030 <errExit@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/tmp\00"
@.str.1 = [14 x i8] c"ftok()failed\0A\00"
@.str.2 = [16 x i8] c"shmget()failed\0A\00"
define i32 @init_msg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* %2
%6 = call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @errExit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i32, i32* %4
%12 = call i32 @shmget(i32 %11, i32 0, i32 384)
store i32 %12, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @errExit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* %3
ret i32 %17
}

LLVM IR (-O2):
@.str = [5 x i8] c"/tmp\00"
@.str.1 = [14 x i8] c"ftok()failed\0A\00"
@.str.2 = [16 x i8] c"shmget()failed\0A\00"
define i32 @init_msg(i32 %0) {
%2 = tail call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @errExit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @shmget(i32 %2, i32 0, i32 384)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @errExit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
ret i32 %7
}