#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*/ my_snprintf(char *, int, char *, char const *);
void sg_get_scsi_status_str(int scsi_status, int buff_len, char *buff) {
  const char *ccp;
  if ((NULL == buff) || (buff_len < 1))
    return;
  else if (1 == buff_len) {
    buff[0] = '\0';
    return;
  }
  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 (obsolete)";
    break;
  case 0x14:
    ccp = "Intermediate-Condition Met (obs)";
    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;
  }
  my_snprintf(buff, buff_len, "%s", ccp);
}


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)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1138 <sg_get_scsi_status_str+0x28>
cmpl   $0x1,-0x8(%rbp)
jge    113d <sg_get_scsi_status_str+0x2d>
jmp    125c <sg_get_scsi_status_str+0x14c>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    1157 <sg_get_scsi_status_str+0x47>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    125c <sg_get_scsi_status_str+0x14c>
jmp    115c <sg_get_scsi_status_str+0x4c>
mov    -0x4(%rbp),%eax
and    $0x7e,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x40,%rax
ja     123a <sg_get_scsi_status_str+0x12a>
mov    -0x20(%rbp),%rax
lea    0xe7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf73(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf68(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf68(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf66(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf5b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf63(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf74(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf79(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf87(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf85(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf80(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <sg_get_scsi_status_str+0x135>
lea    0xf7d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xf76(%rip),%rdx
call   1030 <my_snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sg_get_scsi_status_str>:
test   %esi,%esi
jle    1121 <sg_get_scsi_status_str+0x11>
test   %rdx,%rdx
je     1121 <sg_get_scsi_status_str+0x11>
cmp    $0x1,%esi
jne    1122 <sg_get_scsi_status_str+0x12>
movb   $0x0,(%rdx)
ret
and    $0x7e,%edi
cmp    $0x40,%edi
ja     114a <sg_get_scsi_status_str+0x3a>
lea    0xfd3(%rip),%rcx
lea    0xec8(%rip),%rax
movslq (%rax,%rdi,4),%rdi
add    %rax,%rdi
jmp    *%rdi
lea    0xfc1(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0x106d(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0xfbf(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0xfc4(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0xfc0(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0xfcf(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0xfe7(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0xff3(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0x1008(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0x100d(%rip),%rcx
jmp    11a2 <sg_get_scsi_status_str+0x92>
lea    0x100f(%rip),%rcx
lea    0x1024(%rip),%rax
mov    %rdx,%rdi
mov    %rax,%rdx
jmp    1030 <my_snprintf@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 = [24 x i8] c"Intermediate (obsolete)\00"
@.str.5 = [33 x i8] c"Intermediate-Condition Met (obs)\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"
@.str.12 = [3 x i8] c"%s\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 i8*, i8** %6
%9 = icmp eq i8* null, %8
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %10, %3
br label %42
14: ; preds = %10
%15 = load i32, i32* %5
%16 = icmp eq i32 1, %15
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 0, i8* %19
br label %42
20: ; preds = %14
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = and i32 %22, 126
store i32 %23, i32* %4
%24 = load i32, i32* %4
switch i32 %24, label %36 [
i32 0, label %25
i32 2, label %26
i32 4, label %27
i32 8, label %28
i32 16, label %29
i32 20, label %30
i32 24, label %31
i32 34, label %32
i32 40, label %33
i32 48, label %34
i32 64, label %35
]
25: ; preds = %21
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
br label %37
26: ; preds = %21
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %37
27: ; preds = %21
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %37
28: ; preds = %21
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %37
29: ; preds = %21
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %37
30: ; preds = %21
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %37
31: ; preds = %21
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %37
32: ; preds = %21
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %37
33: ; preds = %21
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %7
br label %37
34: ; preds = %21
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8** %7
br label %37
35: ; preds = %21
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8** %7
br label %37
36: ; preds = %21
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8** %7
br label %37
37: ; preds = %36, %35, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25
%38 = load i8*, i8** %6
%39 = load i32, i32* %5
%40 = load i8*, i8** %7
%41 = call i32 @my_snprintf(i8* %38, i32 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %37, %17, %13
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 = [24 x i8] c"Intermediate (obsolete)\00"
@.str.5 = [33 x i8] c"Intermediate-Condition Met (obs)\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"
@.str.12 = [3 x i8] c"%s\00"
define void @sg_get_scsi_status_str(i32 %0, i32 %1, i8* %2) {
%4 = icmp eq i8* %2, null
%5 = icmp slt i32 %1, 1
%6 = or i1 %5, %4
br i1 %6, label %26, label %7
7: ; preds = %3
%8 = icmp eq i32 %1, 1
br i1 %8, label %9, label %10
9: ; preds = %7
store i8 0, i8* %2
br label %26
10: ; preds = %7
%11 = and i32 %0, 126
switch i32 %11, label %22 [
i32 0, label %23
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
]
12: ; preds = %10
br label %23
13: ; preds = %10
br label %23
14: ; preds = %10
br label %23
15: ; preds = %10
br label %23
16: ; preds = %10
br label %23
17: ; preds = %10
br label %23
18: ; preds = %10
br label %23
19: ; preds = %10
br label %23
20: ; preds = %10
br label %23
21: ; preds = %10
br label %23
22: ; preds = %10
br label %23
23: ; preds = %10, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12
%24 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), %22 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), %21 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), %20 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %19 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), %18 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), %17 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), %16 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %14 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %10 ]
%25 = tail call i32 @my_snprintf(i8* %2, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %3, %23, %9
ret void
}