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


x86 assembly (clang, -O0):
<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 <cache_info@plt>
lea    -0x210(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11a7 <cacheline_length+0x67>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cacheline_length@plt>
mov    %eax,-0x4(%rbp)
jmp    12c6 <cacheline_length+0x186>
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1060 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    11f8 <cacheline_length+0xb8>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cacheline_length@plt>
mov    %eax,-0x4(%rbp)
jmp    12c6 <cacheline_length+0x186>
mov    -0x220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1060 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    1257 <cacheline_length+0x117>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <generic_cacheline_length@plt>
mov    %eax,-0x4(%rbp)
jmp    12c6 <cacheline_length+0x186>
mov    -0x220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     12b7 <cacheline_length+0x177>
mov    -0x220(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x220(%rbp)
movb   $0x0,(%rax)
mov    -0x218(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cacheline_length>:
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdx
mov    $0x200,%ecx
call   1030 <cache_info@plt>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
lea    0x2(%rax),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
lea    0x2(%rax),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
add    $0x2,%rbx
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     119f <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 @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 @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 %22
18: ; preds = %2
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = call i32 @generic_cacheline_length(i32 %19, i32 %20)
store i32 %21, i32* %3
br label %64
22: ; preds = %2
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
br label %25
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = call i32 @generic_cacheline_length(i32 %32, i32 %33)
store i32 %34, i32* %3
br label %64
35: ; preds = %25
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %8
br label %38
38: ; preds = %35
%39 = load i8*, i8** %8
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = call i32 @generic_cacheline_length(i32 %46, i32 %47)
store i32 %48, i32* %3
br label %64
49: ; preds = %38
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %8
br label %52
52: ; preds = %49
%53 = load i8*, i8** %8
store i8* %53, i8** %7
%54 = load i8*, i8** %7
%55 = call i8* @strstr(i8* %54, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* %55, i8** %8
%56 = load i8*, i8** %8
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %52
%59 = load i8*, i8** %8
%60 = getelementptr inbounds i8, i8* %59, i32 -1
store i8* %60, i8** %8
store i8 0, i8* %59
br label %61
61: ; preds = %58, %52
%62 = load i8*, i8** %7
%63 = call i32 @atoi(i8* %62)
store i32 %63, i32* %3
br label %64
64: ; preds = %61, %45, %31, %18
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"Byte cachelines\00"
define i32 @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 @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
}