#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 SASAllocateShmNameProj(char *key_name, char proj, void *addr, long size) {
  key_t shm_key;
  int shm_id = 0;
  char lower = ('a' - 'A');
  int proj_id;
  proj_id = (proj + lower);
  shm_key = ftok(key_name, (proj_id + lower));
  if (shm_key != (key_t)-1) {
    shm_id = SASAllocateShmID(shm_key, addr, size);
  }
  return (shm_id);
}


x86 assembly (clang, -O0):
<SASAllocateShmNameProj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movb   $0x20,-0x2d(%rbp)
movsbl -0x9(%rbp),%eax
movsbl -0x2d(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%esi
movsbl -0x2d(%rbp),%eax
add    %eax,%esi
call   1040 <ftok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
je     1187 <SASAllocateShmNameProj+0x67>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <SASAllocateShmID@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SASAllocateShmNameProj>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
add    $0x40,%esi
call   1040 <ftok@plt>
cmp    $0xffffffffffffffff,%rax
je     114d <SASAllocateShmNameProj+0x2d>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <SASAllocateShmID@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @SASAllocateShmNameProj(i8* %0, i8 signext %1, i8* %2, i64 %3) {
%5 = sext i8 %1 to i32
%6 = add nsw i32 %5, 64
%7 = tail call i64 @ftok(i8* %0, i32 %6)
%8 = icmp eq i64 %7, -1
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @SASAllocateShmID(i64 %7, i8* %2, i64 %3)
br label %11
11: ; preds = %9, %4
%12 = phi i32 [ %10, %9 ], [ 0, %4 ]
ret i32 %12
}