#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 *path, int id) {
  struct stat st;
  if (stat(path, &st) < 0)
    return -1;
  return ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) |
          ((id & 0xff) << 24));
}


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    -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,-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>
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
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 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, 65535
%15 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%16 = load i32, i32* %15
%17 = and i32 %16, 255
%18 = shl i32 %17, 16
%19 = or i32 %14, %18
%20 = load i32, i32* %5
%21 = and i32 %20, 255
%22 = shl i32 %21, 24
%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 = 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
}