#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 */

/* Variables and functions */
int dev_lseek(int, int, int);
int mx_lseek(int, int, int);
int u_lseek(int fd, int offset, int whence) {
  if (fd < 0)
    return -1;
  int fs = fd >> 8;
  int localfd = fd & 0xff;
  switch (fs) {
  case 1:
    return mx_lseek(localfd, offset, whence);
  case 2:
    return -1;
  case 3:
    return dev_lseek(localfd, offset, whence);
  case 0:
    return -1;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<u_lseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1147 <u_lseek+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <u_lseek+0xa7>
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x14(%rbp)
movzbl -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%rax
ja     11c0 <u_lseek+0xa0>
mov    -0x20(%rbp),%rax
lea    0xe8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <mx_lseek@plt>
mov    %eax,-0x4(%rbp)
jmp    11c7 <u_lseek+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <u_lseek+0xa7>
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <dev_lseek@plt>
mov    %eax,-0x4(%rbp)
jmp    11c7 <u_lseek+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <u_lseek+0xa7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_lseek>:
test   %edi,%edi
js     113c <u_lseek+0x1c>
mov    %edi,%eax
shr    $0x8,%eax
movzbl %dil,%edi
cmp    $0x3,%eax
je     1142 <u_lseek+0x22>
cmp    $0x1,%eax
jne    113c <u_lseek+0x1c>
jmp    1040 <mx_lseek@plt>
mov    $0xffffffff,%eax
ret
jmp    1030 <dev_lseek@plt>

LLVM IR (-O0):
define i32 @u_lseek(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %32
13: ; preds = %3
%14 = load i32, i32* %5
%15 = ashr i32 %14, 8
store i32 %15, i32* %8
%16 = load i32, i32* %5
%17 = and i32 %16, 255
store i32 %17, i32* %9
%18 = load i32, i32* %8
switch i32 %18, label %31 [
i32 1, label %19
i32 2, label %24
i32 3, label %25
i32 0, label %30
]
19: ; preds = %13
%20 = load i32, i32* %9
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @mx_lseek(i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %4
br label %32
24: ; preds = %13
store i32 -1, i32* %4
br label %32
25: ; preds = %13
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = call i32 @dev_lseek(i32 %26, i32 %27, i32 %28)
store i32 %29, i32* %4
br label %32
30: ; preds = %13
store i32 -1, i32* %4
br label %32
31: ; preds = %13
store i32 -1, i32* %4
br label %32
32: ; preds = %31, %30, %25, %24, %19, %12
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @u_lseek(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %0, 0
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = lshr i32 %0, 8
%7 = and i32 %0, 255
switch i32 %6, label %12 [
i32 1, label %8
i32 3, label %10
]
8: ; preds = %5
%9 = tail call i32 @mx_lseek(i32 %7, i32 %1, i32 %2)
br label %12
10: ; preds = %5
%11 = tail call i32 @dev_lseek(i32 %7, i32 %1, i32 %2)
br label %12
12: ; preds = %8, %10, %5, %3
%13 = phi i32 [ -1, %3 ], [ %11, %10 ], [ %9, %8 ], [ -1, %5 ]
ret i32 %13
}