#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 IPC_EXCL;
int ftok(char *, int);
long shmget(int, int, int);
long shmOpen(char *filename, char create, long count) {
  key_t key = ftok(filename, 0x03);
  if (key == -1) {
    return -1;
  }
  if (create) {
    return shmget(key, sizeof(float) * count, IPC_CREAT | IPC_EXCL | 0600);
  } else {
    return shmget(key, 0, 0);
  }
}


x86 assembly (clang, -O0):
<shmOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
call   1040 <ftok@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    115e <shmOpen+0x3e>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ab <shmOpen+0x8b>
cmpb   $0x0,-0x11(%rbp)
je     119b <shmOpen+0x7b>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    0x2e6b(%rip),%rax
or     (%rax),%edx
or     $0x180,%edx
call   1030 <shmget@plt>
mov    %rax,-0x8(%rbp)
jmp    11ab <shmOpen+0x8b>
mov    -0x24(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <shmget@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shmOpen>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    $0x3,%esi
call   1040 <ftok@plt>
cmp    $0xffffffff,%eax
je     115d <shmOpen+0x3d>
test   %bpl,%bpl
je     116b <shmOpen+0x4b>
shl    $0x2,%ebx
mov    0x2e92(%rip),%rcx
mov    (%rcx),%edx
mov    0x2ea1(%rip),%rcx
or     (%rcx),%edx
or     $0x180,%edx
mov    %eax,%edi
mov    %ebx,%esi
jmp    1171 <shmOpen+0x51>
mov    $0xffffffffffffffff,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <shmget@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
define i64 @shmOpen(i8* %0, i8 signext %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = call i32 @ftok(i8* %9, i32 3)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %3
store i64 -1, i64* %4
br label %30
14: ; preds = %3
%15 = load i8, i8* %6
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %8
%19 = load i64, i64* %7
%20 = mul i64 4, %19
%21 = trunc i64 %20 to i32
%22 = load i32, i32* @IPC_CREAT
%23 = load i32, i32* @IPC_EXCL
%24 = or i32 %22, %23
%25 = or i32 %24, 384
%26 = call i64 @shmget(i32 %18, i32 %21, i32 %25)
store i64 %26, i64* %4
br label %30
27: ; preds = %14
%28 = load i32, i32* %8
%29 = call i64 @shmget(i32 %28, i32 0, i32 0)
store i64 %29, i64* %4
br label %30
30: ; preds = %27, %17, %13
%31 = load i64, i64* %4
ret i64 %31
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
define i64 @shmOpen(i8* %0, i8 signext %1, i64 %2) {
%4 = tail call i32 @ftok(i8* %0, i32 3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = icmp eq i8 %1, 0
br i1 %7, label %16, label %8
8: ; preds = %6
%9 = trunc i64 %2 to i32
%10 = shl i32 %9, 2
%11 = load i32, i32* @IPC_CREAT
%12 = load i32, i32* @IPC_EXCL
%13 = or i32 %11, %12
%14 = or i32 %13, 384
%15 = tail call i64 @shmget(i32 %4, i32 %10, i32 %14)
br label %18
16: ; preds = %6
%17 = tail call i64 @shmget(i32 %4, i32 0, i32 0)
br label %18
18: ; preds = %3, %16, %8
%19 = phi i64 [ %15, %8 ], [ %17, %16 ], [ -1, %3 ]
ret i64 %19
}