#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint32_t;
struct cache_description {
  int dummy;
};

/* Variables and functions */
scalar_t__ cpu_check_cache_list_by_register(struct cache_description const *,
                                            int, int *, int *);
int /*<<< orphan*/ cpuid(int, int *, int *, int *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *);
int /*<<< orphan*/ stderr;
void cpu_cache_size(const struct cache_description *ctab, uint32_t *cache_size,
                    uint32_t *cache_line) {
  uint32_t local_eax;
  uint32_t local_ebx;
  uint32_t local_ecx;
  uint32_t local_edx;
  unsigned int index;
  unsigned int max;
  (void)fprintf(stderr, "cpu_cache_size: %p\n", (void *)ctab);
  if (ctab) {
    cpuid(0x00000002u, &local_eax, &local_ebx, &local_ecx, &local_edx);
    max = local_eax & 0xff;
    for (index = 0; index < max; ++index) {
      cpuid(0x00000002u, &local_eax, &local_ebx, &local_ecx, &local_edx);
      local_eax = (local_eax & 0x80000000u) ? 0 : local_eax;
      local_ebx = (local_ebx & 0x80000000u) ? 0 : local_ebx;
      local_ecx = (local_ecx & 0x80000000u) ? 0 : local_ecx;
      local_edx = (local_edx & 0x80000000u) ? 0 : local_edx;
      if (cpu_check_cache_list_by_register(ctab, local_eax, cache_size,
                                           cache_line))
        return;
      if (cpu_check_cache_list_by_register(ctab, local_ebx, cache_size,
                                           cache_line))
        return;
      if (cpu_check_cache_list_by_register(ctab, local_ecx, cache_size,
                                           cache_line))
        return;
      if (cpu_check_cache_list_by_register(ctab, local_edx, cache_size,
                                           cache_line))
        return;
    }
  }
}


