#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*/ dStrHex(char const *, int, int);
int /*<<< orphan*/ dWordHex(unsigned short const *, int, int /*<<< orphan*/,
                            int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memcpy(char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int sg_ata_get_chars(unsigned short const *, int, int, int, char *);
int sg_is_big_endian();
int /*<<< orphan*/ stderr;
int decode_ata_info_vpd(unsigned char *buff, int len, int long_out,
                        int do_hex) {
  char b[80];
  int num, is_be;
  const char *cp;
  if (len < 36) {
    fprintf(stderr,
            "ATA information VPD page length too "
            "short=%d\n",
            len);
    return 97;
  }
  memcpy(b, buff + 8, 8);
  b[8] = '\0';
  printf("  SAT Vendor identification: %s\n", b);
  memcpy(b, buff + 16, 16);
  b[16] = '\0';
  printf("  SAT Product identification: %s\n", b);
  memcpy(b, buff + 32, 4);
  b[4] = '\0';
  printf("  SAT Product revision level: %s\n", b);
  if (len < 56)
    return 97;
  if (long_out) {
    printf("  Signature (Device to host FIS):\n");
    dStrHex((const char *)buff + 36, 20, 1);
  }
  if (len < 60)
    return 97;
  is_be = sg_is_big_endian();
  if ((0xec == buff[56]) || (0xa1 == buff[56])) {
    cp = (0xa1 == buff[56]) ? "PACKET " : "";
    printf("  ATA command IDENTIFY %sDEVICE response summary:\n", cp);
    num =
        sg_ata_get_chars((const unsigned short *)(buff + 60), 27, 20, is_be, b);
    b[num] = '\0';
    printf("    model: %s\n", b);
    num =
        sg_ata_get_chars((const unsigned short *)(buff + 60), 10, 10, is_be, b);
    b[num] = '\0';
    printf("    serial number: %s\n", b);
    num =
        sg_ata_get_chars((const unsigned short *)(buff + 60), 23, 4, is_be, b);
    b[num] = '\0';
    printf("    firmware revision: %s\n", b);
    if (long_out)
      printf("  ATA command IDENTIFY %sDEVICE response in hex:\n", cp);
  } else if (long_out)
    printf("  ATA command 0x%x got following response:\n",
           (unsigned int)buff[56]);
  if (len < 572)
    return 97;
  if (do_hex)
    dStrHex((const char *)(buff + 60), 512, 0);
  else if (long_out)
    dWordHex((const unsigned short *)(buff + 60), 256, 0, is_be);
  return 0;
}


x86 assembly (clang, -O0):
<decode_ata_info_vpd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x24,-0x14(%rbp)
jge    11b6 <decode_ata_info_vpd+0x46>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x61,-0x4(%rbp)
jmp    1460 <decode_ata_info_vpd+0x2f0>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    $0x8,%edx
call   1070 <memcpy@plt>
movb   $0x0,-0x68(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
movb   $0x0,-0x60(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x20,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
movb   $0x0,-0x6c(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x38,-0x14(%rbp)
jge    1250 <decode_ata_info_vpd+0xe0>
movl   $0x61,-0x4(%rbp)
jmp    1460 <decode_ata_info_vpd+0x2f0>
cmpl   $0x0,-0x18(%rbp)
je     127f <decode_ata_info_vpd+0x10f>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
add    $0x24,%rdi
mov    $0x14,%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
cmpl   $0x3c,-0x14(%rbp)
jge    1295 <decode_ata_info_vpd+0x125>
movl   $0x61,-0x4(%rbp)
jmp    1460 <decode_ata_info_vpd+0x2f0>
mov    $0x0,%al
call   1080 <sg_is_big_endian@plt>
mov    %eax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x38(%rax),%ecx
mov    $0xec,%eax
cmp    %ecx,%eax
je     12c9 <decode_ata_info_vpd+0x159>
mov    -0x10(%rbp),%rax
movzbl 0x38(%rax),%ecx
mov    $0xa1,%eax
cmp    %ecx,%eax
jne    13d2 <decode_ata_info_vpd+0x262>
mov    -0x10(%rbp),%rax
movzbl 0x38(%rax),%esi
mov    $0xa1,%edx
lea    0xdd8(%rip),%rax
lea    0xdd2(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rsi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
add    $0x3c,%rdi
mov    -0x78(%rbp),%ecx
lea    -0x70(%rbp),%r8
mov    $0x1b,%esi
mov    $0x14,%edx
call   1090 <sg_ata_get_chars@plt>
mov    %eax,-0x74(%rbp)
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
add    $0x3c,%rdi
mov    -0x78(%rbp),%ecx
lea    -0x70(%rbp),%r8
mov    $0xa,%edx
mov    %edx,%esi
call   1090 <sg_ata_get_chars@plt>
mov    %eax,-0x74(%rbp)
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
add    $0x3c,%rdi
mov    -0x78(%rbp),%ecx
lea    -0x70(%rbp),%r8
mov    $0x17,%esi
mov    $0x4,%edx
call   1090 <sg_ata_get_chars@plt>
mov    %eax,-0x74(%rbp)
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     13cd <decode_ata_info_vpd+0x25d>
mov    -0x80(%rbp),%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13f7 <decode_ata_info_vpd+0x287>
cmpl   $0x0,-0x18(%rbp)
je     13f2 <decode_ata_info_vpd+0x282>
mov    -0x10(%rbp),%rax
movzbl 0x38(%rax),%esi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13f7 <decode_ata_info_vpd+0x287>
cmpl   $0x23c,-0x14(%rbp)
jge    1410 <decode_ata_info_vpd+0x2a0>
movl   $0x61,-0x4(%rbp)
jmp    1460 <decode_ata_info_vpd+0x2f0>
cmpl   $0x0,-0x1c(%rbp)
je     1433 <decode_ata_info_vpd+0x2c3>
mov    -0x10(%rbp),%rdi
add    $0x3c,%rdi
mov    $0x200,%esi
xor    %edx,%edx
call   1030 <dStrHex@plt>
jmp    1459 <decode_ata_info_vpd+0x2e9>
cmpl   $0x0,-0x18(%rbp)
je     1454 <decode_ata_info_vpd+0x2e4>
mov    -0x10(%rbp),%rdi
add    $0x3c,%rdi
mov    -0x78(%rbp),%ecx
mov    $0x100,%esi
xor    %edx,%edx
call   1040 <dWordHex@plt>
jmp    1459 <decode_ata_info_vpd+0x2e9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_ata_info_vpd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebp
cmp    $0x23,%esi
jg     11b7 <decode_ata_info_vpd+0x37>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    $0x61,%r12d
jmp    13e4 <decode_ata_info_vpd+0x264>
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rdi,%r13
lea    0x8(%rdi),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%edx
call   1080 <memcpy@plt>
movb   $0x0,0x18(%rsp)
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%r13),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1080 <memcpy@plt>
movb   $0x0,0x20(%rsp)
lea    0xe46(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%r13),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1080 <memcpy@plt>
movb   $0x0,0x14(%rsp)
lea    0xe41(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x61,%r12d
cmp    $0x38,%ebp
jb     13e4 <decode_ata_info_vpd+0x264>
test   %r14d,%r14d
je     126d <decode_ata_info_vpd+0xed>
lea    0xf18(%rip),%rdi
call   1030 <puts@plt>
lea    0x24(%r13),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
call   1040 <dStrHex@plt>
cmp    $0x3c,%ebp
jb     13e4 <decode_ata_info_vpd+0x264>
xor    %eax,%eax
call   1090 <sg_is_big_endian@plt>
mov    %eax,(%rsp)
movzbl 0x38(%r13),%esi
cmp    $0xec,%esi
je     1297 <decode_ata_info_vpd+0x117>
cmp    $0xa1,%sil
jne    1389 <decode_ata_info_vpd+0x209>
cmp    $0xa1,%sil
lea    0xdf1(%rip),%rax
lea    0xec3(%rip),%rsi
cmove  %rax,%rsi
lea    0xde7(%rip),%rdi
mov    %rsi,0x8(%rsp)
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x3c(%r13),%rbx
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
mov    $0x1b,%esi
mov    $0x14,%edx
mov    %r15d,0x4(%rsp)
mov    (%rsp),%r15d
mov    %r15d,%ecx
call   10a0 <sg_ata_get_chars@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xdd9(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xa,%edx
mov    %r15d,%ecx
lea    0x10(%rsp),%r8
call   10a0 <sg_ata_get_chars@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xdb4(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x17,%esi
mov    $0x4,%edx
mov    %r15d,%ecx
mov    0x4(%rsp),%r15d
lea    0x10(%rsp),%r8
mov    %r8,%rbx
call   10a0 <sg_ata_get_chars@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xd8f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
je     139c <decode_ata_info_vpd+0x21c>
lea    0xd94(%rip),%rdi
mov    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    139c <decode_ata_info_vpd+0x21c>
test   %r14d,%r14d
je     139c <decode_ata_info_vpd+0x21c>
lea    0xdac(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x23c,%ebp
jb     13e4 <decode_ata_info_vpd+0x264>
test   %r15d,%r15d
je     13c1 <decode_ata_info_vpd+0x241>
add    $0x3c,%r13
xor    %r12d,%r12d
mov    %r13,%rdi
mov    $0x200,%esi
xor    %edx,%edx
call   1040 <dStrHex@plt>
jmp    13e4 <decode_ata_info_vpd+0x264>
test   %r14d,%r14d
je     13e1 <decode_ata_info_vpd+0x261>
add    $0x3c,%r13
xor    %r12d,%r12d
mov    %r13,%rdi
mov    $0x100,%esi
xor    %edx,%edx
mov    (%rsp),%ecx
call   1050 <dWordHex@plt>
jmp    13e4 <decode_ata_info_vpd+0x264>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"ATA information VPD page length too short=%d\0A\00"
@.str.1 = [33 x i8] c" SAT Vendor identification: %s\0A\00"
@.str.2 = [34 x i8] c" SAT Product identification: %s\0A\00"
@.str.3 = [34 x i8] c" SAT Product revision level: %s\0A\00"
@.str.4 = [35 x i8] c" Signature (Device to host FIS):\0A\00"
@.str.5 = [8 x i8] c"PACKET \00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [51 x i8] c" ATA command IDENTIFY %sDEVICE response summary:\0A\00"
@.str.8 = [15 x i8] c" model: %s\0A\00"
@.str.9 = [23 x i8] c" serial number: %s\0A\00"
@.str.10 = [27 x i8] c" firmware revision: %s\0A\00"
@.str.11 = [50 x i8] c" ATA command IDENTIFY %sDEVICE response in hex:\0A\00"
@.str.12 = [44 x i8] c" ATA command 0x%x got following response:\0A\00"
define i32 @decode_ata_info_vpd(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [80 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 36
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = load i32, i32* %7
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 97, i32* %5
br label %151
20: ; preds = %4
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 8
%24 = call i32 @memcpy(i8* %21, i8* %23, i32 8)
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 8
store i8 0, i8* %25
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 16
%31 = call i32 @memcpy(i8* %28, i8* %30, i32 16)
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 16
store i8 0, i8* %32
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 32
%38 = call i32 @memcpy(i8* %35, i8* %37, i32 4)
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 4
store i8 0, i8* %39
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %7
%43 = icmp slt i32 %42, 56
br i1 %43, label %44, label %45
44: ; preds = %20
store i32 97, i32* %5
br label %151
45: ; preds = %20
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i64 36
%52 = call i32 @dStrHex(i8* %51, i32 20, i32 1)
br label %53
53: ; preds = %48, %45
%54 = load i32, i32* %7
%55 = icmp slt i32 %54, 60
br i1 %55, label %56, label %57
56: ; preds = %53
store i32 97, i32* %5
br label %151
57: ; preds = %53
%58 = call i32 (...) @sg_is_big_endian()
store i32 %58, i32* %12
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 56
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp eq i32 236, %62
br i1 %63, label %70, label %64
64: ; preds = %57
%65 = load i8*, i8** %6
%66 = getelementptr inbounds i8, i8* %65, i64 56
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = icmp eq i32 161, %68
br i1 %69, label %70, label %119
70: ; preds = %64, %57
%71 = load i8*, i8** %6
%72 = getelementptr inbounds i8, i8* %71, i64 56
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = icmp eq i32 161, %74
%76 = zext i1 %75 to i64
%77 = select i1 %75, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0)
store i8* %77, i8** %13
%78 = load i8*, i8** %13
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i8* %78)
%80 = load i8*, i8** %6
%81 = getelementptr inbounds i8, i8* %80, i64 60
%82 = bitcast i8* %81 to i16*
%83 = load i32, i32* %12
%84 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%85 = call i32 @sg_ata_get_chars(i16* %82, i32 27, i32 20, i32 %83, i8* %84)
store i32 %85, i32* %11
%86 = load i32, i32* %11
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 %87
store i8 0, i8* %88
%89 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %89)
%91 = load i8*, i8** %6
%92 = getelementptr inbounds i8, i8* %91, i64 60
%93 = bitcast i8* %92 to i16*
%94 = load i32, i32* %12
%95 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%96 = call i32 @sg_ata_get_chars(i16* %93, i32 10, i32 10, i32 %94, i8* %95)
store i32 %96, i32* %11
%97 = load i32, i32* %11
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 %98
store i8 0, i8* %99
%100 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %100)
%102 = load i8*, i8** %6
%103 = getelementptr inbounds i8, i8* %102, i64 60
%104 = bitcast i8* %103 to i16*
%105 = load i32, i32* %12
%106 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%107 = call i32 @sg_ata_get_chars(i16* %104, i32 23, i32 4, i32 %105, i8* %106)
store i32 %107, i32* %11
%108 = load i32, i32* %11
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 %109
store i8 0, i8* %110
%111 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %111)
%113 = load i32, i32* %8
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %70
%116 = load i8*, i8** %13
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.11, i64 0, i64 0), i8* %116)
br label %118
118: ; preds = %115, %70
br label %129
119: ; preds = %64
%120 = load i32, i32* %8
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %128
122: ; preds = %119
%123 = load i8*, i8** %6
%124 = getelementptr inbounds i8, i8* %123, i64 56
%125 = load i8, i8* %124
%126 = zext i8 %125 to i32
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0), i32 %126)
br label %128
128: ; preds = %122, %119
br label %129
129: ; preds = %128, %118
%130 = load i32, i32* %7
%131 = icmp slt i32 %130, 572
br i1 %131, label %132, label %133
132: ; preds = %129
store i32 97, i32* %5
br label %151
133: ; preds = %129
%134 = load i32, i32* %9
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %140
136: ; preds = %133
%137 = load i8*, i8** %6
%138 = getelementptr inbounds i8, i8* %137, i64 60
%139 = call i32 @dStrHex(i8* %138, i32 512, i32 0)
br label %150
140: ; preds = %133
%141 = load i32, i32* %8
%142 = icmp ne i32 %141, 0
br i1 %142, label %143, label %149
143: ; preds = %140
%144 = load i8*, i8** %6
%145 = getelementptr inbounds i8, i8* %144, i64 60
%146 = bitcast i8* %145 to i16*
%147 = load i32, i32* %12
%148 = call i32 @dWordHex(i16* %146, i32 256, i32 0, i32 %147)
br label %149
149: ; preds = %143, %140
br label %150
150: ; preds = %149, %136
store i32 0, i32* %5
br label %151
151: ; preds = %150, %132, %56, %44, %16
%152 = load i32, i32* %5
ret i32 %152
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"ATA information VPD page length too short=%d\0A\00"
@.str.1 = [33 x i8] c" SAT Vendor identification: %s\0A\00"
@.str.2 = [34 x i8] c" SAT Product identification: %s\0A\00"
@.str.3 = [34 x i8] c" SAT Product revision level: %s\0A\00"
@.str.5 = [8 x i8] c"PACKET \00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [51 x i8] c" ATA command IDENTIFY %sDEVICE response summary:\0A\00"
@.str.8 = [15 x i8] c" model: %s\0A\00"
@.str.9 = [23 x i8] c" serial number: %s\0A\00"
@.str.10 = [27 x i8] c" firmware revision: %s\0A\00"
@.str.11 = [50 x i8] c" ATA command IDENTIFY %sDEVICE response in hex:\0A\00"
@.str.12 = [44 x i8] c" ATA command 0x%x got following response:\0A\00"
@str = [34 x i8] c" Signature (Device to host FIS):\00"
define i32 @decode_ata_info_vpd(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [80 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%7 = icmp slt i32 %1, 36
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %73
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %0, i64 8
%13 = call i32 @memcpy(i8* %6, i8* %12, i32 8)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 8
store i8 0, i8* %14
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%16 = getelementptr inbounds i8, i8* %0, i64 16
%17 = call i32 @memcpy(i8* %6, i8* %16, i32 16)
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 16
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%20 = getelementptr inbounds i8, i8* %0, i64 32
%21 = call i32 @memcpy(i8* %6, i8* %20, i32 4)
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 4
store i8 0, i8* %22
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%24 = icmp ult i32 %1, 56
br i1 %24, label %73, label %25
25: ; preds = %11
%26 = icmp eq i32 %2, 0
br i1 %26, label %31, label %27
27: ; preds = %25
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%29 = getelementptr inbounds i8, i8* %0, i64 36
%30 = call i32 @dStrHex(i8* %29, i32 20, i32 1)
br label %31
31: ; preds = %27, %25
%32 = icmp ult i32 %1, 60
br i1 %32, label %73, label %33
33: ; preds = %31
%34 = call i32 (...) @sg_is_big_endian()
%35 = getelementptr inbounds i8, i8* %0, i64 56
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
switch i8 %36, label %58 [
i8 -20, label %38
i8 -95, label %38
]
38: ; preds = %33, %33
%39 = icmp eq i8 %36, -95
%40 = select i1 %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds i8, i8* %0, i64 60
%43 = bitcast i8* %42 to i16*
%44 = call i32 @sg_ata_get_chars(i16* %43, i32 27, i32 20, i32 %34, i8* %6)
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %45
store i8 0, i8* %46
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %6)
%48 = call i32 @sg_ata_get_chars(i16* %43, i32 10, i32 10, i32 %34, i8* %6)
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %49
store i8 0, i8* %50
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %6)
%52 = call i32 @sg_ata_get_chars(i16* %43, i32 23, i32 4, i32 %34, i8* %6)
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %53
store i8 0, i8* %54
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %6)
br i1 %26, label %61, label %56
56: ; preds = %38
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.11, i64 0, i64 0), i8* %40)
br label %61
58: ; preds = %33
br i1 %26, label %61, label %59
59: ; preds = %58
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0), i32 %37)
br label %61
61: ; preds = %58, %59, %38, %56
%62 = icmp ult i32 %1, 572
br i1 %62, label %73, label %63
63: ; preds = %61
%64 = icmp eq i32 %3, 0
br i1 %64, label %68, label %65
65: ; preds = %63
%66 = getelementptr inbounds i8, i8* %0, i64 60
%67 = call i32 @dStrHex(i8* %66, i32 512, i32 0)
br label %73
68: ; preds = %63
br i1 %26, label %73, label %69
69: ; preds = %68
%70 = getelementptr inbounds i8, i8* %0, i64 60
%71 = bitcast i8* %70 to i16*
%72 = call i32 @dWordHex(i16* %71, i32 256, i32 0, i32 %34)
br label %73
73: ; preds = %65, %69, %68, %61, %31, %11, %8
%74 = phi i32 [ 97, %8 ], [ 97, %11 ], [ 97, %31 ], [ 97, %61 ], [ 0, %68 ], [ 0, %69 ], [ 0, %65 ]
ret i32 %74
}