#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*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int ftok(char *, int);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
key_t hashpipe_ipckey(int proj_id) {
  key_t key = -1;
  char *keyfile = getenv("HASHPIPE_KEYFILE");
  if (!keyfile) {
    keyfile = getenv("HOME");
    if (!keyfile) {
      keyfile = "/tmp";
    }
  }
  fprintf(stderr,
          "using pathname '%s' and proj_id '%d' to generate base IPC key\n",
          keyfile, proj_id & 0xff);
  key = ftok(keyfile, proj_id);
  if (key == -1) {
    perror("ftok");
  }
  return key;
}


x86 assembly (clang, -O0):
<hashpipe_ipckey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1198 <hashpipe_ipckey+0x58>
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <hashpipe_ipckey+0x53>
lea    0xe87(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1198 <hashpipe_ipckey+0x58>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
and    $0xff,%ecx
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <ftok@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11df <hashpipe_ipckey+0x9f>
lea    0xe80(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashpipe_ipckey>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1173 <hashpipe_ipckey+0x33>
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xea7(%rip),%rbx
cmovne %rax,%rbx
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
movzbl %bpl,%ecx
lea    0xe94(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <ftok@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11a9 <hashpipe_ipckey+0x69>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeaa(%rip),%rdi
call   1050 <perror@plt>
jmp    11a0 <hashpipe_ipckey+0x60>

LLVM IR (-O0):
@.str = [17 x i8] c"HASHPIPE_KEYFILE\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [5 x i8] c"/tmp\00"
@stderr = global i32 0
@.str.3 = [63 x i8] c"using pathname '%s' and proj_id '%d' to generate base IPC key\0A\00"
@.str.4 = [5 x i8] c"ftok\00"
define i32 @hashpipe_ipckey(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
store i32 -1, i32* %3
%5 = call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %13
13: ; preds = %12, %8
br label %14
14: ; preds = %13, %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = load i32, i32* %2
%18 = and i32 %17, 255
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %16, i32 %18)
%20 = load i8*, i8** %4
%21 = load i32, i32* %2
%22 = call i32 @ftok(i8* %20, i32 %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [17 x i8] c"HASHPIPE_KEYFILE\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [5 x i8] c"/tmp\00"
@stderr = global i32 0
@.str.3 = [63 x i8] c"using pathname '%s' and proj_id '%d' to generate base IPC key\0A\00"
@.str.4 = [5 x i8] c"ftok\00"
define i32 @hashpipe_ipckey(i32 %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %5
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ %2, %1 ], [ %7, %4 ]
%10 = load i32, i32* @stderr
%11 = and i32 %0, 255
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 %11)
%13 = tail call i32 @ftok(i8* %9, i32 %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %8
ret i32 %13
}