// File: /workspace/github_cpp_makefile_star2_O1/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)
movq $0x0, 0x50(%rsi)
xorl %eax, %eax
movzwl (%rdi,%rax,2), %ecx
rolw $0x8, %cx
movw %cx, (%rsp,%rax,2)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x14b17
movzwl 0x1b2(%rdi), %eax
movl %eax, 0x4(%rbx)
movb 0x152(%rdi), %al
andb $0x1, %al
movb 0x2(%rbx), %cl
andb $-0x2, %cl
orb %al, %cl
movb %cl, 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 0x14b77
movzwl 0xa4(%rdi), %eax
addl %eax, %eax
andl $0x2, %eax
jmp 0x14b79
xorl %eax, %eax
movl (%rbx), %ecx
andl $-0x3, %ecx
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0xae(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x14baa
movzwl 0xaa(%rdi), %ecx
shll $0x2, %ecx
andl $0x4, %ecx
jmp 0x14bac
xorl %ecx, %ecx
andl $-0x5, %eax
movzwl %cx, %ecx
orl %eax, %ecx
movw %cx, (%rbx)
movzwl 0xa6(%rdi), %eax
andl $0xc000, %eax           # imm = 0xC000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x14bd9
movzwl 0xa4(%rdi), %eax
shll $0x2, %eax
andl $0x8, %eax
jmp 0x14bdb
xorl %eax, %eax
andl $-0x9, %ecx
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0xae(%rdi), %ecx
andl $0xc000, %ecx           # imm = 0xC000
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x14c0a
movzwl 0xaa(%rdi), %ecx
shll $0x3, %ecx
andl $0x10, %ecx
jmp 0x14c0c
xorl %ecx, %ecx
andl $-0x11, %eax
movzwl %cx, %ecx
orl %eax, %ecx
movw %cx, (%rbx)
movzwl 0x100(%rdi), %eax
andl $0x4, %eax
andl $-0x21, %ecx
leal (%rcx,%rax,8), %eax
movw %ax, (%rbx)
movzwl 0x100(%rdi), %ecx
andl $0x8, %ecx
andl $-0x41, %eax
leal (%rax,%rcx,8), %eax
movw %ax, (%rbx)
movzwl 0x100(%rdi), %ecx
andl $0x10, %ecx
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
leal (%rax,%rcx,8), %eax
movw %ax, (%rbx)
movzwl 0x100(%rdi), %ecx
andl $0x20, %ecx
andl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
leal (%rax,%rcx,8), %ecx
movw %cx, (%rbx)
movzwl 0xa6(%rdi), %eax
andl $0xc000, %eax           # imm = 0xC000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x14cb1
cmpw $0x0, 0xac(%rdi)
jns 0x14cb1
movzwl 0xee(%rdi), %eax
andl $0xc004, %eax           # imm = 0xC004
cmpl $0x4004, %eax           # imm = 0x4004
jne 0x14cb1
movzwl 0xf0(%rdi), %edx
andl $0xc004, %edx           # imm = 0xC004
xorl %eax, %eax
cmpl $0x4004, %edx           # imm = 0x4004
sete %al
jmp 0x14cb3
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
movl $0x7fff, %edx           # imm = 0x7FFF
andl %edx, %eax
orl %ecx, %eax
movw %ax, (%rbx)
movzwl 0xb2(%rdi), %eax
testw %ax, %ax
movl $0xff, %ecx
movl $0xff, %esi
cmovsl %edx, %esi
andl %eax, %esi
addl %esi, %esi
movl %esi, 0x8(%rbx)
movzwl 0xb4(%rdi), %eax
testw %ax, %ax
cmovsl %edx, %ecx
andl %eax, %ecx
addl %ecx, %ecx
movl %ecx, 0xc(%rbx)
leaq 0x14(%rsp), %rdi
leaq 0x10(%rbx), %rdx
leaq 0xa3ae(%rip), %rsi      # 0x1f14e
xorl %eax, %eax
callq 0x4490
leaq 0x2e(%rsp), %rdi
leaq 0x25(%rbx), %rdx
leaq 0xa39c(%rip), %rsi      # 0x1f153
xorl %eax, %eax
callq 0x4490
leaq 0x36(%rsp), %rdi
addq $0x2e, %rbx
leaq 0xa389(%rip), %rsi      # 0x1f157
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4490
addq $0x200, %rsp            # imm = 0x200
popq %rbx
retq