// File: /workspace/github_cpp_makefile_star2_O2/trapexit[P]bbf/src/sg.cpp
// Function: sg::buf_to_identity(char const*, sg::identity&)
void
  buf_to_identity(const char    buf[256*2],
                  sg::identity &ident)
  {
    uint16_t tmpbuf[256];
    const uint16_t *buf16 = (const uint16_t*)buf;

    ::memset(&ident,0,sizeof(sg::identity));
    for(unsigned int i = 0; i < 256; i++)
      tmpbuf[i] = ntohs(buf16[i]);

    ident.rpm = buf16[217];
    ident.trim_supported = !!(buf16[169] & 0x0001);
    ident.form_factor    = (buf16[168] & 0x0003);
    ident.smart_supported    = (((buf16[83] & 0xC000) == 0x4000) && (buf16[82] & 0x0001));
    ident.smart_enabled      = (((buf16[87] & 0xC000) == 0x4000) && (buf16[85] & 0x0001));
    ident.security_supported = (((buf16[83] & 0xC000) == 0x4000) && (buf16[82] & 0x0002));
    ident.security_enabled   = (((buf16[87] & 0xC000) == 0x4000) && (buf16[85] & 0x0002));
    ident.security_locked                   = !!(buf16[128] & 0x0004);
    ident.security_frozen                   = !!(buf16[128] & 0x0008);
    ident.security_count_expired            = !!(buf16[128] & 0x0010);
    ident.security_enhanced_erase_supported = !!(buf16[128] & 0x0020);
    ident.write_uncorrectable = (((buf16[83]  & 0xC000) == 0x4000) &&
                                 ((buf16[86]  & 0x8000) == 0x8000) &&
                                 ((buf16[119] & 0xC004) == 0x4004) &&
                                 ((buf16[120] & 0xC004) == 0x4004));
    ident.block_erase        = !!(buf16[59] & 0x8000);
    ident.overwrite          = !!(buf16[59] & 0x4000);
    ident.crypto_scramble    = !!(buf16[59] & 0x2000);
    ident.sanitize           = !!(buf16[59] & 0x1000);
    ident.supports_sata_gen1 = !!(buf16[76] & 0x0002);
    ident.supports_sata_gen2 = !!(buf16[76] & 0x0004);
    ident.supports_sata_gen3 = !!(buf16[76] & 0x0008);

    ident.security_normal_erase_time   = (((buf16[89] & 0x8000) ?
                                           (buf16[89] & 0x7FFF) :
                                           (buf16[89] & 0x00FF)) * 2);
    if((ident.security_normal_erase_time == 0x7FFF) ||
       (ident.security_normal_erase_time == 0x00FF))
      ident.security_normal_erase_time += 90;
    ident.security_enhanced_erase_time = (((buf16[90] & 0x8000) ?
                                           (buf16[90] & 0x7FFF) :
                                           (buf16[90] & 0x00FF)) * 2);
    if((ident.security_enhanced_erase_time == 0x7FFF) ||
       (ident.security_enhanced_erase_time == 0x00FF))
      ident.security_enhanced_erase_time += 90;

    sscanf((char*)&tmpbuf[10],"%20s",ident.serial_number);
    sscanf((char*)&tmpbuf[23],"%8s",ident.firmware_revision);
    sscanf((char*)&tmpbuf[27],"%40c",ident.model_number);
  }

