#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_type(const char *from, char *to, 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:
      type = "disk";
      break;
    case 1:
      type = "tape";
      break;
    case 4:
      type = "optical";
      break;
    case 5:
      type = "cd";
      break;
    case 7:
      type = "optical";
      break;
    case 0xe:
      type = "disk";
      break;
    case 0xf:
      type = "optical";
      break;
    default:
      break;
    }
  }
  util_strscpy(to, len, type);
}


x86 assembly (clang, -O0):
<set_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    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11fe <set_type+0xde>
mov    -0x1c(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0xf,%rax
ja     11f4 <set_type+0xd4>
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    11f9 <set_type+0xd9>
lea    0xeb2(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f9 <set_type+0xd9>
lea    0xea7(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f9 <set_type+0xd9>
lea    0xe9f(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f9 <set_type+0xd9>
lea    0xe87(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f9 <set_type+0xd9>
lea    0xe6d(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f9 <set_type+0xd9>
lea    0xe67(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f9 <set_type+0xd9>
jmp    11f9 <set_type+0xd9>
jmp    11fe <set_type+0xde>
mov    -0x10(%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_type>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
lea    0xebb(%rip),%rdx
cmp    %rbx,0x8(%rsp)
je     1161 <set_type+0x41>
cmp    $0xf,%eax
ja     1161 <set_type+0x41>
cltq
lea    0xec6(%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_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** %4
%11 = call i32 @strtoul(i8* %10, i8** %8, i32 0)
store i32 %11, i32* %7
%12 = load i8*, i8** %8
%13 = load i8*, i8** %4
%14 = icmp ne i8* %12, %13
br i1 %14, label %15, label %26
15: ; preds = %3
%16 = load i32, i32* %7
switch i32 %16, label %24 [
i32 0, label %17
i32 1, label %18
i32 4, label %19
i32 5, label %20
i32 7, label %21
i32 14, label %22
i32 15, label %23
]
17: ; preds = %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %25
18: ; preds = %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %25
19: ; preds = %15
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %25
20: ; preds = %15
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %9
br label %25
21: ; preds = %15
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %25
22: ; preds = %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %25
23: ; preds = %15
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %25
24: ; preds = %15
br label %25
25: ; preds = %24, %23, %22, %21, %20, %19, %18, %17
br label %26
26: ; preds = %25, %3
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = load i8*, i8** %9
%30 = call i32 @util_strscpy(i8* %27, i64 %28, i8* %29)
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_type = [16 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([16 x i32]* @reltable.set_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_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_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_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_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_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_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.set_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_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_type to i64)) to i32)]
define void @set_type(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @strtoul(i8* %0, i8** %4, i32 0)
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, %0
%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_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* %1, i64 %2, i8* %16)
ret void
}