#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*/ generic_cache_info(int, int, char *, int);
char *strstr(char *, char *);
unsigned int generic_cache_assoc(int cpu, int id) {
  char tmp[512];
  char *beg, *end;
  generic_cache_info(cpu, id, tmp, sizeof(tmp));
  beg = strstr(tmp, ",") + 1;
  if (beg == NULL)
    return -1;
  else
    beg++;
  end = strstr(beg, ",") + 1;
  if (end == NULL)
    return -1;
  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 -1;
}


x86 assembly (clang, -O0):
<generic_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 <generic_cache_info@plt>
lea    -0x210(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    1190 <generic_cache_assoc+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <generic_cache_assoc+0x187>
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1050 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    11da <generic_cache_assoc+0xaa>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <generic_cache_assoc+0x187>
mov    -0x220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     122c <generic_cache_assoc+0xfc>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     1272 <generic_cache_assoc+0x142>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    12b7 <generic_cache_assoc+0x187>
lea    -0x210(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     12b0 <generic_cache_assoc+0x180>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x10,-0x4(%rbp)
jmp    12b7 <generic_cache_assoc+0x187>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_cache_assoc>:
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdx
mov    $0x200,%ecx
call   1040 <generic_cache_info@plt>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
lea    0x2(%rax),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     118f <generic_cache_assoc+0x4f>
movb   $0x0,(%rax)
lea    0xe6a(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11b0 <generic_cache_assoc+0x70>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <atoi@plt>
jmp    11d3 <generic_cache_assoc+0x93>
lea    0xe4e(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11ce <generic_cache_assoc+0x8e>
movb   $0x0,(%rax)
mov    $0x10,%eax
jmp    11d3 <generic_cache_assoc+0x93>
mov    $0xffffffff,%eax
add    $0x200,%rsp
pop    %rbx
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 @generic_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 @generic_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 %19
18: ; preds = %2
store i32 -1, i32* %3
br label %57
19: ; preds = %2
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %7
br label %22
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = call i8* @strstr(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 -1, i32* %3
br label %57
29: ; preds = %22
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %8
br label %32
32: ; preds = %29
%33 = load i8*, i8** %8
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = call i8* @strstr(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = load i8*, i8** %8
store i8 0, i8* %39
br label %40
40: ; preds = %38, %32
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%42 = call i8* @strstr(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i8*, i8** %8
store i8 0, i8* %46
%47 = load i8*, i8** %7
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %3
br label %57
49: ; preds = %40
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%51 = call i8* @strstr(i8* %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %51, i8** %8
%52 = load i8*, i8** %8
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = load i8*, i8** %8
store i8 0, i8* %55
store i32 16, i32* %3
br label %57
56: ; preds = %49
store i32 -1, i32* %3
br label %57
57: ; preds = %56, %54, %45, %28, %18
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"-way\00"
@.str.2 = [6 x i8] c"fully\00"
define i32 @generic_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 @generic_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 %22
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 %22
22: ; preds = %18, %21, %16
%23 = phi i32 [ %17, %16 ], [ 16, %21 ], [ -1, %18 ]
ret i32 %23
}