#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*/ size;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int arch_cache_line_size(void) {
  char size[32];
  int fd, ret;
  fd = open("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size",
            O_RDONLY);
  if (fd < 0)
    return -1;
  ret = read(fd, size, sizeof(size));
  close(fd);
  if (ret <= 0)
    return -1;
  else
    return atoi(size);
}


x86 assembly (clang, -O0):
<arch_cache_line_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1176 <arch_cache_line_size+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <arch_cache_line_size+0x74>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1040 <read@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x38(%rbp)
jg     11a8 <arch_cache_line_size+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <arch_cache_line_size+0x74>
lea    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arch_cache_line_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1190 <arch_cache_line_size+0x50>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x20,%edx
call   1040 <read@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <close@plt>
test   %r14d,%r14d
jle    1190 <arch_cache_line_size+0x50>
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size\00"
@O_RDONLY = global i32 0
define i32 @arch_cache_line_size() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %22
10: ; preds = %0
%11 = load i32, i32* %3
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 32)
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %4
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
store i32 -1, i32* %1
br label %22
19: ; preds = %10
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %1
br label %22
22: ; preds = %19, %18, %9
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [62 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size\00"
@O_RDONLY = global i32 0
define i32 @arch_cache_line_size() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 32)
%8 = tail call i32 @close(i32 %4)
%9 = icmp slt i32 %7, 1
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = call i32 @atoi(i8* %2)
br label %12
12: ; preds = %6, %0, %10
%13 = phi i32 [ %11, %10 ], [ -1, %0 ], [ -1, %6 ]
ret i32 %13
}