#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 *);
void set_scsi_type(char *to, const char *from, size_t len) {
  int type_num;
  char *eptr;
  char *type = "generic";
  type_num = strtoul(from, &eptr, 0);
  if (eptr != from) {
    switch (type_num) {
    case 0:
    case 0xe:
      type = "disk";
      break;
    case 1:
      type = "tape";
      break;
    case 4:
    case 7:
    case 0xf:
      type = "optical";
      break;
    case 5:
      type = "cd";
      break;
    default:
      break;
    }
  }
  util_strscpy(to, len, type);
}


x86 assembly (clang, -O0):
<set_scsi_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xf05(%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     11ce <set_scsi_type+0xae>
mov    -0x1c(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0xf,%rax
ja     11c4 <set_scsi_type+0xa4>
mov    -0x38(%rbp),%rax
lea    0xe85(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xebd(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11c9 <set_scsi_type+0xa9>
lea    0xeb2(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11c9 <set_scsi_type+0xa9>
lea    0xea7(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11c9 <set_scsi_type+0xa9>
lea    0xe9f(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11c9 <set_scsi_type+0xa9>
jmp    11c9 <set_scsi_type+0xa9>
jmp    11ce <set_scsi_type+0xae>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <util_strscpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_scsi_type>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
lea    0xeb8(%rip),%rdx
cmp    %rbx,0x8(%rsp)
je     1164 <set_scsi_type+0x44>
cmp    $0xf,%eax
ja     1164 <set_scsi_type+0x44>
cltq
lea    0xec3(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <util_strscpy@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"generic\00"
@.str.1 = [5 x i8] c"disk\00"
@.str.2 = [5 x i8] c"tape\00"
@.str.3 = [8 x i8] c"optical\00"
@.str.4 = [3 x i8] c"cd\00"
define void @set_scsi_type(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 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 %23
15: ; preds = %3
%16 = load i32, i32* %7
switch i32 %16, label %21 [
i32 0, label %17
i32 14, label %17
i32 1, label %18
i32 4, label %19
i32 7, label %19
i32 15, label %19
i32 5, label %20
]
17: ; preds = %15, %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %22
18: ; preds = %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %22
19: ; preds = %15, %15, %15
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %22
20: ; preds = %15
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %9
br label %22
21: ; preds = %15
br label %22
22: ; preds = %21, %20, %19, %18, %17
br label %23
23: ; preds = %22, %3
%24 = load i8*, i8** %4
%25 = load i64, i64* %6
%26 = load i8*, i8** %9
%27 = call i32 @util_strscpy(i8* %24, i64 %25, i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"generic\00"
@.str.1 = [5 x i8] c"disk\00"
@.str.2 = [5 x i8] c"tape\00"
@.str.3 = [8 x i8] c"optical\00"
@.str.4 = [3 x i8] c"cd\00"
@reltable.set_scsi_type = [16 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.4 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_scsi_type to i64)) to i32)]
define void @set_scsi_type(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 ne i8* %7, %1
%9 = icmp ult i32 %6, 16
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = sext i32 %6 to i64
%13 = shl i64 %12, 2
%14 = call i8* @llvm.load.relative.i64(i8* bitcast ([16 x i32]* @reltable.set_scsi_type to i8*), i64 %13)
br label %15
15: ; preds = %11, %3
%16 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %3 ], [ %14, %11 ]
%17 = tail call i32 @util_strscpy(i8* %0, i64 %2, i8* %16)
ret void
}