#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 /*<<< orphan*/ tmp;

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ cache_info(int, int, char *, int);
unsigned int generic_cache_assoc(int, int);
char *strstr(char *, char *);
unsigned int cache_assoc(int cpu, int id) {
  char tmp[512];
  char *beg, *end;
  cache_info(cpu, id, tmp, sizeof(tmp));
  beg = strstr(tmp, ",") + 1;
  if (beg == NULL)
    return generic_cache_assoc(cpu, id);
  else
    beg++;
  end = strstr(beg, ",") + 1;
  if (end == NULL)
    return generic_cache_assoc(cpu, id);
  else
    end++;
  beg = end;
  end = strstr(beg, ",");
  if (end != NULL)
    *end = '\0';
  end = strstr(tmp, "-way");
  if (end != NULL) {
    *end = '\0';
    return atoi(beg);
  }
  end = strstr(tmp, "fully");
  if (end != NULL) {
    *end = '\0';
    return 0x10;
  }
  return generic_cache_assoc(cpu, id);
}


x86 assembly (clang, -O0):
<cache_assoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x210(%rbp),%rdx
mov    $0x200,%ecx
call   1030 <cache_info@plt>
lea    -0x210(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11a7 <cache_assoc+0x67>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cache_assoc@plt>
mov    %eax,-0x4(%rbp)
jmp    12dc <cache_assoc+0x19c>
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1060 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    11f8 <cache_assoc+0xb8>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cache_assoc@plt>
mov    %eax,-0x4(%rbp)
jmp    12dc <cache_assoc+0x19c>
mov    -0x220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     124a <cache_assoc+0x10a>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     1290 <cache_assoc+0x150>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    12dc <cache_assoc+0x19c>
lea    -0x210(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     12ce <cache_assoc+0x18e>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x10,-0x4(%rbp)
jmp    12dc <cache_assoc+0x19c>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cache_assoc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_assoc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdx
mov    $0x200,%ecx
call   1030 <cache_info@plt>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
lea    0x2(%rax),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a7 <cache_assoc+0x57>
movb   $0x0,(%rax)
lea    0xe52(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11c8 <cache_assoc+0x78>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1060 <atoi@plt>
jmp    11f0 <cache_assoc+0xa0>
lea    0xe36(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11e6 <cache_assoc+0x96>
movb   $0x0,(%rax)
mov    $0x10,%eax
jmp    11f0 <cache_assoc+0xa0>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <generic_cache_assoc@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [5 x i8] c"-way\00"
@.str.2 = [6 x i8] c"fully\00"
define i32 @cache_assoc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = call i32 @cache_info(i32 %9, i32 %10, i8* %11, i32 512)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = call i32 @generic_cache_assoc(i32 %19, i32 %20)
store i32 %21, i32* %3
br label %66
22: ; preds = %2
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
br label %25
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = call i32 @generic_cache_assoc(i32 %32, i32 %33)
store i32 %34, i32* %3
br label %66
35: ; preds = %25
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %8
br label %38
38: ; preds = %35
%39 = load i8*, i8** %8
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = load i8*, i8** %8
store i8 0, i8* %45
br label %46
46: ; preds = %44, %38
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%48 = call i8* @strstr(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %48, i8** %8
%49 = load i8*, i8** %8
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = load i8*, i8** %8
store i8 0, i8* %52
%53 = load i8*, i8** %7
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %3
br label %66
55: ; preds = %46
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%57 = call i8* @strstr(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %57, i8** %8
%58 = load i8*, i8** %8
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = load i8*, i8** %8
store i8 0, i8* %61
store i32 16, i32* %3
br label %66
62: ; preds = %55
%63 = load i32, i32* %4
%64 = load i32, i32* %5
%65 = call i32 @generic_cache_assoc(i32 %63, i32 %64)
store i32 %65, i32* %3
br label %66
66: ; preds = %62, %60, %51, %31, %18
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"-way\00"
@.str.2 = [6 x i8] c"fully\00"
define i32 @cache_assoc(i32 %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @cache_info(i32 %0, i32 %1, i8* %4, i32 512)
%6 = call i8* @strchr(i8* %4, i32 44)
%7 = getelementptr inbounds i8, i8* %6, i64 2
%8 = call i8* @strchr(i8* %7, i32 44)
%9 = getelementptr inbounds i8, i8* %8, i64 2
%10 = call i8* @strchr(i8* %9, i32 44)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i8 0, i8* %10
br label %13
13: ; preds = %12, %2
%14 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %13
store i8 0, i8* %14
%17 = call i32 @atoi(i8* %9)
br label %24
18: ; preds = %13
%19 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %18
store i8 0, i8* %19
br label %24
22: ; preds = %18
%23 = call i32 @generic_cache_assoc(i32 %0, i32 %1)
br label %24
24: ; preds = %22, %21, %16
%25 = phi i32 [ %17, %16 ], [ 16, %21 ], [ %23, %22 ]
ret i32 %25
}