// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libcpuid/recog_intel.c
// Function: get_brand_code_and_bits
static intel_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data)
{
	intel_code_t code = (intel_code_t) NC;
	intel_code_and_bits_t result;
	uint64_t bits = 0;
	int i = 0;
	const char* bs = data->brand_str;
	const char* s;
	const size_t n = strlen(bs);
	const struct { intel_code_t c; const char *search; } matchtable[] = {
		{ PENTIUM_M, "Pentium(R) M" },
		{ CORE_SOLO, "Pentium(R) Dual  CPU" },
		{ CORE_SOLO, "Pentium(R) Dual-Core" },
		{ PENTIUM_D, "Pentium(R) D" },
		{ CORE_SOLO, "Genuine Intel(R) CPU" },
		{ CORE_SOLO, "Intel(R) Core(TM)" },
		{ DIAMONDVILLE, "CPU [N ][23]## " },
		{ SILVERTHORNE, "CPU Z" },
		{ PINEVIEW, "CPU [ND][45]## " },
		{ CEDARVIEW, "CPU [ND]#### " },
	};

	const struct { uint64_t bit; const char* search; } bit_matchtable[] = {
		{ XEON_, "Xeon" },
		{ _MP_, " MP" },
		{ ATOM_, "Atom" },
		{ MOBILE_, "Mobile" },
		{ CELERON_, "Celeron" },
		{ PENTIUM_, "Pentium" },
		{ _BRONZE_, "Bronze" },
		{ _SILVER_, "Silver" },
		{ _GOLD_, "Gold" },
		{ _PLATINIUM_, "Platinum" },
		{ _MAX_, "Max" },
	};

	for (i = 0; i < COUNT_OF(bit_matchtable); i++) {
		if (match_pattern(bs, bit_matchtable[i].search))
			bits |= bit_matchtable[i].bit;
	}

	if ((i = match_pattern(bs, "Core(TM) [im][3579]")) != 0) {
		bits |= CORE_;
		i--;
		switch (bs[i + 9]) {
			case 'i': bits |= _I_; break;
			case 'm': bits |= _M_; break;
		}
		switch (bs[i + 10]) {
			case '3': bits |= _3; break;
			case '5': bits |= _5; break;
			case '7': bits |= _7; break;
			case '9': bits |= _9; break;
		}
		for(i = i + 11; i < n; i++) {
			switch (bs[i]) {
				case 'H': bits |= _H; break;
				case 'K': bits |= _K; break;
				case 'N': bits |= _N; break;
				case 'P': bits |= _P; break;
				case 'S': bits |= _S; break;
				case 'U': bits |= _U; break;
				case 'X': bits |= _X; break;
			}
		}
	}
	else if ((i = match_pattern(bs, "Xeon(R) w[3579]")) != 0) {
		bits |= XEON_;
		i--;
		switch (bs[i + 8]) {
			case 'w': bits |= _W_; break;
		}
		switch (bs[i + 9]) {
			case '3': bits |= _3; break;
			case '5': bits |= _5; break;
			case '7': bits |= _7; break;
			case '9': bits |= _9; break;
		}
	}
	else if ((i = match_pattern(bs, "Xeon(R) [DW]")) != 0) {
		bits |= XEON_;
		i--;
		switch (bs[i + 8]) {
			case 'D': bits |= _D_; break;
			case 'W': bits |= _W_; break;
		}
	}
	for (i = 0; i < COUNT_OF(matchtable); i++)
		if (match_pattern(bs, matchtable[i].search)) {
			code = matchtable[i].c;
			break;
		}
	debugf(2, "intel matchtable result is %d\n", code);
	if (bits & XEON_) {
		if (match_pattern(bs, "W35##") || match_pattern(bs, "[ELXW]75##"))
			bits |= _7;
		else if (match_pattern(bs, "[ELXW]55##"))
			code = GAINESTOWN;
		else if (match_pattern(bs, "[ELXW]56##"))
			code = WESTMERE;
		else if (data->l3_cache > 0 && data->family == 16)
			/* restrict by family, since later Xeons also have L3 ... */
			code = IRWIN;
	}
	if (match_all(bits, XEON_ + _MP_) && data->l3_cache > 0)
		code = POTOMAC;
	if (code == CORE_SOLO) {
		s = strstr(bs, "CPU");
		if (s) {
			s += 3;
			while (*s == ' ') s++;
			if (*s == 'T')
				bits |= MOBILE_;
		}
	}
	if (code == CORE_SOLO) {
		switch (data->num_cores) {
			case 1: break;
			case 2:
			{
				code = CORE_DUO;
				if (data->num_logical_cpus > 2)
					code = DUAL_CORE_HT;
				break;
			}
			case 4:
			{
				code = QUAD_CORE;
				if (data->num_logical_cpus > 4)
					code = QUAD_CORE_HT;
				break;
			}
			default:
				code = MORE_THAN_QUADCORE; break;
		}
	}

	if (code == CORE_DUO && (bits & MOBILE_) && data->model != 14) {
		if (data->ext_model < 23) {
			code = MEROM;
		} else {
			code = PENRYN;
		}
	}
	if (data->ext_model == 23 &&
		(code == CORE_DUO || code == PENTIUM_D || (bits & CELERON_))) {
		code = WOLFDALE;
	}

	result.code = code;
	result.bits = bits;
	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x5a790
movq %rax, -0x48(%rbp)
leaq -0xf0(%rbp), %rdi
leaq 0xce9e4(%rip), %rsi     # 0x207e30
movl $0xa0, %edx
callq 0x593a0
leaq -0x1a0(%rbp), %rdi
leaq 0xcea6c(%rip), %rsi     # 0x207ed0
movl $0xb0, %edx
callq 0x593a0
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
cmpq $0xb, %rax
jae 0x1394cd
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x135ec0
cmpl $0x0, %eax
je 0x1394c0
movslq -0x2c(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
orq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1394c2
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x139475
movq -0x38(%rbp), %rdi
leaq 0x82acb(%rip), %rsi     # 0x1bbfa3
callq 0x135ec0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x139679
movb -0x27(%rbp), %al
orb $0x10, %al
movb %al, -0x27(%rbp)
movl -0x2c(%rbp), %eax
decl %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movslq -0x2c(%rbp), %rax
movsbl 0x9(%rax,%rcx), %eax
movl %eax, -0x1a4(%rbp)
subl $0x69, %eax
je 0x139520
jmp 0x139513
movl -0x1a4(%rbp), %eax
subl $0x6d, %eax
je 0x139530
jmp 0x13953c
movq -0x28(%rbp), %rax
orq $0x2000, %rax           # imm = 0x2000
movq %rax, -0x28(%rbp)
jmp 0x13953c
movq -0x28(%rbp), %rax
orq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rcx
movslq -0x2c(%rbp), %rax
movsbl 0xa(%rax,%rcx), %eax
addl $-0x33, %eax
movl %eax, %ecx
movq %rcx, -0x1b0(%rbp)
subl $0x6, %eax
ja 0x1395a7
movq -0x1b0(%rbp), %rax
leaq 0x77a74(%rip), %rcx     # 0x1b0fdc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
orq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x1395a7
movq -0x28(%rbp), %rax
orq $0x10, %rax
movq %rax, -0x28(%rbp)
jmp 0x1395a7
movq -0x28(%rbp), %rax
orq $0x20, %rax
movq %rax, -0x28(%rbp)
jmp 0x1395a7
movq -0x28(%rbp), %rax
orq $0x40, %rax
movq %rax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0xb, %eax
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x139674
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl $-0x48, %eax
movl %eax, %ecx
movq %rcx, -0x1b8(%rbp)
subl $0x10, %eax
ja 0x139664
movq -0x1b8(%rbp), %rax
leaq 0x77a0b(%rip), %rcx     # 0x1b0ff8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
orq $0x80, %rax
movq %rax, -0x28(%rbp)
jmp 0x139664
movq -0x28(%rbp), %rax
orq $0x10000, %rax          # imm = 0x10000
movq %rax, -0x28(%rbp)
jmp 0x139664
movq -0x28(%rbp), %rax
orq $0x40000, %rax          # imm = 0x40000
movq %rax, -0x28(%rbp)
jmp 0x139664
movq -0x28(%rbp), %rax
orq $0x20000, %rax          # imm = 0x20000
movq %rax, -0x28(%rbp)
jmp 0x139664
movq -0x28(%rbp), %rax
orq $0x100, %rax            # imm = 0x100
movq %rax, -0x28(%rbp)
jmp 0x139664
movq -0x28(%rbp), %rax
orq $0x200, %rax            # imm = 0x200
movq %rax, -0x28(%rbp)
jmp 0x139664
movq -0x28(%rbp), %rax
orq $0x400, %rax            # imm = 0x400
movq %rax, -0x28(%rbp)
jmp 0x139666
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1395b0
jmp 0x1397a5
movq -0x38(%rbp), %rdi
leaq 0x82933(%rip), %rsi     # 0x1bbfb7
callq 0x135ec0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x139732
movb -0x27(%rbp), %al
orb $0x40, %al
movb %al, -0x27(%rbp)
movl -0x2c(%rbp), %eax
decl %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movslq -0x2c(%rbp), %rax
movb 0x8(%rax,%rcx), %al
subb $0x77, %al
jne 0x1396c5
jmp 0x1396b7
movq -0x28(%rbp), %rax
orq $0x80000, %rax          # imm = 0x80000
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rcx
movslq -0x2c(%rbp), %rax
movsbl 0x9(%rax,%rcx), %eax
addl $-0x33, %eax
movl %eax, %ecx
movq %rcx, -0x1c0(%rbp)
subl $0x6, %eax
ja 0x139730
movq -0x1c0(%rbp), %rax
leaq 0x778cf(%rip), %rcx     # 0x1b0fc0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
orq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x139730
movq -0x28(%rbp), %rax
orq $0x10, %rax
movq %rax, -0x28(%rbp)
jmp 0x139730
movq -0x28(%rbp), %rax
orq $0x20, %rax
movq %rax, -0x28(%rbp)
jmp 0x139730
movq -0x28(%rbp), %rax
orq $0x40, %rax
movq %rax, -0x28(%rbp)
jmp 0x1397a3
movq -0x38(%rbp), %rdi
leaq 0x8288a(%rip), %rsi     # 0x1bbfc7
callq 0x135ec0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x1397a1
movb -0x27(%rbp), %al
orb $0x40, %al
movb %al, -0x27(%rbp)
movl -0x2c(%rbp), %eax
decl %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movslq -0x2c(%rbp), %rax
movsbl 0x8(%rax,%rcx), %eax
movl %eax, -0x1c4(%rbp)
subl $0x44, %eax
je 0x139781
jmp 0x139774
movl -0x1c4(%rbp), %eax
subl $0x57, %eax
je 0x139791
jmp 0x13979f
movq -0x28(%rbp), %rax
orq $0x100000, %rax         # imm = 0x100000
movq %rax, -0x28(%rbp)
jmp 0x13979f
movq -0x28(%rbp), %rax
orq $0x80000, %rax          # imm = 0x80000
movq %rax, -0x28(%rbp)
jmp 0x1397a1
jmp 0x1397a3
jmp 0x1397a5
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
cmpq $0xa, %rax
jae 0x139800
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq -0xf0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x135ec0
cmpl $0x0, %eax
je 0x1397f3
movslq -0x2c(%rbp), %rcx
leaq -0xf0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
jmp 0x139800
jmp 0x1397f5
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1397ac
movl -0x1c(%rbp), %edx
movl $0x2, %edi
leaq 0x827c5(%rip), %rsi     # 0x1bbfd4
movb $0x0, %al
callq 0x135780
movq -0x28(%rbp), %rax
andq $0x4000, %rax           # imm = 0x4000
cmpq $0x0, %rax
je 0x1398c7
movq -0x38(%rbp), %rdi
leaq 0x827be(%rip), %rsi     # 0x1bbff3
callq 0x135ec0
cmpl $0x0, %eax
jne 0x139854
movq -0x38(%rbp), %rdi
leaq 0x827af(%rip), %rsi     # 0x1bbff9
callq 0x135ec0
cmpl $0x0, %eax
je 0x139862
movq -0x28(%rbp), %rax
orq $0x20, %rax
movq %rax, -0x28(%rbp)
jmp 0x1398c5
movq -0x38(%rbp), %rdi
leaq 0x82797(%rip), %rsi     # 0x1bc004
callq 0x135ec0
cmpl $0x0, %eax
je 0x139880
movl $0x7d3, -0x1c(%rbp)     # imm = 0x7D3
jmp 0x1398c3
movq -0x38(%rbp), %rdi
leaq 0x82784(%rip), %rsi     # 0x1bc00f
callq 0x135ec0
cmpl $0x0, %eax
je 0x13989e
movl $0x7d4, -0x1c(%rbp)     # imm = 0x7D4
jmp 0x1398c1
movq -0x18(%rbp), %rax
cmpl $0x0, 0x104(%rax)
jle 0x1398bf
movq -0x18(%rbp), %rax
cmpl $0x10, 0xd8(%rax)
jne 0x1398bf
movl $0x7d1, -0x1c(%rbp)     # imm = 0x7D1
jmp 0x1398c1
jmp 0x1398c3
jmp 0x1398c5
jmp 0x1398c7
movq -0x28(%rbp), %rdi
movl $0x4004, %esi           # imm = 0x4004
callq 0x136190
cmpl $0x0, %eax
je 0x1398ee
movq -0x18(%rbp), %rax
cmpl $0x0, 0x104(%rax)
jle 0x1398ee
movl $0x7d2, -0x1c(%rbp)     # imm = 0x7D2
cmpl $0x7d7, -0x1c(%rbp)     # imm = 0x7D7
jne 0x139954
movq -0x38(%rbp), %rdi
leaq 0x825ff(%rip), %rsi     # 0x1bbf01
callq 0x5ab80
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x139952
movq -0x40(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x139938
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x13991e
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x54, %eax
jne 0x139950
movq -0x28(%rbp), %rax
orq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x139952
jmp 0x139954
cmpl $0x7d7, -0x1c(%rbp)     # imm = 0x7D7
jne 0x1399d3
movq -0x18(%rbp), %rax
movl 0xec(%rax), %eax
movl %eax, -0x1c8(%rbp)
subl $0x1, %eax
je 0x13998e
jmp 0x139974
movl -0x1c8(%rbp), %eax
subl $0x2, %eax
je 0x139990
jmp 0x139981
movl -0x1c8(%rbp), %eax
subl $0x4, %eax
je 0x1399ad
jmp 0x1399ca
jmp 0x1399d1
movl $0x7d9, -0x1c(%rbp)     # imm = 0x7D9
movq -0x18(%rbp), %rax
cmpl $0x2, 0xf0(%rax)
jle 0x1399ab
movl $0x7df, -0x1c(%rbp)     # imm = 0x7DF
jmp 0x1399d1
movl $0x7de, -0x1c(%rbp)     # imm = 0x7DE
movq -0x18(%rbp), %rax
cmpl $0x4, 0xf0(%rax)
jle 0x1399c8
movl $0x7e0, -0x1c(%rbp)     # imm = 0x7E0
jmp 0x1399d1
movl $0x7e1, -0x1c(%rbp)     # imm = 0x7E1
jmp 0x1399d3
cmpl $0x7d9, -0x1c(%rbp)     # imm = 0x7D9
jne 0x139a16
movq -0x28(%rbp), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x139a16
movq -0x18(%rbp), %rax
cmpl $0xe, 0xdc(%rax)
je 0x139a16
movq -0x18(%rbp), %rax
cmpl $0x17, 0xe8(%rax)
jge 0x139a0d
movl $0x7dc, -0x1c(%rbp)     # imm = 0x7DC
jmp 0x139a14
movl $0x7dd, -0x1c(%rbp)     # imm = 0x7DD
jmp 0x139a16
movq -0x18(%rbp), %rax
cmpl $0x17, 0xe8(%rax)
jne 0x139a4c
cmpl $0x7d9, -0x1c(%rbp)     # imm = 0x7D9
je 0x139a45
cmpl $0x7e2, -0x1c(%rbp)     # imm = 0x7E2
je 0x139a45
movq -0x28(%rbp), %rax
andq $0x800, %rax            # imm = 0x800
cmpq $0x0, %rax
je 0x139a4c
movl $0x7db, -0x1c(%rbp)     # imm = 0x7DB
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rdx
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopw (%rax,%rax)