#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*/ strncpy(char *, char *, size_t);
void set_usb_iftype(char *to, int if_class_num, size_t len) {
  char *type = "generic";
  switch (if_class_num) {
  case 1:
    type = "audio";
    break;
  case 2:
    break;
  case 3:
    type = "hid";
    break;
  case 5:
    break;
  case 6:
    type = "media";
    break;
  case 7:
    type = "printer";
    break;
  case 8:
    type = "storage";
    break;
  case 9:
    type = "hub";
    break;
  case 0x0a:
    break;
  case 0x0b:
    break;
  case 0x0d:
    break;
  case 0x0e:
    type = "video";
    break;
  case 0xdc:
    break;
  case 0xe0:
    break;
  case 0xfe:
    break;
  case 0xff:
    break;
  default:
    break;
  }
  strncpy(to, type, len);
  to[len - 1] = '\0';
}


x86 assembly (clang, -O0):
<set_usb_iftype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xed6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     1249 <set_usb_iftype+0x139>
jmp    1142 <set_usb_iftype+0x32>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     1259 <set_usb_iftype+0x149>
jmp    1153 <set_usb_iftype+0x43>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     125e <set_usb_iftype+0x14e>
jmp    1164 <set_usb_iftype+0x54>
mov    -0x24(%rbp),%eax
sub    $0x5,%eax
je     126e <set_usb_iftype+0x15e>
jmp    1175 <set_usb_iftype+0x65>
mov    -0x24(%rbp),%eax
sub    $0x6,%eax
je     1273 <set_usb_iftype+0x163>
jmp    1186 <set_usb_iftype+0x76>
mov    -0x24(%rbp),%eax
sub    $0x7,%eax
je     1283 <set_usb_iftype+0x173>
jmp    1197 <set_usb_iftype+0x87>
mov    -0x24(%rbp),%eax
sub    $0x8,%eax
je     1293 <set_usb_iftype+0x183>
jmp    11a8 <set_usb_iftype+0x98>
mov    -0x24(%rbp),%eax
sub    $0x9,%eax
je     12a3 <set_usb_iftype+0x193>
jmp    11b9 <set_usb_iftype+0xa9>
mov    -0x24(%rbp),%eax
sub    $0xa,%eax
je     12b3 <set_usb_iftype+0x1a3>
jmp    11ca <set_usb_iftype+0xba>
mov    -0x24(%rbp),%eax
sub    $0xb,%eax
je     12b8 <set_usb_iftype+0x1a8>
jmp    11db <set_usb_iftype+0xcb>
mov    -0x24(%rbp),%eax
sub    $0xd,%eax
je     12bd <set_usb_iftype+0x1ad>
jmp    11ec <set_usb_iftype+0xdc>
mov    -0x24(%rbp),%eax
sub    $0xe,%eax
je     12c2 <set_usb_iftype+0x1b2>
jmp    11fd <set_usb_iftype+0xed>
mov    -0x24(%rbp),%eax
sub    $0xdc,%eax
je     12d2 <set_usb_iftype+0x1c2>
jmp    1210 <set_usb_iftype+0x100>
mov    -0x24(%rbp),%eax
sub    $0xe0,%eax
je     12d7 <set_usb_iftype+0x1c7>
jmp    1223 <set_usb_iftype+0x113>
mov    -0x24(%rbp),%eax
sub    $0xfe,%eax
je     12dc <set_usb_iftype+0x1cc>
jmp    1236 <set_usb_iftype+0x126>
mov    -0x24(%rbp),%eax
sub    $0xff,%eax
je     12e1 <set_usb_iftype+0x1d1>
jmp    12e6 <set_usb_iftype+0x1d6>
lea    0xdb8(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
lea    0xda9(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
lea    0xd98(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12eb <set_usb_iftype+0x1db>
lea    0xd8e(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12eb <set_usb_iftype+0x1db>
lea    0xd86(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12eb <set_usb_iftype+0x1db>
lea    0xd7e(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
lea    0xd63(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
jmp    12eb <set_usb_iftype+0x1db>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_usb_iftype>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
add    $0xffffffff,%esi
cmp    $0xd,%esi
ja     1135 <set_usb_iftype+0x25>
movslq %esi,%rax
lea    0xf08(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    113c <set_usb_iftype+0x2c>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"generic\00"
@.str.1 = [6 x i8] c"audio\00"
@.str.2 = [4 x i8] c"hid\00"
@.str.3 = [6 x i8] c"media\00"
@.str.4 = [8 x i8] c"printer\00"
@.str.5 = [8 x i8] c"storage\00"
@.str.6 = [4 x i8] c"hub\00"
@.str.7 = [6 x i8] c"video\00"
define void @set_usb_iftype(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = load i32, i32* %5
switch i32 %8, label %25 [
i32 1, label %9
i32 2, label %10
i32 3, label %11
i32 5, label %12
i32 6, label %13
i32 7, label %14
i32 8, label %15
i32 9, label %16
i32 10, label %17
i32 11, label %18
i32 13, label %19
i32 14, label %20
i32 220, label %21
i32 224, label %22
i32 254, label %23
i32 255, label %24
]
9: ; preds = %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %26
10: ; preds = %3
br label %26
11: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %26
12: ; preds = %3
br label %26
13: ; preds = %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %26
14: ; preds = %3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %26
15: ; preds = %3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %26
16: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %26
17: ; preds = %3
br label %26
18: ; preds = %3
br label %26
19: ; preds = %3
br label %26
20: ; preds = %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %26
21: ; preds = %3
br label %26
22: ; preds = %3
br label %26
23: ; preds = %3
br label %26
24: ; preds = %3
br label %26
25: ; preds = %3
br label %26
26: ; preds = %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9
%27 = load i8*, i8** %4
%28 = load i8*, i8** %7
%29 = load i64, i64* %6
%30 = call i32 @strncpy(i8* %27, i8* %28, i64 %29)
%31 = load i8*, i8** %4
%32 = load i64, i64* %6
%33 = sub i64 %32, 1
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"generic\00"
@.str.1 = [6 x i8] c"audio\00"
@.str.2 = [4 x i8] c"hid\00"
@.str.3 = [6 x i8] c"media\00"
@.str.4 = [8 x i8] c"printer\00"
@.str.5 = [8 x i8] c"storage\00"
@.str.6 = [4 x i8] c"hub\00"
@.str.7 = [6 x i8] c"video\00"
@reltable.set_usb_iftype = [14 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([14 x i32]* @reltable.set_usb_iftype to i64)) to i32)]
define void @set_usb_iftype(i8* %0, i32 %1, i64 %2) {
%4 = add i32 %1, -1
%5 = icmp ult i32 %4, 14
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([14 x i32]* @reltable.set_usb_iftype to i8*), i64 %8)
br label %10
10: ; preds = %6, %3
%11 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %3 ], [ %9, %6 ]
%12 = tail call i32 @strncpy(i8* %0, i8* %11, i64 %2)
%13 = add i64 %2, -1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 0, i8* %14
ret void
}