#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_assoc(int size) {
  int i = 0;
  int cache_check = 1;
  int assoc = 0;
  flush_cache();
  access_cache(i);
  while (access_cache(0)) {
    i = size;
    assoc = 0;
    while (i <= cache_check) {
      i += size;
      ++assoc;
      access_cache(i);
    }
    cache_check += size;
  }
  return assoc;
}


x86 assembly (clang, -O0):
<get_cache_assoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%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     11a5 <get_cache_assoc+0x85>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1197 <get_cache_assoc+0x77>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <access_cache@plt>
jmp    116c <get_cache_assoc+0x4c>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    114f <get_cache_assoc+0x2f>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cache_assoc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %r13d,%r13d
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     11a8 <get_cache_assoc+0x88>
lea    (%r14,%r14,1),%r15d
mov    $0x1,%r12d
jmp    116e <get_cache_assoc+0x4e>
cs nopw 0x0(%rax,%rax,1)
add    %r14d,%r12d
xor    %edi,%edi
call   1030 <access_cache@plt>
test   %eax,%eax
je     11a8 <get_cache_assoc+0x88>
mov    $0x0,%r13d
cmp    %r14d,%r12d
jl     1160 <get_cache_assoc+0x40>
xor    %r13d,%r13d
mov    %r15d,%ebx
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r14d,%ebp
add    $0x1,%r13d
mov    %ebx,%edi
call   1030 <access_cache@plt>
add    %r14d,%ebx
cmp    %r12d,%ebp
jle    1190 <get_cache_assoc+0x70>
jmp    1160 <get_cache_assoc+0x40>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_cache_assoc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
store i32 0, i32* %5
%6 = call i32 (...) @flush_cache()
%7 = load i32, i32* %3
%8 = call i32 @access_cache(i32 %7)
br label %9
9: ; preds = %26, %1
%10 = call i32 @access_cache(i32 0)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = load i32, i32* %2
store i32 %13, i32* %3
store i32 0, i32* %5
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 %26
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* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = call i32 @access_cache(i32 %24)
br label %14
26: ; preds = %14
%27 = load i32, i32* %2
%28 = load i32, i32* %4
%29 = add nsw i32 %28, %27
store i32 %29, i32* %4
br label %9
30: ; preds = %9
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
define i32 @get_cache_assoc(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 %21, label %6
6: ; preds = %1, %16
%7 = phi i32 [ %18, %16 ], [ 1, %1 ]
%8 = icmp slt i32 %7, %0
br i1 %8, label %16, label %9
9: ; preds = %6, %9
%10 = phi i32 [ %13, %9 ], [ 0, %6 ]
%11 = phi i32 [ %12, %9 ], [ %0, %6 ]
%12 = add nsw i32 %11, %0
%13 = add nuw nsw i32 %10, 1
%14 = tail call i32 @access_cache(i32 %12)
%15 = icmp sgt i32 %12, %7
br i1 %15, label %16, label %9
16: ; preds = %9, %6
%17 = phi i32 [ 0, %6 ], [ %13, %9 ]
%18 = add nsw i32 %7, %0
%19 = tail call i32 @access_cache(i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %6
21: ; preds = %16, %1
%22 = phi i32 [ 0, %1 ], [ %17, %16 ]
ret i32 %22
}