#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 */
int atoi(char *);
int /*<<< orphan*/ generic_cache_info(int, int, char *, int);
char *strstr(char *, char *);
unsigned long long generic_cache_size(int cpu, int id) {
  char tmp[512];
  char *beg, *end;
  generic_cache_info(cpu, id, tmp, sizeof(tmp));
  beg = strstr(tmp, ",");
  if (beg == NULL)
    return -1;
  else
    beg += 2;
  end = strstr(beg, ",");
  if (end != NULL)
    *end = '\0';
  end = strstr(beg, "K");
  if (end != NULL) {
    end--;
    *end = '\0';
    return atoi(beg) * 1024;
  }
  end = strstr(beg, "M");
  if (end != NULL) {
    end--;
    *end = '\0';
    return atoi(beg) * 1024 * 1024;
  }
  return -1;
}


x86 assembly (clang, -O0):
<generic_cache_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%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>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    118d <generic_cache_size+0x5d>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1298 <generic_cache_size+0x168>
mov    -0x218(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     11d1 <generic_cache_size+0xa1>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     122f <generic_cache_size+0xff>
mov    -0x220(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rdi
call   1040 <atoi@plt>
shl    $0xa,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1298 <generic_cache_size+0x168>
mov    -0x218(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     1290 <generic_cache_size+0x160>
mov    -0x220(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rdi
call   1040 <atoi@plt>
shl    $0xa,%eax
shl    $0xa,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1298 <generic_cache_size+0x168>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_cache_size>:
push   %rbp
push   %r14
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>
mov    $0xffffffffffffffff,%r14
test   %rax,%rax
je     11c3 <generic_cache_size+0x93>
mov    %rax,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1180 <generic_cache_size+0x50>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x4b,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1199 <generic_cache_size+0x69>
mov    $0xa,%ebp
jmp    11b0 <generic_cache_size+0x80>
mov    %rbx,%rdi
mov    $0x4d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11c3 <generic_cache_size+0x93>
mov    $0x14,%ebp
movb   $0x0,-0x1(%rax)
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %ebp,%ecx
shl    %cl,%eax
movslq %eax,%r14
mov    %r14,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [2 x i8] c"M\00"
define i64 @generic_cache_size(i32 %0, i32 %1) {
%3 = alloca i64
%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))
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i64 -1, i64* %3
br label %56
18: ; preds = %2
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 2
store i8* %20, i8** %7
br label %21
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = load i8*, i8** %8
store i8 0, i8* %27
br label %28
28: ; preds = %26, %21
%29 = load i8*, i8** %7
%30 = call i8* @strstr(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %28
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %8
%36 = load i8*, i8** %8
store i8 0, i8* %36
%37 = load i8*, i8** %7
%38 = call i32 @atoi(i8* %37)
%39 = mul nsw i32 %38, 1024
%40 = sext i32 %39 to i64
store i64 %40, i64* %3
br label %56
41: ; preds = %28
%42 = load i8*, i8** %7
%43 = call i8* @strstr(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %55
46: ; preds = %41
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i32 -1
store i8* %48, i8** %8
%49 = load i8*, i8** %8
store i8 0, i8* %49
%50 = load i8*, i8** %7
%51 = call i32 @atoi(i8* %50)
%52 = mul nsw i32 %51, 1024
%53 = mul nsw i32 %52, 1024
%54 = sext i32 %53 to i64
store i64 %54, i64* %3
br label %56
55: ; preds = %41
store i64 -1, i64* %3
br label %56
56: ; preds = %55, %46, %33, %17
%57 = load i64, i64* %3
ret i64 %57
}

LLVM IR (-O2):
define i64 @generic_cache_size(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 = icmp eq i8* %6, null
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %6, 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 = %8
store i8 0, i8* %10
br label %13
13: ; preds = %12, %8
%14 = call i8* @strchr(i8* %9, i32 75)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i8* @strchr(i8* %9, i32 77)
%18 = icmp eq i8* %17, null
br i1 %18, label %26, label %19
19: ; preds = %16, %13
%20 = phi i8* [ %14, %13 ], [ %17, %16 ]
%21 = phi i32 [ 10, %13 ], [ 20, %16 ]
%22 = getelementptr inbounds i8, i8* %20, i64 -1
store i8 0, i8* %22
%23 = call i32 @atoi(i8* %9)
%24 = shl nsw i32 %23, %21
%25 = sext i32 %24 to i64
br label %26
26: ; preds = %19, %16, %2
%27 = phi i64 [ -1, %2 ], [ -1, %16 ], [ %25, %19 ]
ret i64 %27
}