// File: /workspace/github_cpp_makefile_star2_O3/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
pxor %xmm0, %xmm0
movdqu %xmm0, 0x40(%rsi)
movdqu %xmm0, 0x30(%rsi)
movdqu %xmm0, 0x20(%rsi)
movdqu %xmm0, 0x10(%rsi)
movdqu %xmm0, (%rsi)
movq $0x0, 0x50(%rsi)
xorl %eax, %eax
movdqu (%rdi,%rax,2), %xmm0
movdqa %xmm0, %xmm1
psrlw $0x8, %xmm1
psllw $0x8, %xmm0
por %xmm1, %xmm0
movdqa %xmm0, (%rsp,%rax,2)
addq $0x8, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x14a8b
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
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x14af4
movzwl 0xa4(%rdi), %eax
addl %eax, %eax
andl $0x2, %eax
jmp 0x14af6
xorl %eax, %eax
movw %ax, (%rbx)
movzwl 0xae(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x14b1d
movzwl 0xaa(%rdi), %ecx
shll $0x2, %ecx
andl $0x4, %ecx
jmp 0x14b1f
xorl %ecx, %ecx
movzwl %ax, %edx
movzwl %cx, %eax
orl %edx, %eax
movw %ax, (%rbx)
movzwl 0xa6(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x14b4e
movzwl 0xa4(%rdi), %ecx
shll $0x2, %ecx
andl $0x8, %ecx
jmp 0x14b50
xorl %ecx, %ecx
movzwl %ax, %edx
movzwl %cx, %eax
orl %edx, %eax
movw %ax, (%rbx)
movzwl 0xae(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x14b7f
movzwl 0xaa(%rdi), %ecx
shll $0x3, %ecx
andl $0x10, %ecx
jmp 0x14b81
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
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x14c16
cmpw $0x0, 0xac(%rdi)
jns 0x14c16
movzwl 0xee(%rdi), %eax
andl $0xc004, %eax           # imm = 0xC004
cmpl $0x4004, %eax           # imm = 0x4004
jne 0x14c16
movzwl 0xf0(%rdi), %edx
andl $0xc004, %edx           # imm = 0xC004
xorl %eax, %eax
cmpl $0x4004, %edx           # imm = 0x4004
sete %al
jmp 0x14c18
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 0xa23f(%rip), %xmm2     # 0x1ef20
pand 0xa247(%rip), %xmm1     # 0x1ef30
por %xmm2, %xmm1
pand %xmm0, %xmm1
paddd %xmm1, %xmm1
movq %xmm1, 0x8(%rbx)
leaq 0x14(%rsp), %rdi
leaq 0x10(%rbx), %rdx
leaq 0xa465(%rip), %rsi      # 0x1f16f
xorl %eax, %eax
callq 0x4490
leaq 0x2e(%rsp), %rdi
leaq 0x25(%rbx), %rdx
leaq 0xa453(%rip), %rsi      # 0x1f174
xorl %eax, %eax
callq 0x4490
leaq 0x36(%rsp), %rdi
addq $0x2e, %rbx
leaq 0xa440(%rip), %rsi      # 0x1f178
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4490
addq $0x200, %rsp            # imm = 0x200
popq %rbx
retq