#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, 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)) {
      printf("Operation in progress, %d%% done\n", progress * 100 / 65536);
      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    $0xe0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%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    140a <do_cmd_sense+0x28a>
movzbl -0x49(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jle    11ed <do_cmd_sense+0x6d>
movl   $0x20,-0x1c(%rbp)
movzbl -0x4e(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     121e <do_cmd_sense+0x9e>
lea    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
movl   $0x0,-0x4(%rbp)
jmp    14fe <do_cmd_sense+0x37e>
movl   $0x0,-0x30(%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    -0x50(%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    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
movl   $0x1,-0x30(%rbp)
cmpl   $0xc,-0x1c(%rbp)
jle    12a6 <do_cmd_sense+0x126>
movzbl -0x44(%rbp),%eax
mov    %eax,-0xd4(%rbp)
jmp    12b3 <do_cmd_sense+0x133>
xor    %eax,%eax
mov    %eax,-0xd4(%rbp)
jmp    12b3 <do_cmd_sense+0x133>
mov    -0xd4(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xd,-0x1c(%rbp)
jle    12d5 <do_cmd_sense+0x155>
movzbl -0x43(%rbp),%eax
mov    %eax,-0xd8(%rbp)
jmp    12e2 <do_cmd_sense+0x162>
xor    %eax,%eax
mov    %eax,-0xd8(%rbp)
jmp    12e2 <do_cmd_sense+0x162>
mov    -0xd8(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x2c(%rbp),%rdx
call   1080 <sg_get_sense_progress_fld@plt>
cmp    $0x0,%rax
je     1328 <do_cmd_sense+0x1a8>
imul   $0x64,-0x2c(%rbp),%eax
mov    $0x10000,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jne    13b9 <do_cmd_sense+0x239>
mov    $0xb,%eax
cmp    -0x24(%rbp),%eax
je     134f <do_cmd_sense+0x1cf>
mov    $0x5d,%eax
cmp    -0x24(%rbp),%eax
jne    1377 <do_cmd_sense+0x1f7>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
lea    -0xd0(%rbp),%rcx
mov    $0x80,%edx
call   1090 <sg_get_asc_ascq_str@plt>
mov    %rax,%rsi
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5e,%eax
cmp    -0x24(%rbp),%eax
jne    13ad <do_cmd_sense+0x22d>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
lea    -0xd0(%rbp),%rcx
mov    $0x80,%edx
call   1090 <sg_get_asc_ascq_str@plt>
mov    %rax,%rsi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14fe <do_cmd_sense+0x37e>
cmpl   $0x0,-0x30(%rbp)
jne    13fe <do_cmd_sense+0x27e>
cmpl   $0x0,-0x14(%rbp)
jne    13fe <do_cmd_sense+0x27e>
cmpl   $0x0,-0x10(%rbp)
jne    13fe <do_cmd_sense+0x27e>
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
lea    0xc19(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x50(%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    14fe <do_cmd_sense+0x37e>
mov    $0x9,%eax
cmp    -0x18(%rbp),%eax
jne    1432 <do_cmd_sense+0x2b2>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
lea    0xc37(%rip),%rsi
call   1070 <fprintf@plt>
jmp    14f3 <do_cmd_sense+0x373>
mov    $0x5,%eax
cmp    -0x18(%rbp),%eax
jne    145a <do_cmd_sense+0x2da>
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
lea    0xc34(%rip),%rsi
call   1070 <fprintf@plt>
jmp    14ee <do_cmd_sense+0x36e>
mov    $0x2,%eax
cmp    -0x18(%rbp),%eax
jne    1482 <do_cmd_sense+0x302>
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
lea    0xc2c(%rip),%rsi
call   1070 <fprintf@plt>
jmp    14e9 <do_cmd_sense+0x369>
mov    $0xb,%eax
cmp    -0x18(%rbp),%eax
jne    14aa <do_cmd_sense+0x32a>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
lea    0xc2c(%rip),%rsi
call   1070 <fprintf@plt>
jmp    14e4 <do_cmd_sense+0x364>
mov    0x2b2f(%rip),%rax
mov    (%rax),%edi
lea    0xc39(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    14df <do_cmd_sense+0x35f>
mov    0x2b0f(%rip),%rax
mov    (%rax),%edi
lea    0xc37(%rip),%rsi
call   1070 <fprintf@plt>
jmp    14e4 <do_cmd_sense+0x364>
jmp    14e9 <do_cmd_sense+0x369>
jmp    14ee <do_cmd_sense+0x36e>
jmp    14f3 <do_cmd_sense+0x373>
jmp    14f8 <do_cmd_sense+0x378>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%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    0xeee(%rip),%rsi
call   1080 <fprintf@plt>
test   %r12d,%r12d
jne    1292 <do_cmd_sense+0x102>
mov    0x0(%rbp),%edi
lea    0xef8(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
jmp    128d <do_cmd_sense+0xfd>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%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     1379 <do_cmd_sense+0x1e9>
imul   $0x64,0xc(%rsp),%eax
lea    0xffff(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0x10,%esi
lea    0xcfd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
testb  $0xf,0x7(%rsp)
je     13b8 <do_cmd_sense+0x228>
or     %r14d,%r12d
or     %r15d,%r12d
jne    1292 <do_cmd_sense+0x102>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
lea    0xc94(%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     13ce <do_cmd_sense+0x23e>
cmp    $0x5e,%r13b
je     13d8 <do_cmd_sense+0x248>
cmp    $0x5d,%r13b
jne    1292 <do_cmd_sense+0x102>
lea    0x30(%rsp),%rcx
mov    %r13d,%edi
jmp    13e2 <do_cmd_sense+0x252>
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 = [34 x i8] c"Operation in progress, %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 [32 x i8]
%18 = alloca [128 x i8]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 32)
%21 = load i32, i32* %6
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%23 = load i32, i32* %9
%24 = call i32 @sg_ll_request_sense(i32 %21, i32 0, i8* %22, i32 32, i32 1, i32 %23)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %133
27: ; preds = %4
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 7
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = add nsw i32 %30, 8
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = icmp sgt i32 %32, 32
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 32, i32* %11
br label %35
35: ; preds = %34, %27
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 2
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = and i32 15, %38
store i32 %39, i32* %12
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%44 = load i32, i32* %11
%45 = call i32 @dStrHex(i8* %43, i32 %44, i32 1)
store i32 0, i32* %5
br label %172
46: ; preds = %35
store i32 0, i32* %16
%47 = load i32, i32* %9
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %64
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%52 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%53 = load i32, i32* %11
%54 = call i32 @sg_print_sense(i32* null, i8* %52, i32 %53, i32 0)
%55 = load i32, i32* %9
%56 = icmp sgt i32 %55, 1
br i1 %56, label %57, label %63
57: ; preds = %49
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%60 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%61 = load i32, i32* %11
%62 = call i32 @dStrHex(i8* %60, i32 %61, i32 1)
br label %63
63: ; preds = %57, %49
store i32 1, i32* %16
br label %64
64: ; preds = %63, %46
%65 = load i32, i32* %11
%66 = icmp sgt i32 %65, 12
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 12
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
br label %72
71: ; preds = %64
br label %72
72: ; preds = %71, %67
%73 = phi i32 [ %70, %67 ], [ 0, %71 ]
store i32 %73, i32* %13
%74 = load i32, i32* %11
%75 = icmp sgt i32 %74, 13
br i1 %75, label %76, label %80
76: ; preds = %72
%77 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 13
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
br label %81
80: ; preds = %72
br label %81
81: ; preds = %80, %76
%82 = phi i32 [ %79, %76 ], [ 0, %80 ]
store i32 %82, i32* %14
%83 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%84 = load i32, i32* %11
%85 = call i64 @sg_get_sense_progress_fld(i8* %83, i32 %84, i32* %15)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %92
87: ; preds = %81
%88 = load i32, i32* %15
%89 = mul nsw i32 %88, 100
%90 = sdiv i32 %89, 65536
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %90)
store i32 1, i32* %16
br label %92
92: ; preds = %87, %81
%93 = load i32, i32* %12
%94 = icmp eq i32 0, %93
br i1 %94, label %95, label %117
95: ; preds = %92
%96 = load i32, i32* %13
%97 = icmp eq i32 11, %96
br i1 %97, label %101, label %98
98: ; preds = %95
%99 = load i32, i32* %13
%100 = icmp eq i32 93, %99
br i1 %100, label %101, label %107
101: ; preds = %98, %95
%102 = load i32, i32* %13
%103 = load i32, i32* %14
%104 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%105 = call i8* @sg_get_asc_ascq_str(i32 %102, i32 %103, i32 128, i8* %104)
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %105)
br label %107
107: ; preds = %101, %98
%108 = load i32, i32* %13
%109 = icmp eq i32 94, %108
br i1 %109, label %110, label %116
110: ; preds = %107
%111 = load i32, i32* %13
%112 = load i32, i32* %14
%113 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%114 = call i8* @sg_get_asc_ascq_str(i32 %111, i32 %112, i32 128, i8* %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %114)
br label %116
116: ; preds = %110, %107
store i32 0, i32* %5
br label %172
117: ; preds = %92
%118 = load i32, i32* %16
%119 = icmp ne i32 %118, 0
br i1 %119, label %132, label %120
120: ; preds = %117
%121 = load i32, i32* %9
%122 = icmp ne i32 %121, 0
br i1 %122, label %132, label %123
123: ; preds = %120
%124 = load i32, i32* %8
%125 = icmp ne i32 %124, 0
br i1 %125, label %132, label %126
126: ; preds = %123
%127 = load i32, i32* @stderr
%128 = call i32 @fprintf(i32 %127, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%129 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%130 = load i32, i32* %11
%131 = call i32 @sg_print_sense(i32* null, i8* %129, i32 %130, i32 0)
br label %132
132: ; preds = %126, %123, %120, %117
store i32 0, i32* %5
br label %172
133: ; preds = %4
%134 = load i32, i32* %10
%135 = icmp eq i32 9, %134
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = load i32, i32* @stderr
%138 = call i32 @fprintf(i32 %137, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %169
139: ; preds = %133
%140 = load i32, i32* %10
%141 = icmp eq i32 5, %140
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = load i32, i32* @stderr
%144 = call i32 @fprintf(i32 %143, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %168
145: ; preds = %139
%146 = load i32, i32* %10
%147 = icmp eq i32 2, %146
br i1 %147, label %148, label %151
148: ; preds = %145
%149 = load i32, i32* @stderr
%150 = call i32 @fprintf(i32 %149, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
br label %167
151: ; preds = %145
%152 = load i32, i32* %10
%153 = icmp eq i32 11, %152
br i1 %153, label %154, label %157
154: ; preds = %151
%155 = load i32, i32* @stderr
%156 = call i32 @fprintf(i32 %155, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %166
157: ; preds = %151
%158 = load i32, i32* @stderr
%159 = call i32 @fprintf(i32 %158, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%160 = load i32, i32* %9
%161 = icmp eq i32 0, %160
br i1 %161, label %162, label %165
162: ; preds = %157
%163 = load i32, i32* @stderr
%164 = call i32 @fprintf(i32 %163, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
br label %165
165: ; preds = %162, %157
br label %166
166: ; preds = %165, %154
br label %167
167: ; preds = %166, %148
br label %168
168: ; preds = %167, %142
br label %169
169: ; preds = %168, %136
br label %170
170: ; preds = %169
%171 = load i32, i32* %10
store i32 %171, i32* %5
br label %172
172: ; preds = %170, %132, %116, %42
%173 = load i32, i32* %5
ret i32 %173
}

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 = [34 x i8] c"Operation in progress, %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 %87 [
i32 0, label %13
i32 9, label %75
i32 5, label %78
i32 2, label %81
i32 11, label %84
]
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 %94
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 %56, label %51
51: ; preds = %37
%52 = load i32, i32* %5
%53 = mul nsw i32 %52, 100
%54 = sdiv i32 %53, 65536
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %51, %37
%57 = phi i32 [ 1, %51 ], [ %38, %37 ]
%58 = icmp eq i8 %22, 0
br i1 %58, label %59, label %67
59: ; preds = %56
%60 = trunc i32 %43 to i8
switch i8 %60, label %94 [
i8 93, label %61
i8 11, label %61
i8 94, label %64
]
61: ; preds = %59, %59
%62 = call i8* @sg_get_asc_ascq_str(i32 %43, i32 %48, i32 128, i8* %10)
%63 = call i32 @puts(i8* dereferenceable(1) %62)
br label %94
64: ; preds = %59
%65 = call i8* @sg_get_asc_ascq_str(i32 94, i32 %48, i32 128, i8* %10)
%66 = call i32 @puts(i8* dereferenceable(1) %65)
br label %94
67: ; preds = %56
%68 = or i32 %3, %2
%69 = or i32 %68, %57
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %94
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%74 = call i32 @sg_print_sense(i32* null, i8* %9, i32 %19, i32 0)
br label %94
75: ; preds = %4
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %94
78: ; preds = %4
%79 = load i32, i32* @stderr
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %94
81: ; preds = %4
%82 = load i32, i32* @stderr
%83 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
br label %94
84: ; preds = %4
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %94
87: ; preds = %4
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%90 = icmp eq i32 %3, 0
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = load i32, i32* @stderr
%93 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
br label %94
94: ; preds = %61, %78, %84, %91, %87, %81, %75, %67, %71, %64, %59, %24
ret i32 %12
}