#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 */

/* Variables and functions */
int /*<<< orphan*/ access_cache(int);
int /*<<< orphan*/ flush_cache();
int get_cache_size(int size) {
  int i = 0;
  int cache_check = size;
  flush_cache();
  access_cache(i);
  while (access_cache(0)) {
    i = size;
    while (i <= cache_check) {
      i += size;
      access_cache(i);
    }
    cache_check += size;
  }
  return i;
}


x86 assembly (clang, -O0):
<get_cache_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1040 <flush_cache@plt>
mov    -0x8(%rbp),%edi
call   1030 <access_cache@plt>
xor    %edi,%edi
call   1030 <access_cache@plt>
cmp    $0x0,%eax
je     118d <get_cache_size+0x6d>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     117f <get_cache_size+0x5f>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <access_cache@plt>
jmp    115d <get_cache_size+0x3d>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1147 <get_cache_size+0x27>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cache_size>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <flush_cache@plt>
xor    %edi,%edi
call   1030 <access_cache@plt>
xor    %edi,%edi
call   1030 <access_cache@plt>
test   %eax,%eax
je     1184 <get_cache_size+0x64>
lea    (%r14,%r14,1),%r15d
mov    %r14d,%r12d
jmp    115e <get_cache_size+0x3e>
nop
add    %r14d,%r12d
xor    %edi,%edi
call   1030 <access_cache@plt>
test   %eax,%eax
je     1184 <get_cache_size+0x64>
mov    %r14d,%ebp
cmp    %r14d,%r12d
jl     1150 <get_cache_size+0x30>
mov    %r15d,%ebx
mov    %r14d,%ebp
nopl   0x0(%rax)
add    %r14d,%ebp
mov    %ebx,%edi
call   1030 <access_cache@plt>
add    %r14d,%ebx
cmp    %r12d,%ebp
jle    1170 <get_cache_size+0x50>
jmp    1150 <get_cache_size+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_cache_size(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* %2
store i32 %5, i32* %4
%6 = call i32 (...) @flush_cache()
%7 = load i32, i32* %3
%8 = call i32 @access_cache(i32 %7)
br label %9
9: ; preds = %24, %1
%10 = call i32 @access_cache(i32 0)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i32, i32* %2
store i32 %13, i32* %3
br label %14
14: ; preds = %18, %12
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = call i32 @access_cache(i32 %22)
br label %14
24: ; preds = %14
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = add nsw i32 %26, %25
store i32 %27, i32* %4
br label %9
28: ; preds = %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @get_cache_size(i32 %0) {
%2 = tail call i32 (...) @flush_cache()
%3 = tail call i32 @access_cache(i32 0)
%4 = tail call i32 @access_cache(i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %1, %14
%7 = phi i32 [ %16, %14 ], [ %0, %1 ]
%8 = icmp slt i32 %7, %0
br i1 %8, label %14, label %9
9: ; preds = %6, %9
%10 = phi i32 [ %11, %9 ], [ %0, %6 ]
%11 = add nsw i32 %10, %0
%12 = tail call i32 @access_cache(i32 %11)
%13 = icmp sgt i32 %11, %7
br i1 %13, label %14, label %9
14: ; preds = %9, %6
%15 = phi i32 [ %0, %6 ], [ %11, %9 ]
%16 = add nsw i32 %7, %0
%17 = tail call i32 @access_cache(i32 0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %14, %1
%20 = phi i32 [ 0, %1 ], [ %15, %14 ]
ret i32 %20
}