#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 */
struct stat {
  scalar_t__ st_ino;
  scalar_t__ st_dev;
};
typedef int key_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ftok(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (2 != argc) {
    printf("usage: %s <pathname>\n", argv[0]);
    exit(0);
  }
  struct stat st;
  if (0 != stat(argv[1], &st)) {
    perror("stat error");
    exit(0);
  }
  key_t key = ftok(argv[1], 0x57);
  if (-1 == key) {
    printf("ftok error: %s\n", strerror(errno));
    exit(0);
  }
  printf("st_dev: %lx, st_ino: %lx, key: %x\n", (unsigned long)st.st_dev,
         (unsigned long)st.st_ino, key);
  exit(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)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     11a0 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11d2 <main+0x72>
lea    0xe50(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x57,%esi
call   1070 <ftok@plt>
mov    %eax,-0x24(%rbp)
mov    $0xffffffff,%eax
cmp    -0x24(%rbp),%eax
jne    121b <main+0xbb>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ab <main+0x4b>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %rax,%rax
jne    11c3 <main+0x63>
mov    0x8(%rbx),%rdi
mov    $0x57,%esi
call   1070 <ftok@plt>
cmp    $0xffffffff,%eax
jne    11d6 <main+0x76>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe7b(%rip),%rdi
mov    %rax,%rsi
jmp    11b5 <main+0x55>
mov    (%rbx),%rsi
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rsi
lea    0xe4b(%rip),%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@.str = [22 x i8] c"usage: %s <pathname>\0A\00"
@.str.1 = [11 x i8] c"stat error\00"
@.str.2 = [16 x i8] c"ftok error: %s\0A\00"
@errno = global i32 0
@.str.3 = [35 x i8] c"st_dev: %lx, st_ino: %lx, key: %x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 2, %8
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @stat(i8* %19, %struct.stat* %6)
%21 = icmp ne i64 0, %20
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @ftok(i8* %28, i32 87)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 -1, %30
br i1 %31, label %32, label %37
32: ; preds = %25
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %25
%38 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%39 = load i64, i64* %38
%40 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%41 = load i64, i64* %40
%42 = load i32, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i64 %39, i64 %41, i32 %42)
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@.str = [22 x i8] c"usage: %s <pathname>\0A\00"
@.str.1 = [11 x i8] c"stat error\00"
@.str.2 = [16 x i8] c"ftok error: %s\0A\00"
@errno = global i32 0
@.str.3 = [35 x i8] c"st_dev: %lx, st_ino: %lx, key: %x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = bitcast %struct.stat* %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @stat(i8* %12, %struct.stat* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %9
%19 = load i8*, i8** %11
%20 = call i32 @ftok(i8* %19, i32 87)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %18
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%31 = load i64, i64* %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i64 %29, i64 %31, i32 %20)
%33 = call i32 @exit(i32 0)
unreachable
}