#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_close(int);
int mx_close(int);
int u_close(int fd) {
  if (fd < 0)
    return -1;
  int fs = fd >> 8;
  int localfd = fd & 0xff;
  switch (fs) {
  case 1:
    return mx_close(localfd);
  case 2:
    return -1;
  case 3:
    return dev_close(localfd);
  case 0:
    return -1;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<u_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1141 <u_close+0x21>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <u_close+0x95>
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
movzbl -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     11ae <u_close+0x8e>
mov    -0x18(%rbp),%rax
lea    0xe93(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%edi
call   1030 <mx_close@plt>
mov    %eax,-0x4(%rbp)
jmp    11b5 <u_close+0x95>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <u_close+0x95>
mov    -0x10(%rbp),%edi
call   1040 <dev_close@plt>
mov    %eax,-0x4(%rbp)
jmp    11b5 <u_close+0x95>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <u_close+0x95>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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