#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 /*<<< orphan*/ key_t;

/* Variables and functions */
scalar_t__ stat(char const *, struct stat *);
key_t ftok(const char *path, int id) {
  struct stat st;
  if (stat(path, &st) < 0)
    return (key_t)-1;
  return (key_t)((id & 0xff) << 24 | (st.st_dev & 0xff) << 16 |
                 (st.st_ino & 0xffff));
}


x86 assembly (clang, -O0):
<ftok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    1169 <ftok+0x59>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
shl    $0x18,%eax
mov    -0x20(%rbp),%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xffff,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%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>
shl    $0x18,%ebx
mov    0x8(%rsp),%eax
movzbl %al,%ecx
shl    $0x10,%ecx
or     %ebx,%ecx
movzwl 0xc(%rsp),%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
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i64 @stat(i8* %7, %struct.stat* %6)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %24
11: ; preds = %2
%12 = load i32, i32* %5
%13 = and i32 %12, 255
%14 = shl i32 %13, 24
%15 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%16 = load i32, i32* %15
%17 = and i32 %16, 255
%18 = shl i32 %17, 16
%19 = or i32 %14, %18
%20 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%21 = load i32, i32* %20
%22 = and i32 %21, 65535
%23 = or i32 %19, %22
store i32 %23, i32* %3
br label %24
24: ; preds = %11, %10
%25 = load i32, i32* %3
ret i32 %25
}

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 = shl i32 %1, 24
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = shl i32 %10, 16
%12 = and i32 %11, 16711680
%13 = or i32 %12, %8
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = and i32 %15, 65535
%17 = or i32 %13, %16
br label %18
18: ; preds = %2, %7
%19 = phi i32 [ %17, %7 ], [ -1, %2 ]
ret i32 %19
}