#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 /*<<< orphan*/ generic_cache_info(int, int, char *, int);
char *strstr(char *, char *);
int generic_cache_type(int cpu, int id) {
  char tmp[512];
  char *beg, *end;
  generic_cache_info(cpu, id, tmp, sizeof(tmp));
  beg = tmp;
  end = strstr(beg, ",");
  if (end != NULL)
    *end = '\0';
  else
    return -1;
  if (strstr(beg, "Unified") != NULL)
    return 0x03;
  if (strstr(beg, "Trace") != NULL)
    return 0x04;
  if (strstr(beg, "Data") != NULL)
    return 0x02;
  if (strstr(beg, "Instruction") != NULL)
    return 0x01;
  return -1;
}


x86 assembly (clang, -O0):
<generic_cache_type>:
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),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     118d <generic_cache_type+0x6d>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
jmp    1199 <generic_cache_type+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    1244 <generic_cache_type+0x124>
mov    -0x218(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11c2 <generic_cache_type+0xa2>
movl   $0x3,-0x4(%rbp)
jmp    1244 <generic_cache_type+0x124>
mov    -0x218(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11eb <generic_cache_type+0xcb>
movl   $0x4,-0x4(%rbp)
jmp    1244 <generic_cache_type+0x124>
mov    -0x218(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     1214 <generic_cache_type+0xf4>
movl   $0x2,-0x4(%rbp)
jmp    1244 <generic_cache_type+0x124>
mov    -0x218(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     123d <generic_cache_type+0x11d>
movl   $0x1,-0x4(%rbp)
jmp    1244 <generic_cache_type+0x124>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_cache_type>:
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>
test   %rax,%rax
je     11cb <generic_cache_type+0x9b>
movb   $0x0,(%rax)
lea    0xe9c(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strstr@plt>
mov    %rax,%rcx
mov    $0x3,%eax
test   %rcx,%rcx
jne    11d0 <generic_cache_type+0xa0>
lea    0xe88(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strstr@plt>
mov    %rax,%rcx
mov    $0x4,%eax
test   %rcx,%rcx
jne    11d0 <generic_cache_type+0xa0>
lea    0xe72(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strstr@plt>
mov    %rax,%rcx
mov    $0x2,%eax
test   %rcx,%rcx
jne    11d0 <generic_cache_type+0xa0>
lea    0xe5b(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strstr@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     $0x1,%eax
jmp    11d0 <generic_cache_type+0xa0>
mov    $0xffffffff,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [8 x i8] c"Unified\00"
@.str.2 = [6 x i8] c"Trace\00"
@.str.3 = [5 x i8] c"Data\00"
@.str.4 = [12 x i8] c"Instruction\00"
define i32 @generic_cache_type(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
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i8*, i8** %8
store i8 0, i8* %19
br label %21
20: ; preds = %2
store i32 -1, i32* %3
br label %42
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 3, i32* %3
br label %42
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = call i8* @strstr(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 4, i32* %3
br label %42
31: ; preds = %26
%32 = load i8*, i8** %7
%33 = call i8* @strstr(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 2, i32* %3
br label %42
36: ; preds = %31
%37 = load i8*, i8** %7
%38 = call i8* @strstr(i8* %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 1, i32* %3
br label %42
41: ; preds = %36
store i32 -1, i32* %3
br label %42
42: ; preds = %41, %40, %35, %30, %25, %20
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"Unified\00"
@.str.2 = [6 x i8] c"Trace\00"
@.str.3 = [5 x i8] c"Data\00"
@.str.4 = [12 x i8] c"Instruction\00"
define i32 @generic_cache_type(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 %21, label %8
8: ; preds = %2
store i8 0, i8* %6
%9 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i8* %18, null
%20 = select i1 %19, i32 -1, i32 1
br label %21
21: ; preds = %17, %14, %11, %8, %2
%22 = phi i32 [ -1, %2 ], [ 3, %8 ], [ 4, %11 ], [ 2, %14 ], [ %20, %17 ]
ret i32 %22
}