#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 *);
int generic_cache_level(int cpu, int id) {
  char tmp[512];
  char *beg, *end;
  generic_cache_info(cpu, id, tmp, sizeof(tmp));
  beg = strstr(tmp, "Level");
  if (beg == NULL)
    return -1;
  else
    beg += 6;
  end = strstr(beg, " ");
  if (end != NULL)
    *end = '\0';
  return atoi(beg);
}


x86 assembly (clang, -O0):
<generic_cache_level>:
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>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    118c <generic_cache_level+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <generic_cache_level+0xaf>
mov    -0x218(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     11d0 <generic_cache_level+0xa0>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_cache_level>:
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdx
mov    $0x200,%ecx
call   1040 <generic_cache_info@plt>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     1192 <generic_cache_level+0x52>
mov    %rax,%rbx
add    $0x6,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1188 <generic_cache_level+0x48>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <atoi@plt>
jmp    1197 <generic_cache_level+0x57>
mov    $0xffffffff,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Level\00"
@.str.1 = [2 x i8] c" \00"
define i32 @generic_cache_level(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 ([6 x i8], [6 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 i32 -1, i32* %3
br label %31
18: ; preds = %2
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 6
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.1, 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 i32 @atoi(i8* %29)
store i32 %30, i32* %3
br label %31
31: ; preds = %28, %17
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"Level\00"
define i32 @generic_cache_level(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* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %6, i64 6
%10 = call i8* @strchr(i8* %9, i32 32)
%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 i32 @atoi(i8* %9)
br label %15
15: ; preds = %2, %13
%16 = phi i32 [ %14, %13 ], [ -1, %2 ]
ret i32 %16
}