#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 const *, int);
void sg_get_scsi_status_str(int scsi_status, int buff_len, char *buff) {
  const char *ccp;
  scsi_status &= 0x7e;
  switch (scsi_status) {
  case 0:
    ccp = "Good";
    break;
  case 0x2:
    ccp = "Check Condition";
    break;
  case 0x4:
    ccp = "Condition Met";
    break;
  case 0x8:
    ccp = "Busy";
    break;
  case 0x10:
    ccp = "Intermediate";
    break;
  case 0x14:
    ccp = "Intermediate-Condition Met";
    break;
  case 0x18:
    ccp = "Reservation Conflict";
    break;
  case 0x22:
    ccp = "Command Terminated (obsolete)";
    break;
  case 0x28:
    ccp = "Task set Full";
    break;
  case 0x30:
    ccp = "ACA Active";
    break;
  case 0x40:
    ccp = "Task Aborted";
    break;
  default:
    ccp = "Unknown status";
    break;
  }
  strncpy(buff, ccp, buff_len);
}


x86 assembly (clang, -O0):
<sg_get_scsi_status_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7e,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x40,%rax
ja     1200 <sg_get_scsi_status_str+0xf0>
mov    -0x20(%rbp),%rax
lea    0xeb9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xfad(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xfa2(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xfc1(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xf92(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xf87(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xf84(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xf8f(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xf94(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xfa2(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xfa0(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xf9b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    120b <sg_get_scsi_status_str+0xfb>
lea    0xf98(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sg_get_scsi_status_str>:
mov    %rdx,%rax
mov    %esi,%edx
and    $0x7e,%edi
cmp    $0x40,%edi
ja     1143 <sg_get_scsi_status_str+0x33>
lea    0xfe0(%rip),%rsi
lea    0xed5(%rip),%rcx
movslq (%rcx,%rdi,4),%rdi
add    %rcx,%rdi
jmp    *%rdi
lea    0xfce(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0x1055(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfdf(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfb1(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfa7(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfa5(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfb1(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfb7(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfc6(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfc5(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>
lea    0xfc1(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"Good\00"
@.str.1 = [16 x i8] c"Check Condition\00"
@.str.2 = [14 x i8] c"Condition Met\00"
@.str.3 = [5 x i8] c"Busy\00"
@.str.4 = [13 x i8] c"Intermediate\00"
@.str.5 = [27 x i8] c"Intermediate-Condition Met\00"
@.str.6 = [21 x i8] c"Reservation Conflict\00"
@.str.7 = [30 x i8] c"Command Terminated (obsolete)\00"
@.str.8 = [14 x i8] c"Task set Full\00"
@.str.9 = [11 x i8] c"ACA Active\00"
@.str.10 = [13 x i8] c"Task Aborted\00"
@.str.11 = [15 x i8] c"Unknown status\00"
define void @sg_get_scsi_status_str(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = and i32 %8, 126
store i32 %9, i32* %4
%10 = load i32, i32* %4
switch i32 %10, label %22 [
i32 0, label %11
i32 2, label %12
i32 4, label %13
i32 8, label %14
i32 16, label %15
i32 20, label %16
i32 24, label %17
i32 34, label %18
i32 40, label %19
i32 48, label %20
i32 64, label %21
]
11: ; preds = %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
br label %23
12: ; preds = %3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %23
13: ; preds = %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %23
14: ; preds = %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %23
15: ; preds = %3
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %23
16: ; preds = %3
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %23
17: ; preds = %3
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %23
18: ; preds = %3
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %23
19: ; preds = %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %7
br label %23
20: ; preds = %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8** %7
br label %23
21: ; preds = %3
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8** %7
br label %23
22: ; preds = %3
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8** %7
br label %23
23: ; preds = %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11
%24 = load i8*, i8** %6
%25 = load i8*, i8** %7
%26 = load i32, i32* %5
%27 = call i32 @strncpy(i8* %24, i8* %25, i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"Good\00"
@.str.1 = [16 x i8] c"Check Condition\00"
@.str.2 = [14 x i8] c"Condition Met\00"
@.str.3 = [5 x i8] c"Busy\00"
@.str.4 = [13 x i8] c"Intermediate\00"
@.str.5 = [27 x i8] c"Intermediate-Condition Met\00"
@.str.6 = [21 x i8] c"Reservation Conflict\00"
@.str.7 = [30 x i8] c"Command Terminated (obsolete)\00"
@.str.8 = [14 x i8] c"Task set Full\00"
@.str.9 = [11 x i8] c"ACA Active\00"
@.str.10 = [13 x i8] c"Task Aborted\00"
@.str.11 = [15 x i8] c"Unknown status\00"
define void @sg_get_scsi_status_str(i32 %0, i32 %1, i8* %2) {
%4 = and i32 %0, 126
switch i32 %4, label %15 [
i32 0, label %16
i32 2, label %5
i32 4, label %6
i32 8, label %7
i32 16, label %8
i32 20, label %9
i32 24, label %10
i32 34, label %11
i32 40, label %12
i32 48, label %13
i32 64, label %14
]
5: ; preds = %3
br label %16
6: ; preds = %3
br label %16
7: ; preds = %3
br label %16
8: ; preds = %3
br label %16
9: ; preds = %3
br label %16
10: ; preds = %3
br label %16
11: ; preds = %3
br label %16
12: ; preds = %3
br label %16
13: ; preds = %3
br label %16
14: ; preds = %3
br label %16
15: ; preds = %3
br label %16
16: ; preds = %3, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%17 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), %15 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), %14 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), %13 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %12 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), %11 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), %10 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %8 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %3 ]
%18 = tail call i32 @strncpy(i8* %2, i8* %17, i32 %1)
ret void
}