// File: /workspace/github_c_makefile_star2_O2/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 0x11515(%rip), %rsi     # 0x31df2
callq 0x4190
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x20c21
leaq 0x60(%rsp), %r14
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
movq 0x18(%rsp), %rdx
callq 0x4110
testq %rax, %rax
je 0x20bfb
movq %r14, %rdi
leaq 0x116e9(%rip), %rsi     # 0x32018
callq 0x4200
testq %rax, %rax
je 0x209c0
movq %rax, %r15
movq %rax, %rdi
leaq 0x116d9(%rip), %rsi     # 0x32023
callq 0x4200
testq %rax, %rax
je 0x20994
movq %rax, %r13
leaq 0x7(%rax), %r12
movq %r12, %rdi
pushq $0x22
popq %rsi
callq 0x40a0
testq %rax, %rax
je 0x20994
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0x4030
subq %r13, %rbx
addq $-0x7, %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4100
movq %rax, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq %r15, %rdi
leaq 0x1168d(%rip), %rsi     # 0x3202b
callq 0x4200
testq %rax, %rax
je 0x209bd
addq $0x7, %rax
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4160
movq %rax, %r12
jmp 0x209c0
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0x11669(%rip), %rsi     # 0x32033
callq 0x4200
testq %rax, %rax
je 0x2090a
movq %rax, %r15
xorl %eax, %eax
movb %al, 0x40(%rsp)
movb %al, 0x20(%rsp)
movq %r15, %rdi
leaq 0x1164b(%rip), %rsi     # 0x3203a
callq 0x4200
testq %rax, %rax
je 0x20a37
movq %rax, %rbp
leaq 0x7(%rax), %r13
movq %r13, %rdi
pushq $0x22
popq %rsi
callq 0x40a0
testq %rax, %rax
je 0x20a37
movq %rax, %rbx
subq %rbp, %rbx
cmpq $0x26, %rbx
pushq $0x26
popq %rax
cmovgeq %rax, %rbx
leaq -0x7(%rbx), %rdx
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x4040
movb $0x0, 0x19(%rsp,%rbx)
movq %r15, %rdi
leaq 0x11601(%rip), %rsi     # 0x32042
callq 0x4200
testq %rax, %rax
je 0x2090a
movq %rax, %r15
leaq 0x9(%rax), %r13
movq %r13, %rdi
pushq $0x22
popq %rsi
callq 0x40a0
testq %rax, %rax
je 0x2090a
movq %rax, %rbp
subq %r15, %rbp
cmpq $0x28, %rbp
pushq $0x28
popq %rax
cmovgeq %rax, %rbp
leaq -0x9(%rbp), %rdx
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x4040
movb $0x0, 0x37(%rsp,%rbp)
cmpb $0x0, 0x20(%rsp)
je 0x2090a
cmpb $0x0, 0x40(%rsp)
je 0x2090a
leaq 0x20(%rsp), %rdi
leaq 0x11599(%rip), %rsi     # 0x3204c
callq 0x41b0
movq %rax, %r15
pushq $0x5
popq %rbx
testq %rax, %rax
jne 0x20b12
leaq 0x20(%rsp), %rdi
leaq 0x11583(%rip), %rsi     # 0x32052
callq 0x41b0
pushq $0x7
popq %rbx
testq %rax, %rax
jne 0x20b12
leaq 0x20(%rsp), %rdi
leaq 0x11570(%rip), %rsi     # 0x32058
callq 0x41b0
pushq $0x8
popq %rbx
testq %rax, %rax
jne 0x20b12
leaq 0x20(%rsp), %rdi
leaq 0x1155f(%rip), %rsi     # 0x32060
callq 0x41b0
pushq $0x9
popq %rbx
testq %rax, %rax
je 0x2090a
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4160
cmpl $0x20, %r12d
jne 0x2090a
movq %rax, %r13
testq %r15, %r15
je 0x20b46
pushq $0x20
popq %rax
movl %eax, %r12d
testb $0x3, %r13b
jne 0x2090a
sarl $0x2, %r13d
imulq $0x18, %rbx, %rax
leaq 0x1d48f(%rip), %rcx     # 0x3dfe0
leaq (%rcx,%rax), %rbx
movq 0x8(%rax,%rcx), %r15
cmpl %r13d, 0x10(%rax,%rcx)
jle 0x20b69
testq %r15, %r15
jne 0x20bad
xorl %r15d, %r15d
leal 0x1f(%r13), %eax
andl $-0x20, %eax
pushq $0x20
popq %rcx
cmovlel %ecx, %eax
movslq %eax, %r12
leaq (,%r12,8), %rsi
movq %r15, %rdi
callq 0x4170
movq %rax, %r15
movq %rax, 0x8(%rbx)
movslq 0x10(%rbx), %rax
leaq (%r15,%rax,8), %rdi
movq %r12, %rdx
subq %rax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x40d0
movl %r12d, 0x10(%rbx)
movslq %r13d, %rax
movq (%r15,%rax,8), %r8
testq %r8, %r8
jne 0x20bd6
movq 0x10(%rsp), %rcx
movq %rcx, (%r15,%rax,8)
movq $0x0, 0x8(%rsp)
pushq $0x20
popq %rax
movl %eax, %r12d
jmp 0x2090a
movq 0x1c41b(%rip), %rax     # 0x3cff8
movq (%rax), %rdi
movq (%rbx), %r9
leaq 0x11480(%rip), %rsi     # 0x3206a
movl %r13d, %edx
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x4150
jmp 0x20bcb
movq 0x8(%rsp), %rdi
callq 0x4030
movq 0x18(%rsp), %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 0x41a0
pushq $0x1
popq %rdi
callq 0x41e0