x86 assembly (clang, -O0):
<cpu_cache_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     12fa <cpu_cache_size+0x1ca>
mov    $0x2,%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1050 <cpuid@plt>
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jae    12f5 <cpu_cache_size+0x1c5>
mov    $0x2,%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1050 <cpuid@plt>
mov    -0x1c(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     11d5 <cpu_cache_size+0xa5>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    11db <cpu_cache_size+0xab>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     11fc <cpu_cache_size+0xcc>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    1202 <cpu_cache_size+0xd2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1223 <cpu_cache_size+0xf3>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    1229 <cpu_cache_size+0xf9>
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     124a <cpu_cache_size+0x11a>
xor    %eax,%eax
mov    %eax,-0x40(%rbp)
jmp    1250 <cpu_cache_size+0x120>
mov    -0x28(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
cmp    $0x0,%rax
je     1279 <cpu_cache_size+0x149>
jmp    12fa <cpu_cache_size+0x1ca>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
cmp    $0x0,%rax
je     129c <cpu_cache_size+0x16c>
jmp    12fa <cpu_cache_size+0x1ca>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
cmp    $0x0,%rax
je     12bf <cpu_cache_size+0x18f>
jmp    12fa <cpu_cache_size+0x1ca>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
cmp    $0x0,%rax
je     12e2 <cpu_cache_size+0x1b2>
jmp    12fa <cpu_cache_size+0x1ca>
jmp    12e7 <cpu_cache_size+0x1b7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1194 <cpu_cache_size+0x64>
jmp    12fa <cpu_cache_size+0x1ca>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_cache_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
test   %rbx,%rbx
je     125c <cpu_cache_size+0x12c>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    $0x2,%edi
call   1050 <cpuid@plt>
movzbl 0x14(%rsp),%r13d
test   %r13d,%r13d
je     125c <cpu_cache_size+0x12c>
mov    $0x1,%ebp
xor    %r12d,%r12d
nopl   (%rax)
mov    $0x2,%edi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1050 <cpuid@plt>
mov    0x14(%rsp),%esi
test   %esi,%esi
cmovs  %r12d,%esi
mov    0x10(%rsp),%eax
test   %eax,%eax
cmovs  %r12d,%eax
mov    %esi,0x14(%rsp)
mov    %eax,0x10(%rsp)
mov    0xc(%rsp),%eax
test   %eax,%eax
cmovs  %r12d,%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%eax
test   %eax,%eax
cmovs  %r12d,%eax
mov    %eax,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
test   %rax,%rax
jne    125c <cpu_cache_size+0x12c>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
test   %rax,%rax
jne    125c <cpu_cache_size+0x12c>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
test   %rax,%rax
jne    125c <cpu_cache_size+0x12c>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <cpu_check_cache_list_by_register@plt>
test   %rax,%rax
jne    125c <cpu_cache_size+0x12c>
lea    0x1(%rbp),%eax
cmp    %r13d,%ebp
mov    %eax,%ebp
jb     11a0 <cpu_cache_size+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cache_description = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"cpu_cache_size: %p\0A\00"
define void @cpu_cache_size(%struct.cache_description* %0, i32* %1, i32* %2) {
%4 = alloca %struct.cache_description*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.cache_description* %0, %struct.cache_description** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%13 = load i32, i32* @stderr
%14 = load %struct.cache_description*, %struct.cache_description** %4
%15 = bitcast %struct.cache_description* %14 to i8*
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load %struct.cache_description*, %struct.cache_description** %4
%18 = icmp ne %struct.cache_description* %17, null
br i1 %18, label %19, label %97
19: ; preds = %3
%20 = call i32 @cpuid(i32 2, i32* %7, i32* %8, i32* %9, i32* %10)
%21 = load i32, i32* %7
%22 = and i32 %21, 255
store i32 %22, i32* %12
store i32 0, i32* %11
br label %23
23: ; preds = %93, %19
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %96
27: ; preds = %23
%28 = call i32 @cpuid(i32 2, i32* %7, i32* %8, i32* %9, i32* %10)
%29 = load i32, i32* %7
%30 = and i32 %29, -2147483648
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
br label %35
33: ; preds = %27
%34 = load i32, i32* %7
br label %35
35: ; preds = %33, %32
%36 = phi i32 [ 0, %32 ], [ %34, %33 ]
store i32 %36, i32* %7
%37 = load i32, i32* %8
%38 = and i32 %37, -2147483648
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %43
41: ; preds = %35
%42 = load i32, i32* %8
br label %43
43: ; preds = %41, %40
%44 = phi i32 [ 0, %40 ], [ %42, %41 ]
store i32 %44, i32* %8
%45 = load i32, i32* %9
%46 = and i32 %45, -2147483648
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
br label %51
49: ; preds = %43
%50 = load i32, i32* %9
br label %51
51: ; preds = %49, %48
%52 = phi i32 [ 0, %48 ], [ %50, %49 ]
store i32 %52, i32* %9
%53 = load i32, i32* %10
%54 = and i32 %53, -2147483648
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %51
br label %59
57: ; preds = %51
%58 = load i32, i32* %10
br label %59
59: ; preds = %57, %56
%60 = phi i32 [ 0, %56 ], [ %58, %57 ]
store i32 %60, i32* %10
%61 = load %struct.cache_description*, %struct.cache_description** %4
%62 = load i32, i32* %7
%63 = load i32*, i32** %5
%64 = load i32*, i32** %6
%65 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %61, i32 %62, i32* %63, i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %59
br label %97
68: ; preds = %59
%69 = load %struct.cache_description*, %struct.cache_description** %4
%70 = load i32, i32* %8
%71 = load i32*, i32** %5
%72 = load i32*, i32** %6
%73 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %69, i32 %70, i32* %71, i32* %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %68
br label %97
76: ; preds = %68
%77 = load %struct.cache_description*, %struct.cache_description** %4
%78 = load i32, i32* %9
%79 = load i32*, i32** %5
%80 = load i32*, i32** %6
%81 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %77, i32 %78, i32* %79, i32* %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %76
br label %97
84: ; preds = %76
%85 = load %struct.cache_description*, %struct.cache_description** %4
%86 = load i32, i32* %10
%87 = load i32*, i32** %5
%88 = load i32*, i32** %6
%89 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %85, i32 %86, i32* %87, i32* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %92
91: ; preds = %84
br label %97
92: ; preds = %84
br label %93
93: ; preds = %92
%94 = load i32, i32* %11
%95 = add i32 %94, 1
store i32 %95, i32* %11
br label %23
96: ; preds = %23
br label %97
97: ; preds = %67, %75, %83, %91, %96, %3
ret void
}

LLVM IR (-O2):
%struct.cache_description = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"cpu_cache_size: %p\0A\00"
define void @cpu_cache_size(%struct.cache_description* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = load i32, i32* @stderr
%13 = bitcast %struct.cache_description* %0 to i8*
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = icmp eq %struct.cache_description* %0, null
br i1 %15, label %53, label %16
16: ; preds = %3
%17 = call i32 @cpuid(i32 2, i32* %4, i32* %5, i32* %6, i32* %7)
%18 = load i32, i32* %4
%19 = and i32 %18, 255
%20 = icmp eq i32 %19, 0
br i1 %20, label %53, label %21
21: ; preds = %16, %46
%22 = phi i32 [ %50, %46 ], [ 0, %16 ]
%23 = call i32 @cpuid(i32 2, i32* %4, i32* %5, i32* %6, i32* %7)
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 0
%26 = select i1 %25, i32 %24, i32 0
store i32 %26, i32* %4
%27 = load i32, i32* %5
%28 = icmp sgt i32 %27, 0
%29 = select i1 %28, i32 %27, i32 0
store i32 %29, i32* %5
%30 = load i32, i32* %6
%31 = icmp sgt i32 %30, 0
%32 = select i1 %31, i32 %30, i32 0
store i32 %32, i32* %6
%33 = load i32, i32* %7
%34 = icmp sgt i32 %33, 0
%35 = select i1 %34, i32 %33, i32 0
store i32 %35, i32* %7
%36 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %0, i32 %26, i32* %1, i32* %2)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %21
%39 = load i32, i32* %5
%40 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %0, i32 %39, i32* %1, i32* %2)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %38
%43 = load i32, i32* %6
%44 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %0, i32 %43, i32* %1, i32* %2)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i32, i32* %7
%48 = call i64 @cpu_check_cache_list_by_register(%struct.cache_description* %0, i32 %47, i32* %1, i32* %2)
%49 = icmp eq i64 %48, 0
%50 = add nuw nsw i32 %22, 1
%51 = icmp ult i32 %50, %19
%52 = select i1 %49, i1 %51, i1 false
br i1 %52, label %21, label %53
53: ; preds = %21, %38, %42, %46, %16, %3
ret void
}