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

/* Variables and functions */
scalar_t__ stat(char const *, struct stat *);
key_t ftok(const char *pathname, int proj_id) {
  struct stat st;
  key_t key;
  if (stat(pathname, &st) < 0)
    return (key_t)-1;
  key = ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) |
         ((proj_id & 0xff) << 24));
  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    $0x0,%rax
jge    1142 <ftok+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    116f <ftok+0x5f>
mov    -0x20(%rbp),%eax
and    $0xffff,%eax
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x14(%rbp),%ecx
and    $0xff,%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%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>
test   %rax,%rax
js     113e <ftok+0x2e>
movzwl 0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
movzbl %cl,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
shl    $0x18,%ebx
or     %ecx,%ebx
jmp    1143 <ftok+0x33>
mov    $0xffffffff,%ebx
mov    %ebx,%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
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i64 @stat(i8* %8, %struct.stat* %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %26
12: ; preds = %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, 65535
%16 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%17 = load i32, i32* %16
%18 = and i32 %17, 255
%19 = shl i32 %18, 16
%20 = or i32 %15, %19
%21 = load i32, i32* %5
%22 = and i32 %21, 255
%23 = shl i32 %22, 24
%24 = or i32 %20, %23
store i32 %24, i32* %7
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %12, %11
%27 = load i32, i32* %3
ret i32 %27
}

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