#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 _IOC_TYPE(unsigned int);
int block_ioctl(struct tcb *, unsigned int, long);
int loop_ioctl(struct tcb *, unsigned int, long);
int mtd_ioctl(struct tcb *, unsigned int, long);
int ptp_ioctl(struct tcb *, unsigned int, long);
int rtc_ioctl(struct tcb *, unsigned int, long);
int sock_ioctl(struct tcb *, unsigned int, long);
int term_ioctl(struct tcb *, unsigned int, long);
int ubi_ioctl(struct tcb *, unsigned int, long);
int v4l2_ioctl(struct tcb *, unsigned int, long);
int ioctl_decode(struct tcb *tcp, unsigned int code, long arg) {
  switch (_IOC_TYPE(code)) {
  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:
  case 'X':
    return block_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);
  case 'V':
    return v4l2_ioctl(tcp, code, arg);
  case '=':
    return ptp_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    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <_IOC_TYPE@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0x3,%eax
je     12d3 <ioctl_decode+0x133>
jmp    11ce <ioctl_decode+0x2e>
mov    -0x24(%rbp),%eax
sub    $0x12,%eax
je     12d3 <ioctl_decode+0x133>
jmp    11df <ioctl_decode+0x3f>
mov    -0x24(%rbp),%eax
sub    $0x3d,%eax
je     134b <ioctl_decode+0x1ab>
jmp    11f0 <ioctl_decode+0x50>
mov    -0x24(%rbp),%eax
sub    $0x4c,%eax
je     12eb <ioctl_decode+0x14b>
jmp    1201 <ioctl_decode+0x61>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
je     1303 <ioctl_decode+0x163>
jmp    1212 <ioctl_decode+0x72>
mov    -0x24(%rbp),%eax
sub    $0x4f,%eax
je     131b <ioctl_decode+0x17b>
jmp    1223 <ioctl_decode+0x83>
mov    -0x24(%rbp),%eax
sub    $0x54,%eax
je     128b <ioctl_decode+0xeb>
jmp    1234 <ioctl_decode+0x94>
mov    -0x24(%rbp),%eax
sub    $0x56,%eax
je     1333 <ioctl_decode+0x193>
jmp    1245 <ioctl_decode+0xa5>
mov    -0x24(%rbp),%eax
sub    $0x58,%eax
je     12d3 <ioctl_decode+0x133>
jmp    1256 <ioctl_decode+0xb6>
mov    -0x24(%rbp),%eax
sub    $0x6f,%eax
je     131b <ioctl_decode+0x17b>
jmp    1267 <ioctl_decode+0xc7>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
je     12bb <ioctl_decode+0x11b>
jmp    1278 <ioctl_decode+0xd8>
mov    -0x24(%rbp),%eax
sub    $0x89,%eax
je     12a3 <ioctl_decode+0x103>
jmp    1363 <ioctl_decode+0x1c3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <term_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <sock_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <rtc_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1080 <block_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <loop_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10a0 <mtd_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10c0 <ubi_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10b0 <v4l2_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1090 <ptp_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    136f <ioctl_decode+0x1cf>
jmp    1368 <ioctl_decode+0x1c8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ioctl_decode>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1070 <_IOC_TYPE@plt>
lea    -0x3(%rax),%ecx
cmp    $0x6d,%ecx
ja     11ed <ioctl_decode+0x4d>
lea    0xe3e(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <block_ioctl@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    10c0 <ubi_ioctl@plt>
cmp    $0x89,%eax
jne    1205 <ioctl_decode+0x65>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <sock_ioctl@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <ptp_ioctl@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <loop_ioctl@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    10a0 <mtd_ioctl@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <term_ioctl@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    10b0 <v4l2_ioctl@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <rtc_ioctl@plt>

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

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