int ioctl_decode(tcp, code, arg)
struct tcb *tcp;
long code, arg;
{
  switch ((code >> 8) & 0xff) {
  case 'f':
  case 't':
  case 'T':
    return term_ioctl(tcp, code, arg);
  case 'r':
  case 's':
  case 'i':
  case 'p':
    return sock_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    $0x54,%rax
je     11ae <ioctl_decode+0x8e>
jmp    114b <ioctl_decode+0x2b>
mov    -0x28(%rbp),%rax
sub    $0x66,%rax
je     11ae <ioctl_decode+0x8e>
jmp    115e <ioctl_decode+0x3e>
mov    -0x28(%rbp),%rax
sub    $0x69,%rax
je     11c9 <ioctl_decode+0xa9>
jmp    1171 <ioctl_decode+0x51>
mov    -0x28(%rbp),%rax
sub    $0x70,%rax
je     11c9 <ioctl_decode+0xa9>
jmp    1184 <ioctl_decode+0x64>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffff8e,%rax
sub    $0x2,%rax
jb     11c9 <ioctl_decode+0xa9>
jmp    119b <ioctl_decode+0x7b>
mov    -0x28(%rbp),%rax
sub    $0x74,%rax
jne    11e4 <ioctl_decode+0xc4>
jmp    11ae <ioctl_decode+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <term_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    11f0 <ioctl_decode+0xd0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <sock_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    11f0 <ioctl_decode+0xd0>
jmp    11e9 <ioctl_decode+0xc9>
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
add    $0xac,%al
cmp    $0x20,%al
ja     1159 <ioctl_decode+0x39>
movzbl %al,%eax
mov    $0xd0200000,%ecx
bt     %rax,%rcx
jae    1142 <ioctl_decode+0x22>
xor    %eax,%eax
jmp    1030 <sock_ioctl@plt>
movabs $0x100040001,%rcx
bt     %rax,%rcx
jae    1159 <ioctl_decode+0x39>
xor    %eax,%eax
jmp    1040 <term_ioctl@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.tcb = type opaque
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 %21 [
i64 102, label %11
i64 116, label %11
i64 84, label %11
i64 114, label %16
i64 115, label %16
i64 105, label %16
i64 112, label %16
]
11: ; preds = %3, %3, %3
%12 = load %struct.tcb*, %struct.tcb** %5
%13 = load i64, i64* %6
%14 = load i64, i64* %7
%15 = call i32 (%struct.tcb*, i64, i64, ...) bitcast (i32 (...)* @term_ioctl to i32 (%struct.tcb*, i64, i64, ...)*)(%struct.tcb* %12, i64 %13, i64 %14)
store i32 %15, i32* %4
br label %23
16: ; preds = %3, %3, %3, %3
%17 = load %struct.tcb*, %struct.tcb** %5
%18 = load i64, i64* %6
%19 = load i64, i64* %7
%20 = call i32 (%struct.tcb*, i64, i64, ...) bitcast (i32 (...)* @sock_ioctl to i32 (%struct.tcb*, i64, i64, ...)*)(%struct.tcb* %17, i64 %18, i64 %19)
store i32 %20, i32* %4
br label %23
21: ; preds = %3
br label %22
22: ; preds = %21
store i32 0, i32* %4
br label %23
23: ; preds = %22, %16, %11
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
%struct.tcb = type opaque
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 %10 [
i8 102, label %6
i8 116, label %6
i8 84, label %6
i8 114, label %8
i8 115, label %8
i8 105, label %8
i8 112, label %8
]
6: ; preds = %3, %3, %3
%7 = tail call i32 (%struct.tcb*, i64, i64, ...) bitcast (i32 (...)* @term_ioctl to i32 (%struct.tcb*, i64, i64, ...)*)(%struct.tcb* %0, i64 %1, i64 %2)
br label %10
8: ; preds = %3, %3, %3, %3
%9 = tail call i32 (%struct.tcb*, i64, i64, ...) bitcast (i32 (...)* @sock_ioctl to i32 (%struct.tcb*, i64, i64, ...)*)(%struct.tcb* %0, i64 %1, i64 %2)
br label %10
10: ; preds = %3, %8, %6
%11 = phi i32 [ %9, %8 ], [ %7, %6 ], [ 0, %3 ]
ret i32 %11
}