// Assembly:
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rsi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsi)
movups %xmm0, 0x30(%rsi)
movups %xmm0, 0x20(%rsi)
movups %xmm0, 0x10(%rsi)
movups %xmm0, (%rsi)
andq $0x0, 0x50(%rsi)
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x10fbf
movzwl (%rdi,%rax,2), %ecx
rolw $0x8, %cx
movw %cx, (%rsp,%rax,2)
incq %rax
jmp 0x10fa6
movzwl 0x1b2(%rdi), %eax
movl %eax, 0x4(%rbx)
movb 0x152(%rdi), %al
andb $0x1, %al
movb %al, 0x2(%rbx)
movb 0x150(%rdi), %al
andb $0x3, %al
movb %al, 0x3(%rbx)
movzwl 0xa6(%rdi), %eax
andl $0xc000, %eax           # imm = 0xC000
cmpw $0x4000, %ax            # imm = 0x4000
jne 0x10fff
movzwl 0xa4(%rdi), %eax
addl %eax, %eax
andl $0x2, %eax
jmp 0x11001
xorl %eax, %eax
movw %ax, (%rbx)
movzwl 0xae(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpw $0x4000, %cx            # imm = 0x4000
jne 0x11027
movzwl 0xaa(%rdi), %ecx
shll $0x2, %ecx
andl $0x4, %ecx
jmp 0x11029
xorl %ecx, %ecx
movzwl %ax, %edx
movzwl %cx, %eax
orl %edx, %eax
movw %ax, (%rbx)
movzwl 0xa6(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpw $0x4000, %cx            # imm = 0x4000
jne 0x11057
movzwl 0xa4(%rdi), %ecx
shll $0x2, %ecx
andl $0x8, %ecx
jmp 0x11059
xorl %ecx, %ecx
movzwl %ax, %edx
movzwl %cx, %eax
orl %edx, %eax
movw %ax, (%rbx)
movzwl 0xae(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpw $0x4000, %cx            # imm = 0x4000
jne 0x11087
movzwl 0xaa(%rdi), %ecx
shll $0x3, %ecx
andl $0x10, %ecx
jmp 0x11089
xorl %ecx, %ecx
movzwl %ax, %eax
movzwl %cx, %ecx
orl %eax, %ecx
movw %cx, (%rbx)
movzwl 0x100(%rdi), %eax
andl $0x4, %eax
leal (%rcx,%rax,8), %eax
movw %ax, (%rbx)
movzwl 0x100(%rdi), %ecx
andl $0x8, %ecx
leal (%rax,%rcx,8), %eax
movw %ax, (%rbx)
movzwl 0x100(%rdi), %ecx
andl $0x10, %ecx
leal (%rax,%rcx,8), %eax
movw %ax, (%rbx)
movzwl 0x100(%rdi), %ecx
andl $0x20, %ecx
leal (%rax,%rcx,8), %ecx
movw %cx, (%rbx)
movzwl 0xa6(%rdi), %eax
andl $0xc000, %eax           # imm = 0xC000
cmpw $0x4000, %ax            # imm = 0x4000
jne 0x1111b
cmpw $0x0, 0xac(%rdi)
jns 0x1111b
movzwl 0xee(%rdi), %eax
andl $0xc004, %eax           # imm = 0xC004
cmpw $0x4004, %ax            # imm = 0x4004
jne 0x1111b
movzwl 0xf0(%rdi), %edx
andl $0xc004, %edx           # imm = 0xC004
xorl %eax, %eax
cmpw $0x4004, %dx            # imm = 0x4004
sete %al
jmp 0x1111d
xorl %eax, %eax
andl $-0x2, %ecx
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0x76(%rdi), %ecx
shrl $0x6, %ecx
andl $0x200, %ecx            # imm = 0x200
andl $0xfffffdff, %eax       # imm = 0xFFFFFDFF
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0x76(%rdi), %ecx
shrl $0x4, %ecx
andl $0x400, %ecx            # imm = 0x400
andl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0x76(%rdi), %ecx
shrl $0x2, %ecx
andl $0x800, %ecx            # imm = 0x800
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0x76(%rdi), %ecx
andl $0x1000, %ecx           # imm = 0x1000
andl $0xffffefff, %eax       # imm = 0xFFFFEFFF
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0x98(%rdi), %ecx
andl $0x2, %ecx
shll $0xc, %ecx
andl $0xffffdfff, %eax       # imm = 0xFFFFDFFF
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0x98(%rdi), %ecx
andl $0x4, %ecx
shll $0xc, %ecx
andl $0xffffbfff, %eax       # imm = 0xFFFFBFFF
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0x98(%rdi), %ecx
andl $0x8, %ecx
shll $0xc, %ecx
orl %eax, %ecx
movw %cx, (%rbx)
movd 0xb2(%rdi), %xmm0
pxor %xmm1, %xmm1
pshuflw $0x50, %xmm0, %xmm2     # xmm2 = xmm0[0,0,1,1,4,5,6,7]
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
pcmpgtw %xmm2, %xmm1
movdqa %xmm1, %xmm2
pandn 0x9d5a(%rip), %xmm2     # 0x1af40
pand 0x9d62(%rip), %xmm1     # 0x1af50
por %xmm2, %xmm1
pand %xmm0, %xmm1
paddd %xmm1, %xmm1
movq %xmm1, 0x8(%rbx)
leaq 0x14(%rsp), %rdi
leaq 0x10(%rbx), %rdx
leaq 0x9f80(%rip), %rsi      # 0x1b18f
xorl %eax, %eax
callq 0x44a0
leaq 0x2e(%rsp), %rdi
leaq 0x25(%rbx), %rdx
leaq 0x9f6e(%rip), %rsi      # 0x1b194
xorl %eax, %eax
callq 0x44a0
leaq 0x36(%rsp), %rdi
addq $0x2e, %rbx
leaq 0x9f5b(%rip), %rsi      # 0x1b198
movq %rbx, %rdx
xorl %eax, %eax
callq 0x44a0
addq $0x200, %rsp            # imm = 0x200
popq %rbx
retq