// File: /workspace/github_c_makefile_star2_O3/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 0x116d8(%rip), %rsi     # 0x32df2
callq 0x4190
testq %rax, %rax
je 0x21aca
movq %rax, %r13
leaq 0x60(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %rax, %rdx
callq 0x4110
testq %rax, %rax
je 0x21a9d
leaq 0x60(%rsp), %r15
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq %r15, %rdi
leaq 0x118a8(%rip), %rsi     # 0x33018
callq 0x4200
testq %rax, %rax
je 0x2180b
movq %rax, %r12
movq %rax, %rdi
leaq 0x11898(%rip), %rsi     # 0x33023
callq 0x4200
testq %rax, %rax
je 0x217d7
movq %rax, %rbp
leaq 0x7(%rax), %r14
movq %r14, %rdi
movl $0x22, %esi
callq 0x40a0
testq %rax, %rax
je 0x217d7
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x4030
subq %rbp, %rbx
addq $-0x7, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4100
movq %rax, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %r12, %rdi
leaq 0x1184a(%rip), %rsi     # 0x3302b
callq 0x4200
testq %rax, %rax
je 0x21802
addq $0x7, %rax
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4160
movq %rax, 0x8(%rsp)
jmp 0x2180b
movq $0x0, 0x8(%rsp)
movq %r15, %rdi
leaq 0x1181e(%rip), %rsi     # 0x33033
callq 0x4200
testq %rax, %rax
je 0x2194a
movq %rax, %r12
movq %r13, %r14
xorl %eax, %eax
movb %al, 0x20(%rsp)
movb %al, 0x40(%rsp)
movq %r12, %rdi
leaq 0x117fd(%rip), %rsi     # 0x3303a
callq 0x4200
testq %rax, %rax
je 0x21889
movq %rax, %r13
leaq 0x7(%rax), %rbp
movq %rbp, %rdi
movl $0x22, %esi
callq 0x40a0
testq %rax, %rax
je 0x21889
movq %rax, %rbx
subq %r13, %rbx
cmpq $0x26, %rbx
movl $0x26, %eax
cmovgeq %rax, %rbx
leaq -0x7(%rbx), %rdx
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x4040
movb $0x0, 0x39(%rsp,%rbx)
movq %r12, %rdi
leaq 0x117af(%rip), %rsi     # 0x33042
callq 0x4200
testq %rax, %rax
je 0x21947
movq %rax, %r13
leaq 0x9(%rax), %r12
movq %r12, %rdi
movl $0x22, %esi
callq 0x40a0
testq %rax, %rax
je 0x21947
movq %rax, %rbx
subq %r13, %rbx
cmpq $0x28, %rbx
movl $0x28, %eax
cmovgeq %rax, %rbx
leaq -0x9(%rbx), %rdx
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x4040
movb $0x0, 0x17(%rsp,%rbx)
cmpb $0x0, 0x40(%rsp)
je 0x21947
cmpb $0x0, 0x20(%rsp)
movq %r14, %r13
leaq 0x40(%rsp), %r12
je 0x2194a
movq %r12, %rdi
leaq 0x11745(%rip), %rsi     # 0x3304c
callq 0x41b0
testq %rax, %rax
je 0x21968
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4160
cmpl $0x20, 0x8(%rsp)
jne 0x2194a
movq %rax, %r12
movl $0x20, %eax
movq %rax, 0x8(%rsp)
testb $0x3, %r12b
jne 0x2194a
sarl $0x2, %r12d
movl $0x5, %ebx
jmp 0x219cb
movq %r14, %r13
movq %r15, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r13, %rdx
callq 0x4110
testq %rax, %rax
jne 0x21766
jmp 0x21aa6
movq %r12, %rdi
leaq 0x116e0(%rip), %rsi     # 0x33052
callq 0x41b0
movl $0x7, %ebx
testq %rax, %rax
jne 0x219b3
movq %r12, %rdi
leaq 0x116cd(%rip), %rsi     # 0x33058
callq 0x41b0
movl $0x8, %ebx
testq %rax, %rax
jne 0x219b3
movq %r12, %rdi
leaq 0x116bc(%rip), %rsi     # 0x33060
callq 0x41b0
movl $0x9, %ebx
testq %rax, %rax
je 0x2194a
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4160
cmpl $0x20, 0x8(%rsp)
jne 0x2194a
movq %rax, %r12
leaq (%rbx,%rbx,2), %rax
leaq 0x1b60a(%rip), %rcx     # 0x3cfe0
leaq (%rcx,%rax,8), %rbx
movq 0x8(%rbx), %rbp
cmpl %r12d, 0x10(%rbx)
jle 0x219eb
testq %rbp, %rbp
jne 0x21a3c
xorl %ebp, %ebp
leal 0x1f(%r12), %eax
andl $-0x20, %eax
movl $0x20, %ecx
cmovlel %ecx, %eax
movslq %eax, %r13
leaq (,%r13,8), %rsi
movq %rbp, %rdi
callq 0x4170
movq %rax, %rbp
movq %rax, 0x8(%rbx)
movslq 0x10(%rbx), %rax
leaq (,%rax,8), %rdi
addq %rbp, %rdi
movq %r13, %rdx
subq %rax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x40d0
movl %r13d, 0x10(%rbx)
movq %r14, %r13
movslq %r12d, %rax
movq (%rbp,%rax,8), %r8
testq %r8, %r8
jne 0x21a6b
movq 0x18(%rsp), %rcx
movq %rcx, (%rbp,%rax,8)
movl $0x20, %eax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
jmp 0x2194a
movq 0x1a586(%rip), %rax     # 0x3bff8
movq (%rax), %rdi
movq (%rbx), %r9
leaq 0x115eb(%rip), %rsi     # 0x3306a
movl %r12d, %edx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x4150
movl $0x20, %eax
movq %rax, 0x8(%rsp)
jmp 0x2194a
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x4030
movq %r13, %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