#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 strtoul(char const *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ util_strscpy(char *, size_t, char *);
int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len) {
  int type_num = 0;
  char *eptr;
  char *type = "generic";
  type_num = strtoul(from, &eptr, 0);
  if (eptr != from) {
    switch (type_num) {
    case 2:
      type = "atapi";
      break;
    case 3:
      type = "tape";
      break;
    case 4:
    case 5:
      type = "floppy";
      break;
    case 1:
      type = "rbc";
      break;
    case 6:
      type = "scsi";
      break;
    default:
      break;
    }
  }
  util_strscpy(to, len, type);
  return type_num;
}


x86 assembly (clang, -O0):
<set_usb_mass_storage_ifsubtype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xed6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11e9 <set_usb_mass_storage_ifsubtype+0xc9>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x5,%eax
ja     11df <set_usb_mass_storage_ifsubtype+0xbf>
mov    -0x38(%rbp),%rax
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe8a(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11e4 <set_usb_mass_storage_ifsubtype+0xc4>
lea    0xe80(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11e4 <set_usb_mass_storage_ifsubtype+0xc4>
lea    0xe75(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11e4 <set_usb_mass_storage_ifsubtype+0xc4>
lea    0xe6c(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11e4 <set_usb_mass_storage_ifsubtype+0xc4>
lea    0xe60(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11e4 <set_usb_mass_storage_ifsubtype+0xc4>
jmp    11e4 <set_usb_mass_storage_ifsubtype+0xc4>
jmp    11e9 <set_usb_mass_storage_ifsubtype+0xc9>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <util_strscpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_usb_mass_storage_ifsubtype>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,%ebp
lea    0xeba(%rip),%rdx
cmp    %rbx,(%rsp)
je     1164 <set_usb_mass_storage_ifsubtype+0x44>
add    $0xffffffff,%eax
cmp    $0x5,%eax
ja     1164 <set_usb_mass_storage_ifsubtype+0x44>
cltq
lea    0xec7(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <util_strscpy@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"generic\00"
@.str.1 = [6 x i8] c"atapi\00"
@.str.2 = [5 x i8] c"tape\00"
@.str.3 = [7 x i8] c"floppy\00"
@.str.4 = [4 x i8] c"rbc\00"
@.str.5 = [5 x i8] c"scsi\00"
define i32 @set_usb_mass_storage_ifsubtype(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %5
%11 = call i32 @strtoul(i8* %10, i8** %8, i32 0)
store i32 %11, i32* %7
%12 = load i8*, i8** %8
%13 = load i8*, i8** %5
%14 = icmp ne i8* %12, %13
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = load i32, i32* %7
switch i32 %16, label %22 [
i32 2, label %17
i32 3, label %18
i32 4, label %19
i32 5, label %19
i32 1, label %20
i32 6, label %21
]
17: ; preds = %15
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %23
18: ; preds = %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %23
19: ; preds = %15, %15
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %23
20: ; preds = %15
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %9
br label %23
21: ; preds = %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %9
br label %23
22: ; preds = %15
br label %23
23: ; preds = %22, %21, %20, %19, %18, %17
br label %24
24: ; preds = %23, %3
%25 = load i8*, i8** %4
%26 = load i64, i64* %6
%27 = load i8*, i8** %9
%28 = call i32 @util_strscpy(i8* %25, i64 %26, i8* %27)
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
@.str = [8 x i8] c"generic\00"
@.str.1 = [6 x i8] c"atapi\00"
@.str.2 = [5 x i8] c"tape\00"
@.str.3 = [7 x i8] c"floppy\00"
@.str.4 = [4 x i8] c"rbc\00"
@.str.5 = [5 x i8] c"scsi\00"
@reltable.set_usb_mass_storage_ifsubtype = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.set_usb_mass_storage_ifsubtype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.set_usb_mass_storage_ifsubtype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.set_usb_mass_storage_ifsubtype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.set_usb_mass_storage_ifsubtype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.set_usb_mass_storage_ifsubtype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.set_usb_mass_storage_ifsubtype to i64)) to i32)]
define i32 @set_usb_mass_storage_ifsubtype(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @strtoul(i8* %1, i8** %4, i32 0)
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, %1
br i1 %8, label %16, label %9
9: ; preds = %3
%10 = add i32 %6, -1
%11 = icmp ult i32 %10, 6
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = sext i32 %10 to i64
%14 = shl i64 %13, 2
%15 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.set_usb_mass_storage_ifsubtype to i8*), i64 %14)
br label %16
16: ; preds = %12, %9, %3
%17 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %3 ], [ %15, %12 ]
%18 = tail call i32 @util_strscpy(i8* %0, i64 %2, i8* %17)
ret i32 %6
}