#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 tcb {
  int dummy;
};

/* Variables and functions */
int block_ioctl(struct tcb *, long, long);
int loop_ioctl(struct tcb *, long, long);
int mtd_ioctl(struct tcb *, long, long);
int rtc_ioctl(struct tcb *, long, long);
int scsi_ioctl(struct tcb *, long, long);
int sock_ioctl(struct tcb *, long, long);
int term_ioctl(struct tcb *, long, long);
int ubi_ioctl(struct tcb *, long, long);
int ioctl_decode(struct tcb *tcp, long code, long arg) {
  switch ((code >> 8) & 0xff) {
  case 0x54:
    return term_ioctl(tcp, code, arg);
  case 0x89:
    return sock_ioctl(tcp, code, arg);
  case 'p':
    return rtc_ioctl(tcp, code, arg);
  case 0x03:
  case 0x12:
    return block_ioctl(tcp, code, arg);
  case 0x22:
    return scsi_ioctl(tcp, code, arg);
  case 'L':
    return loop_ioctl(tcp, code, arg);
  case 'M':
    return mtd_ioctl(tcp, code, arg);
  case 'o':
  case 'O':
    return ubi_ioctl(tcp, code, arg);
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ioctl_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movzbl -0x17(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x3,%rax
je     12a3 <ioctl_decode+0x123>
jmp    11ab <ioctl_decode+0x2b>
mov    -0x28(%rbp),%rax
sub    $0x12,%rax
je     12a3 <ioctl_decode+0x123>
jmp    11be <ioctl_decode+0x3e>
mov    -0x28(%rbp),%rax
sub    $0x22,%rax
je     12bc <ioctl_decode+0x13c>
jmp    11d1 <ioctl_decode+0x51>
mov    -0x28(%rbp),%rax
sub    $0x4c,%rax
je     12d5 <ioctl_decode+0x155>
jmp    11e4 <ioctl_decode+0x64>
mov    -0x28(%rbp),%rax
sub    $0x4d,%rax
je     12ee <ioctl_decode+0x16e>
jmp    11f7 <ioctl_decode+0x77>
mov    -0x28(%rbp),%rax
sub    $0x4f,%rax
je     1307 <ioctl_decode+0x187>
jmp    120a <ioctl_decode+0x8a>
mov    -0x28(%rbp),%rax
sub    $0x54,%rax
je     1258 <ioctl_decode+0xd8>
jmp    121d <ioctl_decode+0x9d>
mov    -0x28(%rbp),%rax
sub    $0x6f,%rax
je     1307 <ioctl_decode+0x187>
jmp    1230 <ioctl_decode+0xb0>
mov    -0x28(%rbp),%rax
sub    $0x70,%rax
je     128a <ioctl_decode+0x10a>
jmp    1243 <ioctl_decode+0xc3>
mov    -0x28(%rbp),%rax
sub    $0x89,%rax
je     1271 <ioctl_decode+0xf1>
jmp    1320 <ioctl_decode+0x1a0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <term_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <sock_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <rtc_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <block_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <scsi_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <loop_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <mtd_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   10a0 <ubi_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    132c <ioctl_decode+0x1ac>
jmp    1325 <ioctl_decode+0x1a5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ioctl_decode>:
mov    %rsi,%rax
shr    $0x8,%rax
cmp    $0x21,%al
jle    11ab <ioctl_decode+0x2b>
lea    -0x4c(%rax),%ecx
cmp    $0x24,%cl
ja     11c1 <ioctl_decode+0x41>
movzbl %cl,%eax
lea    0xe63(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    10a0 <ubi_ioctl@plt>
cmp    $0x89,%al
je     11bc <ioctl_decode+0x3c>
cmp    $0x3,%al
je     11b7 <ioctl_decode+0x37>
cmp    $0x12,%al
jne    11ca <ioctl_decode+0x4a>
jmp    1080 <block_ioctl@plt>
jmp    1040 <sock_ioctl@plt>
cmp    $0x22,%al
jne    11ca <ioctl_decode+0x4a>
jmp    1050 <scsi_ioctl@plt>
xor    %eax,%eax
ret
jmp    1030 <loop_ioctl@plt>
jmp    1090 <mtd_ioctl@plt>
jmp    1060 <term_ioctl@plt>
jmp    1070 <rtc_ioctl@plt>

LLVM IR (-O0):
%struct.tcb = type { i32 }
define i32 @ioctl_decode(%struct.tcb* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.tcb*
%6 = alloca i64
%7 = alloca i64
store %struct.tcb* %0, %struct.tcb** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i64, i64* %6
%9 = ashr i64 %8, 8
%10 = and i64 %9, 255
switch i64 %10, label %51 [
i64 84, label %11
i64 137, label %16
i64 112, label %21
i64 3, label %26
i64 18, label %26
i64 34, label %31
i64 76, label %36
i64 77, label %41
i64 111, label %46
i64 79, label %46
]
11: ; preds = %3
%12 = load %struct.tcb*, %struct.tcb** %5
%13 = load i64, i64* %6
%14 = load i64, i64* %7
%15 = call i32 @term_ioctl(%struct.tcb* %12, i64 %13, i64 %14)
store i32 %15, i32* %4
br label %53
16: ; preds = %3
%17 = load %struct.tcb*, %struct.tcb** %5
%18 = load i64, i64* %6
%19 = load i64, i64* %7
%20 = call i32 @sock_ioctl(%struct.tcb* %17, i64 %18, i64 %19)
store i32 %20, i32* %4
br label %53
21: ; preds = %3
%22 = load %struct.tcb*, %struct.tcb** %5
%23 = load i64, i64* %6
%24 = load i64, i64* %7
%25 = call i32 @rtc_ioctl(%struct.tcb* %22, i64 %23, i64 %24)
store i32 %25, i32* %4
br label %53
26: ; preds = %3, %3
%27 = load %struct.tcb*, %struct.tcb** %5
%28 = load i64, i64* %6
%29 = load i64, i64* %7
%30 = call i32 @block_ioctl(%struct.tcb* %27, i64 %28, i64 %29)
store i32 %30, i32* %4
br label %53
31: ; preds = %3
%32 = load %struct.tcb*, %struct.tcb** %5
%33 = load i64, i64* %6
%34 = load i64, i64* %7
%35 = call i32 @scsi_ioctl(%struct.tcb* %32, i64 %33, i64 %34)
store i32 %35, i32* %4
br label %53
36: ; preds = %3
%37 = load %struct.tcb*, %struct.tcb** %5
%38 = load i64, i64* %6
%39 = load i64, i64* %7
%40 = call i32 @loop_ioctl(%struct.tcb* %37, i64 %38, i64 %39)
store i32 %40, i32* %4
br label %53
41: ; preds = %3
%42 = load %struct.tcb*, %struct.tcb** %5
%43 = load i64, i64* %6
%44 = load i64, i64* %7
%45 = call i32 @mtd_ioctl(%struct.tcb* %42, i64 %43, i64 %44)
store i32 %45, i32* %4
br label %53
46: ; preds = %3, %3
%47 = load %struct.tcb*, %struct.tcb** %5
%48 = load i64, i64* %6
%49 = load i64, i64* %7
%50 = call i32 @ubi_ioctl(%struct.tcb* %47, i64 %48, i64 %49)
store i32 %50, i32* %4
br label %53
51: ; preds = %3
br label %52
52: ; preds = %51
store i32 0, i32* %4
br label %53
53: ; preds = %52, %46, %41, %36, %31, %26, %21, %16, %11
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
%struct.tcb = type { i32 }
define i32 @ioctl_decode(%struct.tcb* %0, i64 %1, i64 %2) {
%4 = lshr i64 %1, 8
%5 = trunc i64 %4 to i8
switch i8 %5, label %22 [
i8 84, label %6
i8 -119, label %8
i8 112, label %10
i8 3, label %12
i8 18, label %12
i8 34, label %14
i8 76, label %16
i8 77, label %18
i8 111, label %20
i8 79, label %20
]
6: ; preds = %3
%7 = tail call i32 @term_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
8: ; preds = %3
%9 = tail call i32 @sock_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
10: ; preds = %3
%11 = tail call i32 @rtc_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
12: ; preds = %3, %3
%13 = tail call i32 @block_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
14: ; preds = %3
%15 = tail call i32 @scsi_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
16: ; preds = %3
%17 = tail call i32 @loop_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
18: ; preds = %3
%19 = tail call i32 @mtd_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
20: ; preds = %3, %3
%21 = tail call i32 @ubi_ioctl(%struct.tcb* %0, i64 %1, i64 %2)
br label %22
22: ; preds = %3, %20, %18, %16, %14, %12, %10, %8, %6
%23 = phi i32 [ %21, %20 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ 0, %3 ]
ret i32 %23
}