#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 {
  int st_dev;
  int st_ino;
};
typedef int key_t;

/* Variables and functions */
int stat(char *, struct stat *);
key_t _ftok(char *pathname, int proj) {
  struct stat info;
  if (stat(pathname, &info) == -1)
    return -1;
  int projbits = 0, devbits = 0, inodebits = 0;
  key_t key = 0;
  projbits = proj & 0xff;
  devbits = info.st_dev & 0xff;
  inodebits = info.st_ino & 0xffff;
  key |= projbits;
  key <<= 8;
  key |= devbits;
  key <<= 16;
  key |= inodebits;
  return key;
}


x86 assembly (clang, -O0):
<_ftok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
jne    1141 <_ftok+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <_ftok+0xa1>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ftok>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
je     113e <_ftok+0x2e>
mov    0x8(%rsp),%eax
movzwl 0xc(%rsp),%ecx
shl    $0x18,%ebx
movzbl %al,%eax
shl    $0x10,%eax
or     %ebx,%eax
or     %ecx,%eax
jmp    1143 <_ftok+0x33>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
define i32 @_ftok(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i8*, i8** %4
%12 = call i32 @stat(i8* %11, %struct.stat* %6)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %38
15: ; preds = %2
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%16 = load i32, i32* %5
%17 = and i32 %16, 255
store i32 %17, i32* %7
%18 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, 255
store i32 %20, i32* %8
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%22 = load i32, i32* %21
%23 = and i32 %22, 65535
store i32 %23, i32* %9
%24 = load i32, i32* %7
%25 = load i32, i32* %10
%26 = or i32 %25, %24
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = shl i32 %27, 8
store i32 %28, i32* %10
%29 = load i32, i32* %8
%30 = load i32, i32* %10
%31 = or i32 %30, %29
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = shl i32 %32, 16
store i32 %33, i32* %10
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = or i32 %35, %34
store i32 %36, i32* %10
%37 = load i32, i32* %10
store i32 %37, i32* %3
br label %38
38: ; preds = %15, %14
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
define i32 @_ftok(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %0, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %18, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%11 = load i32, i32* %10
%12 = and i32 %11, 65535
%13 = shl i32 %1, 24
%14 = shl i32 %9, 16
%15 = and i32 %14, 16711680
%16 = or i32 %15, %13
%17 = or i32 %16, %12
br label %18
18: ; preds = %2, %7
%19 = phi i32 [ %17, %7 ], [ -1, %2 ]
ret i32 %19
}