#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ uint8_t;
struct TYPE_3__ {
  int sb_len_wr;
  scalar_t__ driver_status;
  scalar_t__ host_status;
  scalar_t__ status;
  scalar_t__ masked_status;
};
typedef TYPE_1__ sg_io_hdr_t;

/* Variables and functions */
int /*<<< orphan*/ write_debug(char *, ...);
void print_scsi_error(sg_io_hdr_t *pIo, uint8_t *sense_buffer) {
  int k;
  if (pIo->sb_len_wr > 0) {
    write_debug("SCSI error: sense data: ");
    for (k = 0; k < pIo->sb_len_wr; ++k) {
      if ((k > 0) && (0 == (k % 10)))
        write_debug("\n  ");
      write_debug("0x%02x ", sense_buffer[k]);
    }
    write_debug("\n");
  }
  if (pIo->masked_status)
    write_debug("SCSI status=0x%x\n", pIo->status);
  if (pIo->host_status)
    write_debug("host_status=0x%x\n", pIo->host_status);
  if (pIo->driver_status)
    write_debug("driver_status=0x%x\n", pIo->driver_status);
}


x86 assembly (clang, -O0):
<print_scsi_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11b4 <print_scsi_error+0xa4>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <write_debug@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    11a6 <print_scsi_error+0x96>
cmpl   $0x0,-0x14(%rbp)
jle    117e <print_scsi_error+0x6e>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    117e <print_scsi_error+0x6e>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <write_debug@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <write_debug@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <print_scsi_error+0x32>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <write_debug@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x20(%rax)
je     11d9 <print_scsi_error+0xc9>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <write_debug@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     11fe <print_scsi_error+0xee>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <write_debug@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1223 <print_scsi_error+0x113>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <write_debug@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_scsi_error>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpl   $0x0,(%rdi)
jle    11ae <print_scsi_error+0x9e>
mov    %rsi,%rbx
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <write_debug@plt>
cmpl   $0x0,(%r14)
jle    11a0 <print_scsi_error+0x90>
mov    $0xcccccccd,%r13d
lea    0xece(%rip),%r15
lea    0xecb(%rip),%r12
xor    %ebp,%ebp
jmp    117a <print_scsi_error+0x6a>
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <write_debug@plt>
add    $0x1,%rbp
movslq (%r14),%rax
cmp    %rax,%rbp
jge    11a0 <print_scsi_error+0x90>
test   %rbp,%rbp
je     1160 <print_scsi_error+0x50>
mov    %ebp,%eax
imul   %r13,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%ecx
sub    %eax,%ecx
jne    1160 <print_scsi_error+0x50>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <write_debug@plt>
jmp    1160 <print_scsi_error+0x50>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1030 <write_debug@plt>
cmpq   $0x0,0x20(%r14)
je     11c7 <print_scsi_error+0xb7>
mov    0x18(%r14),%rsi
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1030 <write_debug@plt>
mov    0x10(%r14),%rsi
test   %rsi,%rsi
je     11de <print_scsi_error+0xce>
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1030 <write_debug@plt>
mov    0x8(%r14),%rsi
test   %rsi,%rsi
je     1203 <print_scsi_error+0xf3>
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <write_debug@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64, i64, i64, i64 }
@.str = [25 x i8] c"SCSI error: sense data: \00"
@.str.1 = [4 x i8] c"\0A \00"
@.str.2 = [8 x i8] c"0x%02x \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [18 x i8] c"SCSI status=0x%x\0A\00"
@.str.5 = [18 x i8] c"host_status=0x%x\0A\00"
@.str.6 = [20 x i8] c"driver_status=0x%x\0A\00"
define void @print_scsi_error(%struct.TYPE_3__* %0, i64* %1) {
%3 = alloca %struct.TYPE_3__*
%4 = alloca i64*
%5 = alloca i32
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %3
store i64* %1, i64** %4
%6 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %39
10: ; preds = %2
%11 = call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %12
12: ; preds = %34, %10
%13 = load i32, i32* %5
%14 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = icmp slt i32 %13, %16
br i1 %17, label %18, label %37
18: ; preds = %12
%19 = load i32, i32* %5
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %5
%23 = srem i32 %22, 10
%24 = icmp eq i32 0, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21, %18
%28 = load i64*, i64** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i64, i64* %28, i64 %30
%32 = load i64, i64* %31
%33 = call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %12
37: ; preds = %12
%38 = call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %2
%40 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %40, i32 0, i32 4
%42 = load i64, i64* %41
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 3
%47 = load i64, i64* %46
%48 = call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i64 %47)
br label %49
49: ; preds = %44, %39
%50 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %50, i32 0, i32 2
%52 = load i64, i64* %51
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %49
%55 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%56 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %55, i32 0, i32 2
%57 = load i64, i64* %56
%58 = call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 %57)
br label %59
59: ; preds = %54, %49
%60 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%61 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %60, i32 0, i32 1
%62 = load i64, i64* %61
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%66 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %65, i32 0, i32 1
%67 = load i64, i64* %66
%68 = call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %67)
br label %69
69: ; preds = %64, %59
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64, i64, i64, i64 }
@.str = [25 x i8] c"SCSI error: sense data: \00"
@.str.1 = [4 x i8] c"\0A \00"
@.str.2 = [8 x i8] c"0x%02x \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [18 x i8] c"SCSI status=0x%x\0A\00"
@.str.5 = [18 x i8] c"host_status=0x%x\0A\00"
@.str.6 = [20 x i8] c"driver_status=0x%x\0A\00"
define void @print_scsi_error(%struct.TYPE_3__* nocapture %0, i64* nocapture %1) {
%3 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %29
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %6, %19
%11 = phi i64 [ %23, %19 ], [ 0, %6 ]
%12 = icmp ne i64 %11, 0
%13 = trunc i64 %11 to i32
%14 = urem i32 %13, 10
%15 = icmp eq i32 %14, 0
%16 = and i1 %12, %15
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = tail call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %10
%20 = getelementptr inbounds i64, i64* %1, i64 %11
%21 = load i64, i64* %20
%22 = tail call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %21)
%23 = add nuw nsw i64 %11, 1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %10, label %27
27: ; preds = %19, %6
%28 = tail call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %2
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 4
%31 = load i64, i64* %30
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 3
%35 = load i64, i64* %34
%36 = tail call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i64 %35)
br label %37
37: ; preds = %33, %29
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 2
%39 = load i64, i64* %38
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = tail call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 %39)
br label %43
43: ; preds = %41, %37
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%45 = load i64, i64* %44
%46 = icmp eq i64 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = tail call i32 (i8*, ...) @write_debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %45)
br label %49
49: ; preds = %47, %43
ret void
}