#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ftok(char *, char);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
key_t service_key(char *service_name) {
  char path[80];
  sprintf(path, "/var/run/%s", service_name);
  key_t key = ftok(path, 'S');
  if (key == -1) {
    fprintf(stderr, "could not generate a key for '%s'\n", path);
    exit(1);
  }
  return key;
}


x86 assembly (clang, -O0):
<service_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea5(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x53,%esi
call   1060 <ftok@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    119e <service_key+0x5e>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<service_key>:
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rdx
lea    0xeb1(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x53,%esi
call   1060 <ftok@plt>
cmp    $0xffffffff,%eax
je     1172 <service_key+0x32>
add    $0x50,%rsp
pop    %rbx
ret
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    %rsp,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/var/run/%s\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"could not generate a key for '%s'\0A\00"
define i32 @service_key(i8* %0) {
%2 = alloca i8*
%3 = alloca [80 x i8]
%4 = alloca i32
store i8* %0, i8** %2
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%9 = call i32 @ftok(i8* %8, i8 signext 83)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = load i32, i32* %4
ret i32 %18
}

LLVM IR (-O2):
@.str = [12 x i8] c"/var/run/%s\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"could not generate a key for '%s'\0A\00"
define i32 @service_key(i8* %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @ftok(i8* %3, i8 signext 83)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
ret i32 %5
}