#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 */
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ b;

/* Variables and functions */
int /*<<< orphan*/ dStrHex(char const *, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
char *sg_get_asc_ascq_str(int, int, int, char *);
scalar_t__ sg_get_sense_progress_fld(unsigned char *, int, int *);
int sg_ll_request_sense(int, int /*<<< orphan*/, unsigned char *, int, int,
                        int);
int /*<<< orphan*/ sg_print_sense(int /*<<< orphan*/ *, unsigned char *, int,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int do_cmd_sense(int sg_fd, int hex, int quiet, int verbose) {
  int res, resp_len, sk, asc, ascq, progress, pr, rem, something;
  unsigned char buff[32];
  char b[128];
  memset(buff, 0, sizeof(buff));
  res = sg_ll_request_sense(sg_fd, 0, buff, sizeof(buff), 1, verbose);
  if (0 == res) {
    resp_len = buff[7] + 8;
    if (resp_len > (int)sizeof(buff))
      resp_len = sizeof(buff);
    sk = (0xf & buff[2]);
    if (hex) {
      dStrHex((const char *)buff, resp_len, 1);
      return 0;
    }
    something = 0;
    if (verbose) {
      fprintf(stderr, "Decode response as sense data:\n");
      sg_print_sense(NULL, buff, resp_len, 0);
      if (verbose > 1) {
        fprintf(stderr, "\nOutput response in hex\n");
        dStrHex((const char *)buff, resp_len, 1);
      }
      something = 1;
    }
    asc = (resp_len > 12) ? buff[12] : 0;
    ascq = (resp_len > 13) ? buff[13] : 0;
    if (sg_get_sense_progress_fld(buff, resp_len, &progress)) {
      pr = (progress * 100) / 65536;
      rem = ((progress * 100) % 65536) / 656;
      printf("Operation in progress: %d.%d%% done\n", pr, rem);
      something = 1;
    }
    if (0 == sk) {
      if ((0xb == asc) || (0x5d == asc))
        printf("%s\n", sg_get_asc_ascq_str(asc, ascq, (int)sizeof(b), b));
      if (0x5e == asc)
        printf("%s\n", sg_get_asc_ascq_str(asc, ascq, (int)sizeof(b), b));
      return 0;
    } else {
      if (!(something || verbose || quiet)) {
        fprintf(stderr, "Decode response as sense data:\n");
        sg_print_sense(NULL, buff, resp_len, 0);
      }
      return 0;
    }
  } else if (9 == res)
    fprintf(stderr, "Request Sense command not supported\n");
  else if (5 == res)
    fprintf(stderr, "bad field in Request Sense cdb\n");
  else if (2 == res)
    fprintf(stderr, "Request Sense failed, device not ready\n");
  else if (11 == res)
    fprintf(stderr, "Request Sense failed, aborted command\n");
  else {
    fprintf(stderr, "Request Sense command failed\n");
    if (0 == verbose)
      fprintf(stderr, "    try the '-v' option for "
                      "more information\n");
  }
  return res;
}


x86 assembly (clang, -O0):
<do_cmd_sense>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x60(%rbp),%rdx
mov    -0x14(%rbp),%r9d
xor    %esi,%esi
mov    $0x20,%ecx
mov    $0x1,%r8d
call   10a0 <sg_ll_request_sense@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    142a <do_cmd_sense+0x2aa>
movzbl -0x59(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jle    11ed <do_cmd_sense+0x6d>
movl   $0x20,-0x1c(%rbp)
movzbl -0x5e(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     121e <do_cmd_sense+0x9e>
lea    -0x60(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <do_cmd_sense+0x39e>
movl   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     128d <do_cmd_sense+0x10d>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x60(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
xor    %ecx,%ecx
call   1050 <sg_print_sense@plt>
cmpl   $0x1,-0x14(%rbp)
jle    1286 <do_cmd_sense+0x106>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
movl   $0x1,-0x38(%rbp)
cmpl   $0xc,-0x1c(%rbp)
jle    12a6 <do_cmd_sense+0x126>
movzbl -0x54(%rbp),%eax
mov    %eax,-0xe4(%rbp)
jmp    12b3 <do_cmd_sense+0x133>
xor    %eax,%eax
mov    %eax,-0xe4(%rbp)
jmp    12b3 <do_cmd_sense+0x133>
mov    -0xe4(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xd,-0x1c(%rbp)
jle    12d5 <do_cmd_sense+0x155>
movzbl -0x53(%rbp),%eax
mov    %eax,-0xe8(%rbp)
jmp    12e2 <do_cmd_sense+0x162>
xor    %eax,%eax
mov    %eax,-0xe8(%rbp)
jmp    12e2 <do_cmd_sense+0x162>
mov    -0xe8(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x2c(%rbp),%rdx
call   1080 <sg_get_sense_progress_fld@plt>
cmp    $0x0,%rax
je     1348 <do_cmd_sense+0x1c8>
imul   $0x64,-0x2c(%rbp),%eax
mov    $0x10000,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
imul   $0x64,-0x2c(%rbp),%eax
mov    $0x10000,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x290,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jne    13d9 <do_cmd_sense+0x259>
mov    $0xb,%eax
cmp    -0x24(%rbp),%eax
je     136f <do_cmd_sense+0x1ef>
mov    $0x5d,%eax
cmp    -0x24(%rbp),%eax
jne    1397 <do_cmd_sense+0x217>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
lea    -0xe0(%rbp),%rcx
mov    $0x80,%edx
call   1090 <sg_get_asc_ascq_str@plt>
mov    %rax,%rsi
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5e,%eax
cmp    -0x24(%rbp),%eax
jne    13cd <do_cmd_sense+0x24d>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
lea    -0xe0(%rbp),%rcx
mov    $0x80,%edx
call   1090 <sg_get_asc_ascq_str@plt>
mov    %rax,%rsi
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <do_cmd_sense+0x39e>
cmpl   $0x0,-0x38(%rbp)
jne    141e <do_cmd_sense+0x29e>
cmpl   $0x0,-0x14(%rbp)
jne    141e <do_cmd_sense+0x29e>
cmpl   $0x0,-0x10(%rbp)
jne    141e <do_cmd_sense+0x29e>
mov    0x2be2(%rip),%rax
mov    (%rax),%edi
lea    0xbf9(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x60(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
xor    %ecx,%ecx
call   1050 <sg_print_sense@plt>
movl   $0x0,-0x4(%rbp)
jmp    151e <do_cmd_sense+0x39e>
mov    $0x9,%eax
cmp    -0x18(%rbp),%eax
jne    1452 <do_cmd_sense+0x2d2>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
lea    0xc1a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1513 <do_cmd_sense+0x393>
mov    $0x5,%eax
cmp    -0x18(%rbp),%eax
jne    147a <do_cmd_sense+0x2fa>
mov    0x2b79(%rip),%rax
mov    (%rax),%edi
lea    0xc17(%rip),%rsi
call   1070 <fprintf@plt>
jmp    150e <do_cmd_sense+0x38e>
mov    $0x2,%eax
cmp    -0x18(%rbp),%eax
jne    14a2 <do_cmd_sense+0x322>
mov    0x2b51(%rip),%rax
mov    (%rax),%edi
lea    0xc0f(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1509 <do_cmd_sense+0x389>
mov    $0xb,%eax
cmp    -0x18(%rbp),%eax
jne    14ca <do_cmd_sense+0x34a>
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
lea    0xc0f(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1504 <do_cmd_sense+0x384>
mov    0x2b0f(%rip),%rax
mov    (%rax),%edi
lea    0xc1c(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    14ff <do_cmd_sense+0x37f>
mov    0x2aef(%rip),%rax
mov    (%rax),%edi
lea    0xc1a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1504 <do_cmd_sense+0x384>
jmp    1509 <do_cmd_sense+0x389>
jmp    150e <do_cmd_sense+0x38e>
jmp    1513 <do_cmd_sense+0x393>
jmp    1518 <do_cmd_sense+0x398>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_cmd_sense>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %esi,%r13d
mov    %edi,%ebx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    %rbp,%rdx
mov    $0x20,%ecx
mov    $0x1,%r8d
mov    %r12d,%r9d
call   10b0 <sg_ll_request_sense@plt>
mov    %eax,%ebx
cmp    $0xb,%eax
ja     1220 <do_cmd_sense+0x90>
mov    %ebx,%eax
lea    0xe16(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movzbl 0x17(%rsp),%eax
cmp    $0x18,%eax
mov    $0x18,%ebp
cmovb  %eax,%ebp
lea    0x8(%rbp),%esi
test   %r13d,%r13d
je     12a6 <do_cmd_sense+0x116>
lea    0x10(%rsp),%rdi
mov    $0x1,%edx
call   1040 <dStrHex@plt>
jmp    1292 <do_cmd_sense+0x102>
mov    0x2db9(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xef1(%rip),%rsi
call   1080 <fprintf@plt>
test   %r12d,%r12d
jne    1292 <do_cmd_sense+0x102>
mov    0x0(%rbp),%edi
lea    0xefb(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1080 <fprintf@plt>
mov    %ebx,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x12(%rsp),%al
mov    %al,0x7(%rsp)
xor    %eax,%eax
mov    $0x0,%r15d
test   %r12d,%r12d
mov    %esi,0x8(%rsp)
je     1329 <do_cmd_sense+0x199>
mov    0x2d1a(%rip),%r13
mov    0x0(%r13),%edi
lea    0xd5f(%rip),%rsi
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    0x8(%rsp),%edx
xor    %ecx,%ecx
call   1060 <sg_print_sense@plt>
xor    %eax,%eax
mov    0x8(%rsp),%esi
mov    $0x1,%r15d
cmp    $0x2,%r12d
jl     1329 <do_cmd_sense+0x199>
mov    0x0(%r13),%edi
lea    0xd4b(%rip),%rsi
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%r15d
mov    0x8(%rsp),%esi
mov    $0x1,%edx
call   1040 <dStrHex@plt>
xor    %eax,%eax
mov    0x8(%rsp),%esi
cmp    $0x5,%ebp
movzbl 0x1c(%rsp),%r13d
cmovb  %eax,%r13d
movzbl 0x1d(%rsp),%ebp
cmovbe %eax,%ebp
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1090 <sg_get_sense_progress_fld@plt>
test   %rax,%rax
je     1399 <do_cmd_sense+0x209>
imul   $0x64,0xc(%rsp),%eax
lea    0xffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    %ecx,%esi
sar    $0x10,%esi
and    $0xffff0000,%ecx
sub    %ecx,%eax
cltq
imul   $0x63e7063f,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x28,%rdx
add    %eax,%edx
lea    0xcdd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
testb  $0xf,0x7(%rsp)
je     13d8 <do_cmd_sense+0x248>
or     %r14d,%r12d
or     %r15d,%r12d
jne    1292 <do_cmd_sense+0x102>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xc74(%rip),%rsi
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    0x8(%rsp),%edx
xor    %ecx,%ecx
call   1060 <sg_print_sense@plt>
jmp    1292 <do_cmd_sense+0x102>
cmp    $0xb,%r13b
je     13ee <do_cmd_sense+0x25e>
cmp    $0x5e,%r13b
je     13f8 <do_cmd_sense+0x268>
cmp    $0x5d,%r13b
jne    1292 <do_cmd_sense+0x102>
lea    0x30(%rsp),%rcx
mov    %r13d,%edi
jmp    1402 <do_cmd_sense+0x272>
lea    0x30(%rsp),%rcx
mov    $0x5e,%edi
mov    %ebp,%esi
mov    $0x80,%edx
call   10a0 <sg_get_asc_ascq_str@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
jmp    1292 <do_cmd_sense+0x102>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Decode response as sense data:\0A\00"
@.str.1 = [25 x i8] c"\0AOutput response in hex\0A\00"
@.str.2 = [37 x i8] c"Operation in progress: %d.%d%% done\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [37 x i8] c"Request Sense command not supported\0A\00"
@.str.5 = [32 x i8] c"bad field in Request Sense cdb\0A\00"
@.str.6 = [40 x i8] c"Request Sense failed, device not ready\0A\00"
@.str.7 = [39 x i8] c"Request Sense failed, aborted command\0A\00"
@.str.8 = [30 x i8] c"Request Sense command failed\0A\00"
@.str.9 = [46 x i8] c" try the '-v' option for more information\0A\00"
define i32 @do_cmd_sense(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca [32 x i8]
%20 = alloca [128 x i8]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 32)
%23 = load i32, i32* %6
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%25 = load i32, i32* %9
%26 = call i32 @sg_ll_request_sense(i32 %23, i32 0, i8* %24, i32 32, i32 1, i32 %25)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = icmp eq i32 0, %27
br i1 %28, label %29, label %141
29: ; preds = %4
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 7
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = add nsw i32 %32, 8
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = icmp sgt i32 %34, 32
br i1 %35, label %36, label %37
36: ; preds = %29
store i32 32, i32* %11
br label %37
37: ; preds = %36, %29
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 2
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = and i32 15, %40
store i32 %41, i32* %12
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %37
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%46 = load i32, i32* %11
%47 = call i32 @dStrHex(i8* %45, i32 %46, i32 1)
store i32 0, i32* %5
br label %180
48: ; preds = %37
store i32 0, i32* %18
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %66
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%55 = load i32, i32* %11
%56 = call i32 @sg_print_sense(i32* null, i8* %54, i32 %55, i32 0)
%57 = load i32, i32* %9
%58 = icmp sgt i32 %57, 1
br i1 %58, label %59, label %65
59: ; preds = %51
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%63 = load i32, i32* %11
%64 = call i32 @dStrHex(i8* %62, i32 %63, i32 1)
br label %65
65: ; preds = %59, %51
store i32 1, i32* %18
br label %66
66: ; preds = %65, %48
%67 = load i32, i32* %11
%68 = icmp sgt i32 %67, 12
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 12
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
br label %74
73: ; preds = %66
br label %74
74: ; preds = %73, %69
%75 = phi i32 [ %72, %69 ], [ 0, %73 ]
store i32 %75, i32* %13
%76 = load i32, i32* %11
%77 = icmp sgt i32 %76, 13
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 13
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
br label %83
82: ; preds = %74
br label %83
83: ; preds = %82, %78
%84 = phi i32 [ %81, %78 ], [ 0, %82 ]
store i32 %84, i32* %14
%85 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%86 = load i32, i32* %11
%87 = call i64 @sg_get_sense_progress_fld(i8* %85, i32 %86, i32* %15)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %100
89: ; preds = %83
%90 = load i32, i32* %15
%91 = mul nsw i32 %90, 100
%92 = sdiv i32 %91, 65536
store i32 %92, i32* %16
%93 = load i32, i32* %15
%94 = mul nsw i32 %93, 100
%95 = srem i32 %94, 65536
%96 = sdiv i32 %95, 656
store i32 %96, i32* %17
%97 = load i32, i32* %16
%98 = load i32, i32* %17
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %97, i32 %98)
store i32 1, i32* %18
br label %100
100: ; preds = %89, %83
%101 = load i32, i32* %12
%102 = icmp eq i32 0, %101
br i1 %102, label %103, label %125
103: ; preds = %100
%104 = load i32, i32* %13
%105 = icmp eq i32 11, %104
br i1 %105, label %109, label %106
106: ; preds = %103
%107 = load i32, i32* %13
%108 = icmp eq i32 93, %107
br i1 %108, label %109, label %115
109: ; preds = %106, %103
%110 = load i32, i32* %13
%111 = load i32, i32* %14
%112 = getelementptr inbounds [128 x i8], [128 x i8]* %20, i64 0, i64 0
%113 = call i8* @sg_get_asc_ascq_str(i32 %110, i32 %111, i32 128, i8* %112)
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %113)
br label %115
115: ; preds = %109, %106
%116 = load i32, i32* %13
%117 = icmp eq i32 94, %116
br i1 %117, label %118, label %124
118: ; preds = %115
%119 = load i32, i32* %13
%120 = load i32, i32* %14
%121 = getelementptr inbounds [128 x i8], [128 x i8]* %20, i64 0, i64 0
%122 = call i8* @sg_get_asc_ascq_str(i32 %119, i32 %120, i32 128, i8* %121)
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %122)
br label %124
124: ; preds = %118, %115
store i32 0, i32* %5
br label %180
125: ; preds = %100
%126 = load i32, i32* %18
%127 = icmp ne i32 %126, 0
br i1 %127, label %140, label %128
128: ; preds = %125
%129 = load i32, i32* %9
%130 = icmp ne i32 %129, 0
br i1 %130, label %140, label %131
131: ; preds = %128
%132 = load i32, i32* %8
%133 = icmp ne i32 %132, 0
br i1 %133, label %140, label %134
134: ; preds = %131
%135 = load i32, i32* @stderr
%136 = call i32 @fprintf(i32 %135, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%137 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%138 = load i32, i32* %11
%139 = call i32 @sg_print_sense(i32* null, i8* %137, i32 %138, i32 0)
br label %140
140: ; preds = %134, %131, %128, %125
store i32 0, i32* %5
br label %180
141: ; preds = %4
%142 = load i32, i32* %10
%143 = icmp eq i32 9, %142
br i1 %143, label %144, label %147
144: ; preds = %141
%145 = load i32, i32* @stderr
%146 = call i32 @fprintf(i32 %145, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %177
147: ; preds = %141
%148 = load i32, i32* %10
%149 = icmp eq i32 5, %148
br i1 %149, label %150, label %153
150: ; preds = %147
%151 = load i32, i32* @stderr
%152 = call i32 @fprintf(i32 %151, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %176
153: ; preds = %147
%154 = load i32, i32* %10
%155 = icmp eq i32 2, %154
br i1 %155, label %156, label %159
156: ; preds = %153
%157 = load i32, i32* @stderr
%158 = call i32 @fprintf(i32 %157, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
br label %175
159: ; preds = %153
%160 = load i32, i32* %10
%161 = icmp eq i32 11, %160
br i1 %161, label %162, label %165
162: ; preds = %159
%163 = load i32, i32* @stderr
%164 = call i32 @fprintf(i32 %163, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %174
165: ; preds = %159
%166 = load i32, i32* @stderr
%167 = call i32 @fprintf(i32 %166, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%168 = load i32, i32* %9
%169 = icmp eq i32 0, %168
br i1 %169, label %170, label %173
170: ; preds = %165
%171 = load i32, i32* @stderr
%172 = call i32 @fprintf(i32 %171, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
br label %173
173: ; preds = %170, %165
br label %174
174: ; preds = %173, %162
br label %175
175: ; preds = %174, %156
br label %176
176: ; preds = %175, %150
br label %177
177: ; preds = %176, %144
br label %178
178: ; preds = %177
%179 = load i32, i32* %10
store i32 %179, i32* %5
br label %180
180: ; preds = %178, %140, %124, %44
%181 = load i32, i32* %5
ret i32 %181
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Decode response as sense data:\0A\00"
@.str.1 = [25 x i8] c"\0AOutput response in hex\0A\00"
@.str.2 = [37 x i8] c"Operation in progress: %d.%d%% done\0A\00"
@.str.4 = [37 x i8] c"Request Sense command not supported\0A\00"
@.str.5 = [32 x i8] c"bad field in Request Sense cdb\0A\00"
@.str.6 = [40 x i8] c"Request Sense failed, device not ready\0A\00"
@.str.7 = [39 x i8] c"Request Sense failed, aborted command\0A\00"
@.str.8 = [30 x i8] c"Request Sense command failed\0A\00"
@.str.9 = [46 x i8] c" try the '-v' option for more information\0A\00"
define i32 @do_cmd_sense(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca [32 x i8]
%7 = alloca [128 x i8]
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%11 = call i32 @memset(i8* %9, i32 0, i32 32)
%12 = call i32 @sg_ll_request_sense(i32 %0, i32 0, i8* %9, i32 32, i32 1, i32 %3)
switch i32 %12, label %89 [
i32 0, label %13
i32 9, label %77
i32 5, label %80
i32 2, label %83
i32 11, label %86
]
13: ; preds = %4
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 7
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp ult i32 %16, 24
%18 = select i1 %17, i32 %16, i32 24
%19 = add nuw nsw i32 %18, 8
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 2
%21 = load i8, i8* %20
%22 = and i8 %21, 15
%23 = icmp eq i32 %1, 0
br i1 %23, label %26, label %24
24: ; preds = %13
%25 = call i32 @dStrHex(i8* %9, i32 %19, i32 1)
br label %96
26: ; preds = %13
%27 = icmp eq i32 %3, 0
br i1 %27, label %37, label %28
28: ; preds = %26
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @sg_print_sense(i32* null, i8* %9, i32 %19, i32 0)
%32 = icmp sgt i32 %3, 1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @dStrHex(i8* %9, i32 %19, i32 1)
br label %37
37: ; preds = %28, %33, %26
%38 = phi i32 [ 0, %26 ], [ 1, %33 ], [ 1, %28 ]
%39 = icmp ugt i32 %18, 4
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 12
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = select i1 %39, i32 %42, i32 0
%44 = icmp ugt i32 %18, 5
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 13
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = select i1 %44, i32 %47, i32 0
%49 = call i64 @sg_get_sense_progress_fld(i8* %9, i32 %19, i32* %5)
%50 = icmp eq i64 %49, 0
br i1 %50, label %58, label %51
51: ; preds = %37
%52 = load i32, i32* %5
%53 = mul nsw i32 %52, 100
%54 = sdiv i32 %53, 65536
%55 = srem i32 %53, 65536
%56 = sdiv i32 %55, 656
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %56)
br label %58
58: ; preds = %51, %37
%59 = phi i32 [ 1, %51 ], [ %38, %37 ]
%60 = icmp eq i8 %22, 0
br i1 %60, label %61, label %69
61: ; preds = %58
%62 = trunc i32 %43 to i8
switch i8 %62, label %96 [
i8 93, label %63
i8 11, label %63
i8 94, label %66
]
63: ; preds = %61, %61
%64 = call i8* @sg_get_asc_ascq_str(i32 %43, i32 %48, i32 128, i8* %10)
%65 = call i32 @puts(i8* dereferenceable(1) %64)
br label %96
66: ; preds = %61
%67 = call i8* @sg_get_asc_ascq_str(i32 94, i32 %48, i32 128, i8* %10)
%68 = call i32 @puts(i8* dereferenceable(1) %67)
br label %96
69: ; preds = %58
%70 = or i32 %3, %2
%71 = or i32 %70, %59
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %96
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%76 = call i32 @sg_print_sense(i32* null, i8* %9, i32 %19, i32 0)
br label %96
77: ; preds = %4
%78 = load i32, i32* @stderr
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %96
80: ; preds = %4
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %96
83: ; preds = %4
%84 = load i32, i32* @stderr
%85 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
br label %96
86: ; preds = %4
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %96
89: ; preds = %4
%90 = load i32, i32* @stderr
%91 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%92 = icmp eq i32 %3, 0
br i1 %92, label %93, label %96
93: ; preds = %89
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
br label %96
96: ; preds = %63, %80, %86, %93, %89, %83, %77, %69, %73, %66, %61, %24
ret i32 %12
}