#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 /*<<< orphan*/ u_long;
struct stat {
  scalar_t__ st_ino;
  scalar_t__ st_dev;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ ftok(char *, int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct stat file_state;
  if (argc != 2) {
    fprintf(stderr, "Usage: ./ftok filename\n");
    exit(1);
  }
  stat(argv[1], &file_state);
  printf("st_dev: %lx, st_ino: %lx\nid: 0x57, key: %x\n",
         (u_long)file_state.st_dev, (u_long)file_state.st_ino,
         ftok(argv[1], 0x57));
  return 0;
}


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   $0x2,-0x8(%rbp)
je     118f <main+0x3f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
mov    -0x18(%rbp),%rax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x57,%esi
call   1070 <ftok@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11a0 <main+0x50>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
mov    (%rsp),%r14d
mov    0x8(%rsp),%ebp
mov    0x8(%rbx),%rdi
mov    $0x57,%esi
call   1070 <ftok@plt>
lea    0xe8f(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: ./ftok filename\0A\00"
@.str.1 = [44 x i8] c"st_dev: %lx, st_ino: %lx\0Aid: 0x57, key: %x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @stat(i8* %16, %struct.stat* %6)
%18 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%22 = load i64, i64* %21
%23 = trunc i64 %22 to i32
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @ftok(i8* %26, i32 87)
%28 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %23, i32 %27)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: ./ftok filename\0A\00"
@.str.1 = [44 x i8] c"st_dev: %lx, st_ino: %lx\0Aid: 0x57, key: %x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @stat(i8* %12, %struct.stat* %3)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
%20 = load i8*, i8** %11
%21 = tail call i32 @ftok(i8* %20, i32 87)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %19, i32 %21)
ret i32 0
}