// File: /workspace/github_c_makefile_star2_O1/mikebdp2[P]AtomDis/indices.c
// Function: index_load_registers
void index_load_registers (const char *file)
{
    FILE *f;
    char  buf[512], kind[32], offset[32];
    char *c, *d, *e, *name = NULL, *namefree = NULL;
    int   len, id, nr, size = 0;

    if (! (f = fopen (file, "r")) ) {
	perror (file);
	exit (1);
    }
    while (fgets (buf, 512, f)) {
	if ( (c = strstr (buf, "<register ")) ) {
	    if ( (d = strstr (c, " name=\"")) )
		if ( (e = strchr (d+7, '"')) ) {
		    free (namefree);
		    name = namefree = strndup (d+7, e-d-7);
		}
	    size = 0;
	    if ( (d = strstr (c, " size=\"")) )
		size = strtol (d+7, NULL, 0);
	}
	if ( (c = strstr (buf, "<addr ")) ) {
	    kind[0] = offset[0] = 0;
	    if ( (d = strstr (c, " kind=\"")) )
		if ( (e = strchr (d+7, '"')) ) {
		    strncpy (kind, d+7, e-d-7 > 31 ? 31 : e-d-7);
		    kind[ e-d-7 > 31 ? 31 : e-d-7] = 0;
		}
	    if ( (d = strstr (c, " offset=\"")) )
		if ( (e = strchr (d+9, '"')) ) {
		    strncpy (offset, d+9, e-d-9 > 31 ? 31 : e-d-9);
		    offset[ e-d-9 > 31 ? 31 : e-d-9] = 0;
		}
	    if (! kind[0] || ! offset[0])
		continue;
	    if (strcasestr (kind, "MMReg"))
		id = INDEX_REG_MM;
	    else if (strcasestr (kind, "MCIND"))
		id = INDEX_REG_MC;
	    else if (strcasestr (kind, "PCIEIND"))
		id = INDEX_REG_PCIE;
	    else if (strcasestr (kind, "pciConfig"))
		id = INDEX_REG_PCICONFIG;
	    else
		continue;
	    nr = strtol (offset, NULL, 0);
	    if (size != 32)
		continue;		/* TODO: 8-bit MM */
	    if (id == INDEX_REG_MM) {
		if (! (nr & 3))
		    nr >>= 2;
		else
		    continue;
	    }
	    if (index_tables[id].len <= nr || ! index_tables[id].tab) {
		len = (nr + 0x1f) & -0x20;
		if (len <= 0)
		    len = 0x20;
		index_tables[id].tab = realloc (index_tables[id].tab,
						len * sizeof (const char *));
		memset (index_tables[id].tab + index_tables[id].len,
			0,
			(len - index_tables[id].len) * sizeof (const char *));
		index_tables[id].len = len;
	    }
	    if (index_tables[id].tab[nr]) {
		fprintf (stderr, "Register clash: %04x = %s = %s in table %s\n",
			 nr, name, index_tables[id].tab[nr], index_tables[id].name);
	    } else {
#if 0
		fprintf (stderr, "   %s = %04x  [%02x]\n", name, nr, size);
#endif
		index_tables[id].tab[nr] = name;
		namefree = NULL;
	    }
	}
    }
    free (namefree);
    fclose (f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rdi, %rbx
leaq 0x118d3(%rip), %rsi     # 0x32e15
callq 0x4190
testq %rax, %rax
je 0x218bb
movq %rax, %rbp
leaq 0x60(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %rax, %rdx
callq 0x4110
testq %rax, %rax
je 0x2188e
leaq 0x60(%rsp), %r15
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq %r15, %rdi
leaq 0x11aa3(%rip), %rsi     # 0x3303b
callq 0x4200
testq %rax, %rax
je 0x21633
movq %rax, %r12
movq %rax, %rdi
leaq 0x11a93(%rip), %rsi     # 0x33046
callq 0x4200
testq %rax, %rax
je 0x215ff
movq %rax, %r13
leaq 0x7(%rax), %r14
movq %r14, %rdi
movl $0x22, %esi
callq 0x40a0
testq %rax, %rax
je 0x215ff
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0x4030
subq %r13, %rbx
addq $-0x7, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4100
movq %rax, 0x18(%rsp)
movq %rax, 0x8(%rsp)
movq %r12, %rdi
leaq 0x11a45(%rip), %rsi     # 0x3304e
callq 0x4200
testq %rax, %rax
je 0x2162a
addq $0x7, %rax
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4160
movq %rax, 0x10(%rsp)
jmp 0x21633
movq $0x0, 0x10(%rsp)
movq %r15, %rdi
leaq 0x11a19(%rip), %rsi     # 0x33056
callq 0x4200
testq %rax, %rax
je 0x2184e
movq %rax, %r12
movq %rbp, %r14
xorl %eax, %eax
movb %al, 0x20(%rsp)
movb %al, 0x40(%rsp)
movq %r12, %rdi
leaq 0x119f8(%rip), %rsi     # 0x3305d
callq 0x4200
testq %rax, %rax
je 0x216b1
movq %rax, %rbp
leaq 0x7(%rax), %r13
movq %r13, %rdi
movl $0x22, %esi
callq 0x40a0
testq %rax, %rax
je 0x216b1
movq %rax, %rbx
subq %rbp, %rbx
cmpq $0x26, %rbx
movl $0x26, %eax
cmovgeq %rax, %rbx
leaq -0x7(%rbx), %rdx
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x4040
movb $0x0, 0x39(%rsp,%rbx)
movq %r12, %rdi
leaq 0x119aa(%rip), %rsi     # 0x33065
callq 0x4200
testq %rax, %rax
je 0x21708
movq %rax, %rbx
leaq 0x9(%rax), %r12
movq %r12, %rdi
movl $0x22, %esi
callq 0x40a0
testq %rax, %rax
je 0x21708
movq %rax, %r13
subq %rbx, %r13
cmpq $0x28, %r13
movl $0x28, %eax
cmovgeq %rax, %r13
leaq -0x9(%r13), %rdx
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x4040
movb $0x0, 0x17(%rsp,%r13)
cmpb $0x0, 0x40(%rsp)
movq %r14, %rbp
je 0x2184e
cmpb $0x0, 0x20(%rsp)
leaq 0x40(%rsp), %r14
je 0x2184e
movq %r14, %rdi
leaq 0x1193f(%rip), %rsi     # 0x3306f
callq 0x41b0
movq %rax, %r13
movl $0x5, %ebx
testq %rax, %rax
jne 0x21791
movq %r14, %rdi
leaq 0x11929(%rip), %rsi     # 0x33075
callq 0x41b0
movl $0x7, %ebx
testq %rax, %rax
jne 0x21791
movq %r14, %rdi
leaq 0x11916(%rip), %rsi     # 0x3307b
callq 0x41b0
movl $0x8, %ebx
testq %rax, %rax
jne 0x21791
movq %r14, %rdi
leaq 0x11905(%rip), %rsi     # 0x33083
callq 0x41b0
movl $0x9, %ebx
testq %rax, %rax
je 0x2184e
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4160
cmpl $0x20, 0x10(%rsp)
jne 0x2184e
movq %rax, %r12
testq %r13, %r13
je 0x217cb
testb $0x3, %r12b
je 0x217c7
movl $0x20, %eax
movq %rax, 0x10(%rsp)
jmp 0x2184e
sarl $0x2, %r12d
leaq (%rbx,%rbx,2), %rax
leaq 0x1b80a(%rip), %rcx     # 0x3cfe0
leaq (%rcx,%rax,8), %rbx
cmpl %r12d, 0x10(%rbx)
jle 0x217e7
cmpq $0x0, 0x8(%rbx)
jne 0x2182c
leal 0x1f(%r12), %eax
andl $-0x20, %eax
movl $0x20, %ecx
cmovlel %ecx, %eax
movq 0x8(%rbx), %rdi
movslq %eax, %r13
leaq (,%r13,8), %rsi
callq 0x4170
movq %rax, 0x8(%rbx)
movslq 0x10(%rbx), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r13, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x40d0
movl %r13d, 0x10(%rbx)
movq 0x8(%rbx), %rax
movslq %r12d, %rcx
movq (%rax,%rcx,8), %r8
testq %r8, %r8
jne 0x21869
movq 0x18(%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
movq $0x0, 0x8(%rsp)
movq %r15, %rdi
movl $0x200, %esi            # imm = 0x200
movq %rbp, %rdx
callq 0x4110
testq %rax, %rax
jne 0x2158e
jmp 0x21897
movq 0x1a788(%rip), %rax     # 0x3bff8
movq (%rax), %rdi
movq (%rbx), %r9
leaq 0x11810(%rip), %rsi     # 0x3308d
movl %r12d, %edx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x4150
jmp 0x2184e
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rdi
callq 0x4030
movq %rbp, %rdi
callq 0x4070
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x438d