#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 SASAllocateShmID(scalar_t__, void *, long);
scalar_t__ ftok(char *, int);
int /*<<< orphan*/ printf(char *, char *, void *, long, int);
int SASAllocateShmName(char *key_name, void *addr, long size) {
  key_t shm_key;
  int shm_id = 0;
  int proj_id;
  proj_id = 'r';
  printf("SASAllocateShmName(%s, %p, %ld); projID = %d\n", key_name, addr, size,
         proj_id);
  shm_key = ftok(key_name, proj_id);
  if (shm_key != (key_t)-1) {
    shm_id = SASAllocateShmID(shm_key, addr, size);
  }
  return (shm_id);
}


x86 assembly (clang, -O0):
<SASAllocateShmName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x72,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8d
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1050 <ftok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
je     119d <SASAllocateShmName+0x6d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <SASAllocateShmID@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SASAllocateShmName>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xebb(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x72,%r8d
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x72,%esi
call   1050 <ftok@plt>
cmp    $0xffffffffffffffff,%rax
je     117f <SASAllocateShmName+0x4f>
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <SASAllocateShmID@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [46 x i8] c"SASAllocateShmName(%s, %p, %ld); projID = %d\0A\00"
define i32 @SASAllocateShmName(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %8
store i32 114, i32* %9
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = load i32, i32* %9
%14 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11, i64 %12, i32 %13)
%15 = load i8*, i8** %4
%16 = load i32, i32* %9
%17 = call i64 @ftok(i8* %15, i32 %16)
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = icmp ne i64 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %3
%21 = load i64, i64* %7
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i32 @SASAllocateShmID(i64 %21, i8* %22, i64 %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %20, %3
%26 = load i32, i32* %8
ret i32 %26
}

LLVM IR (-O2):
@.str = [46 x i8] c"SASAllocateShmName(%s, %p, %ld); projID = %d\0A\00"
define i32 @SASAllocateShmName(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i64 %2, i32 114)
%5 = tail call i64 @ftok(i8* %0, i32 114)
%6 = icmp eq i64 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @SASAllocateShmID(i64 %5, i8* %1, i64 %2)
br label %9
9: ; preds = %7, %3
%10 = phi i32 [ %8, %7 ], [ 0, %3 ]
ret i32 %10
}