#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_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
long LONG_MAX;
long LONG_MIN;
int _ftok(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ftok(char *, int);
int /*<<< orphan*/ helpAndExit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, int);
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  if (argc != 3)
    helpAndExit(argv[0], EXIT_FAILURE);
  long proj;
  char *endptr;
  proj = strtol(argv[2], &endptr, 10);
  if (*endptr != '\0' || proj == LONG_MIN || proj == LONG_MAX || proj <= 0)
    helpAndExit(argv[0], EXIT_FAILURE);
  key_t generated_key, system_key;
  generated_key = _ftok(argv[1], (int)proj);
  system_key = ftok(argv[1], (int)proj);
  if (generated_key == -1)
    pexit("_ftok");
  if (system_key == -1)
    pexit("ftok");
  printf("_ftok: \t0x%x\n", generated_key);
  printf("ftok:  \t0x%x\n", system_key);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a5 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndExit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1202 <main+0x92>
mov    -0x18(%rbp),%rax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
je     1202 <main+0x92>
mov    -0x18(%rbp),%rax
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
je     1202 <main+0x92>
cmpq   $0x0,-0x18(%rbp)
jg     1217 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndExit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
call   1030 <_ftok@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
call   1090 <ftok@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1259 <main+0xe9>
lea    0xdac(%rip),%rdi
call   1080 <pexit@plt>
cmpl   $0xffffffff,-0x28(%rbp)
jne    126f <main+0xff>
lea    0xd97(%rip),%rdi
call   1080 <pexit@plt>
mov    -0x24(%rbp),%esi
lea    0xd8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xd8c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     1191 <main+0x21>
mov    (%r14),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndExit@plt>
mov    0x10(%r14),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11ce <main+0x5e>
mov    0x2e30(%rip),%rax
cmp    (%rax),%rbx
je     11ce <main+0x5e>
test   %rbx,%rbx
jle    11ce <main+0x5e>
mov    0x2e0f(%rip),%rax
cmp    (%rax),%rbx
jne    11df <main+0x6f>
mov    (%r14),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndExit@plt>
mov    0x8(%r14),%rdi
mov    %ebx,%esi
call   1030 <_ftok@plt>
mov    %eax,%ebp
mov    0x8(%r14),%rdi
mov    %ebx,%esi
call   1090 <ftok@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%ebp
jne    120a <main+0x9a>
lea    0xdfb(%rip),%rdi
call   1080 <pexit@plt>
cmp    $0xffffffff,%ebx
jne    121b <main+0xab>
lea    0xdeb(%rip),%rdi
call   1080 <pexit@plt>
lea    0xde4(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
lea    0xde4(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@.str = [6 x i8] c"_ftok\00"
@.str.1 = [5 x i8] c"ftok\00"
@.str.2 = [14 x i8] c"_ftok: \090x%x\0A\00"
@.str.3 = [14 x i8] c"ftok: \090x%x\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @helpAndExit(i8* %15, i32 %16)
br label %18
18: ; preds = %12, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @strtol(i8* %21, i8** %7, i32 10)
store i64 %22, i64* %6
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %18
%28 = load i64, i64* %6
%29 = load i64, i64* @LONG_MIN
%30 = icmp eq i64 %28, %29
br i1 %30, label %38, label %31
31: ; preds = %27
%32 = load i64, i64* %6
%33 = load i64, i64* @LONG_MAX
%34 = icmp eq i64 %32, %33
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = load i64, i64* %6
%37 = icmp sle i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35, %31, %27, %18
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @helpAndExit(i8* %41, i32 %42)
br label %44
44: ; preds = %38, %35
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = load i64, i64* %6
%49 = trunc i64 %48 to i32
%50 = call i32 @_ftok(i8* %47, i32 %49)
store i32 %50, i32* %8
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = load i64, i64* %6
%55 = trunc i64 %54 to i32
%56 = call i32 @ftok(i8* %53, i32 %55)
store i32 %56, i32* %9
%57 = load i32, i32* %8
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %44
%60 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %61
61: ; preds = %59, %44
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %64, %61
%67 = load i32, i32* %8
%68 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %9
%70 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = load i32, i32* @EXIT_SUCCESS
%72 = call i32 @exit(i32 %71)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@.str = [6 x i8] c"_ftok\00"
@.str.1 = [5 x i8] c"ftok\00"
@.str.2 = [14 x i8] c"_ftok: \090x%x\0A\00"
@.str.3 = [14 x i8] c"ftok: \090x%x\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp eq i32 %0, 3
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @helpAndExit(i8* %6, i32 %7)
br label %9
9: ; preds = %5, %2
%10 = bitcast i8** %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = call i64 @strtol(i8* %12, i8** %3, i32 10)
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
%17 = load i64, i64* @LONG_MIN
%18 = icmp eq i64 %13, %17
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %25, label %20
20: ; preds = %9
%21 = load i64, i64* @LONG_MAX
%22 = icmp eq i64 %13, %21
%23 = icmp slt i64 %13, 1
%24 = or i1 %23, %22
br i1 %24, label %25, label %29
25: ; preds = %20, %9
%26 = load i8*, i8** %1
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @helpAndExit(i8* %26, i32 %27)
br label %29
29: ; preds = %20, %25
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = trunc i64 %13 to i32
%33 = tail call i32 @_ftok(i8* %31, i32 %32)
%34 = load i8*, i8** %30
%35 = tail call i32 @ftok(i8* %34, i32 %32)
%36 = icmp eq i32 %33, -1
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = tail call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %37, %29
%40 = icmp eq i32 %35, -1
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = tail call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
%44 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%45 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%46 = load i32, i32* @EXIT_SUCCESS
%47 = tail call i32 @exit(i32 %46)
unreachable
}