#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*/ cache_info(int, int, char *, int);
int generic_cache_type(int, int);
char *strstr(char *, char *);
int cache_type(int cpu, int id) {
  char tmp[512];
  char *beg, *end;
  cache_info(cpu, id, tmp, sizeof(tmp));
  beg = tmp;
  end = strstr(beg, ",");
  if (end != NULL)
    *end = '\0';
  else
    return generic_cache_type(cpu, id);
  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 generic_cache_type(cpu, id);
}


x86 assembly (clang, -O0):
<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 <cache_info@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     119d <cache_type+0x6d>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b0 <cache_type+0x80>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cache_type@plt>
mov    %eax,-0x4(%rbp)
jmp    1262 <cache_type+0x132>
mov    -0x218(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11d9 <cache_type+0xa9>
movl   $0x3,-0x4(%rbp)
jmp    1262 <cache_type+0x132>
mov    -0x218(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1202 <cache_type+0xd2>
movl   $0x4,-0x4(%rbp)
jmp    1262 <cache_type+0x132>
mov    -0x218(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     122b <cache_type+0xfb>
movl   $0x2,-0x4(%rbp)
jmp    1262 <cache_type+0x132>
mov    -0x218(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1254 <cache_type+0x124>
movl   $0x1,-0x4(%rbp)
jmp    1262 <cache_type+0x132>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cache_type@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_type>:
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>
test   %rax,%rax
je     11e5 <cache_type+0xa5>
movb   $0x0,(%rax)
lea    0xe84(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
mov    %rax,%rcx
mov    $0x3,%eax
test   %rcx,%rcx
jne    11ef <cache_type+0xaf>
lea    0xe70(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
mov    %rax,%rcx
mov    $0x4,%eax
test   %rcx,%rcx
jne    11ef <cache_type+0xaf>
lea    0xe5a(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
mov    %rax,%rcx
mov    $0x2,%eax
test   %rcx,%rcx
jne    11ef <cache_type+0xaf>
lea    0xe43(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11ef <cache_type+0xaf>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <generic_cache_type@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
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 @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 @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 %24
20: ; preds = %2
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @generic_cache_type(i32 %21, i32 %22)
store i32 %23, i32* %3
br label %48
24: ; preds = %18
%25 = load i8*, i8** %7
%26 = call i8* @strstr(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 3, i32* %3
br label %48
29: ; preds = %24
%30 = load i8*, i8** %7
%31 = call i8* @strstr(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 4, i32* %3
br label %48
34: ; preds = %29
%35 = load i8*, i8** %7
%36 = call i8* @strstr(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 2, i32* %3
br label %48
39: ; preds = %34
%40 = load i8*, i8** %7
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 1, i32* %3
br label %48
44: ; preds = %39
%45 = load i32, i32* %4
%46 = load i32, i32* %5
%47 = call i32 @generic_cache_type(i32 %45, i32 %46)
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %43, %38, %33, %28, %20
%49 = load i32, i32* %3
ret i32 %49
}

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 @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 @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 %20, 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 %22
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 %22
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 %22
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
br i1 %19, label %20, label %22
20: ; preds = %17, %2
%21 = call i32 @generic_cache_type(i32 %0, i32 %1)
br label %22
22: ; preds = %20, %17, %14, %11, %8
%23 = phi i32 [ 3, %8 ], [ 4, %11 ], [ 2, %14 ], [ 1, %17 ], [ %21, %20 ]
ret i32 %23
}