#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_cacheline_length(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, ",") + 1;
  if (end == NULL)
    return -1;
  else
    end++;
  beg = end;
  end = strstr(beg, "Byte cachelines");
  if (end != NULL)
    *(end--) = '\0';
  return atoi(beg);
}


x86 assembly (clang, -O0):
<generic_cacheline_length>:
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_cacheline_length+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <generic_cacheline_length+0x171>
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_cacheline_length+0xaa>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <generic_cacheline_length+0x171>
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>
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    1232 <generic_cacheline_length+0x102>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <generic_cacheline_length+0x171>
mov    -0x220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xda2(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     1292 <generic_cacheline_length+0x162>
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x220(%rbp)
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_cacheline_length>:
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>
lea    0x2(%rax),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
add    $0x2,%rbx
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     119f <generic_cacheline_length+0x5f>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <atoi@plt>
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [16 x i8] c"Byte cachelines\00"
define i32 @generic_cacheline_length(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 %55
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 %55
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))
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 -1, i32* %3
br label %55
40: ; preds = %32
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %8
br label %43
43: ; preds = %40
%44 = load i8*, i8** %8
store i8* %44, i8** %7
%45 = load i8*, i8** %7
%46 = call i8* @strstr(i8* %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* %46, i8** %8
%47 = load i8*, i8** %8
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i32 -1
store i8* %51, i8** %8
store i8 0, i8* %50
br label %52
52: ; preds = %49, %43
%53 = load i8*, i8** %7
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %3
br label %55
55: ; preds = %52, %39, %28, %18
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"Byte cachelines\00"
define i32 @generic_cacheline_length(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 = getelementptr inbounds i8, i8* %10, i64 2
%12 = call i8* @strstr(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i8 0, i8* %12
br label %15
15: ; preds = %2, %14
%16 = call i32 @atoi(i8* %11)
ret i32 %16
}