#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int key_t;
struct TYPE_2__ {
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ftok(char *, char);
TYPE_1__ *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ log_error(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
key_t get_shared_memory_token() {
  char lock_file[1024];
  key_t semaphore_key;
  sprintf(lock_file, "%s/streams.lock", getpwuid(getuid())->pw_dir);
  if ((semaphore_key = ftok(lock_file, 'm')) == -1) {
    log_error("Could not create token using ftok()", 1, errno);
    exit(EXIT_FAILURE);
  }
  return semaphore_key;
}


x86 assembly (clang, -O0):
<get_shared_memory_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    -0x400(%rbp),%rax
mov    %rax,-0x410(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    -0x410(%rbp),%rdi
mov    (%rax),%rdx
lea    0xe68(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x400(%rbp),%rdi
mov    $0x6d,%esi
call   1080 <ftok@plt>
mov    %eax,-0x404(%rbp)
cmp    $0xffffffff,%eax
jne    11e5 <get_shared_memory_token+0x85>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
lea    0xe43(%rip),%rdi
mov    $0x1,%esi
call   1030 <log_error@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x404(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_shared_memory_token>:
push   %rbx
sub    $0x400,%rsp
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    (%rax),%rdx
lea    0xe80(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x6d,%esi
call   1080 <ftok@plt>
cmp    $0xffffffff,%eax
je     11a6 <get_shared_memory_token+0x46>
add    $0x400,%rsp
pop    %rbx
ret
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    0xe5a(%rip),%rdi
mov    $0x1,%esi
call   1030 <log_error@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_2__ = type { i8* }
@.str = [16 x i8] c"%s/streams.lock\00"
@.str.1 = [36 x i8] c"Could not create token using ftok()\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @get_shared_memory_token() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = call i32 (...) @getuid()
%5 = call %struct.TYPE_2__* @getpwuid(i32 %4)
%6 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %5, i32 0, i32 0
%7 = load i8*, i8** %6
%8 = call i32 @sprintf(i8* %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%10 = call i32 @ftok(i8* %9, i8 signext 109)
store i32 %10, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* @errno
%14 = call i32 @log_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i8* }
@.str = [16 x i8] c"%s/streams.lock\00"
@.str.1 = [36 x i8] c"Could not create token using ftok()\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @get_shared_memory_token() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getuid()
%4 = tail call %struct.TYPE_2__* @getpwuid(i32 %3)
%5 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %4, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32 @ftok(i8* %2, i8 signext 109)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i32, i32* @errno
%12 = call i32 @log_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
ret i32 %8
}