#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 /*<<< orphan*/ mx_reopen(int);
int u_reopen(int fd) {
  if (fd < 0)
    return -1;
  int fs = fd >> 8;
  int localfd = fd & 0xff;
  switch (fs) {
  case 1:
    return (fs << 8) + mx_reopen(localfd);
  case 2:
    return -1;
  case 3:
    return -1;
  case 0:
    return -1;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<u_reopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1131 <u_reopen+0x21>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <u_reopen+0xa1>
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     11aa <u_reopen+0x9a>
mov    -0x18(%rbp),%rax
lea    0xea3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <mx_reopen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <u_reopen+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <u_reopen+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <u_reopen+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <u_reopen+0xa1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_reopen>:
mov    %edi,%ecx
and    $0xffffff00,%ecx
mov    $0xffffffff,%eax
cmp    $0x100,%ecx
jne    1138 <u_reopen+0x28>
push   %rax
movzbl %dil,%edi
call   1030 <mx_reopen@plt>
add    $0x100,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
define i32 @u_reopen(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 %25
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 %24 [
i32 1, label %15
i32 2, label %21
i32 3, label %22
i32 0, label %23
]
15: ; preds = %9
%16 = load i32, i32* %4
%17 = shl i32 %16, 8
%18 = load i32, i32* %5
%19 = call i32 @mx_reopen(i32 %18)
%20 = add nsw i32 %17, %19
store i32 %20, i32* %2
br label %25
21: ; preds = %9
store i32 -1, i32* %2
br label %25
22: ; preds = %9
store i32 -1, i32* %2
br label %25
23: ; preds = %9
store i32 -1, i32* %2
br label %25
24: ; preds = %9
store i32 -1, i32* %2
br label %25
25: ; preds = %24, %23, %22, %21, %15, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @u_reopen(i32 %0) {
%2 = and i32 %0, -256
%3 = icmp eq i32 %2, 256
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = and i32 %0, 255
%6 = tail call i32 @mx_reopen(i32 %5)
%7 = add nsw i32 %6, 256
br label %8
8: ; preds = %4, %1
%9 = phi i32 [ -1, %1 ], [ %7, %4 ]
ret i32 %9
}