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

/* Variables and functions */
scalar_t__ ENOENT;
int EXIT_SUCCESS;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int, char *, ...);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, size_t *);
int open(char *, int, int);
long sysconf(int /*<<< orphan*/);
scalar_t__ unlink(char *);
int main(int argc, char **argv) {
  int fd;
  const long page_size = sysconf(_SC_PAGESIZE);
  size_t cache_line_size = 0;
  if (-1 == page_size)
    abort();
  if (unlink("memsizes.h")) {
    if (ENOENT != errno)
      abort();
  }
  FILE *p = NULL;
  p = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size",
            "r");
  if (p) {
    if (1 != fscanf(p, "%u", &cache_line_size))
      abort();
    fclose(p);
  } else {
    abort();
  }
  if (0 == cache_line_size)
    abort();
  fd = open("memsizes.h", O_WRONLY | O_CREAT | O_TRUNC, 0644);
  dprintf(fd, "#ifndef MEM_SIZES_H        \n");
  dprintf(fd, "#define MEM_SIZES_H      \n\n");
  dprintf(fd, "#ifdef PAGE_SIZE          \n");
  dprintf(fd, "#undef PAGE_SIZE          \n");
  dprintf(fd, "#endif                    \n");
  dprintf(fd, "#define PAGE_SIZE (%ld) \n\n", page_size);
  dprintf(fd, "#ifdef CACHE_LINE_SIZE          \n");
  dprintf(fd, "#undef CACHE_LINE_SIZE          \n");
  dprintf(fd, "#endif                    \n");
  dprintf(fd, "#define CACHE_LINE_SIZE (%ld) \n\n", cache_line_size);
  dprintf(fd, "#endif /* MEM_SIZES_H */   \n");
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x20(%rbp),%rax
jne    11d8 <main+0x48>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xe21(%rip),%rdi
call   1040 <unlink@plt>
cmp    $0x0,%rax
je     1214 <main+0x84>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
je     120f <main+0x7f>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1214 <main+0x84>
movq   $0x0,-0x30(%rbp)
lea    0xde8(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1276 <main+0xe6>
mov    -0x30(%rbp),%rdi
lea    0xe02(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1268 <main+0xd8>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
jmp    127d <main+0xed>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1290 <main+0x100>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    0x2d58(%rip),%rax
or     (%rax),%esi
mov    0x2d47(%rip),%rax
or     (%rax),%esi
lea    0xd4e(%rip),%rdi
mov    $0x1a4,%edx
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rdx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rdx
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1080 <dprintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2c2f(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
movq   $0x0,0x8(%rsp)
cmp    $0xffffffffffffffff,%rax
je     1335 <main+0x1a5>
mov    %rax,%r14
lea    0xe3d(%rip),%rdi
call   1040 <unlink@plt>
test   %rax,%rax
je     11e7 <main+0x57>
mov    0x2ddc(%rip),%rax
mov    (%rax),%rax
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
jne    1335 <main+0x1a5>
lea    0xe1d(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1335 <main+0x1a5>
mov    %rax,%rbp
lea    0xe3e(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    1335 <main+0x1a5>
mov    %rbp,%rdi
call   1050 <fclose@plt>
cmpq   $0x0,0x8(%rsp)
je     1335 <main+0x1a5>
mov    0x2d6a(%rip),%rax
mov    0x2db3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2da0(%rip),%rax
or     (%rax),%esi
lea    0xda7(%rip),%rdi
mov    $0x1a4,%edx
call   1090 <open@plt>
mov    %eax,%ebp
lea    0xde2(%rip),%rsi
mov    %eax,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xdef(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xdfb(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xe07(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xe13(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xe1c(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xe24(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xe36(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <dprintf@plt>
mov    0x8(%rsp),%rdx
lea    0xe37(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
lea    0xe48(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <dprintf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@.str = [11 x i8] c"memsizes.h\00"
@ENOENT = global i64 0
@errno = global i64 0
@.str.1 = [62 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%u\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [29 x i8] c"#ifndef MEM_SIZES_H \0A\00"
@.str.5 = [28 x i8] c"#define MEM_SIZES_H \0A\0A\00"
@.str.6 = [28 x i8] c"#ifdef PAGE_SIZE \0A\00"
@.str.7 = [28 x i8] c"#undef PAGE_SIZE \0A\00"
@.str.8 = [28 x i8] c"#endif \0A\00"
@.str.9 = [27 x i8] c"#define PAGE_SIZE (%ld) \0A\0A\00"
@.str.10 = [34 x i8] c"#ifdef CACHE_LINE_SIZE \0A\00"
@.str.11 = [34 x i8] c"#undef CACHE_LINE_SIZE \0A\00"
@.str.12 = [33 x i8] c"#define CACHE_LINE_SIZE (%ld) \0A\0A\00"
@.str.13 = [29 x i8] c"#endif /* MEM_SIZES_H */ \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @_SC_PAGESIZE
%11 = call i64 @sysconf(i32 %10)
store i64 %11, i64* %7
store i64 0, i64* %8
%12 = load i64, i64* %7
%13 = icmp eq i64 -1, %12
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %2
%17 = call i64 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i64, i64* @ENOENT
%21 = load i64, i64* @errno
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %19
br label %26
26: ; preds = %25, %16
store i32* null, i32** %9
%27 = call i32* @fopen(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %9
%28 = load i32*, i32** %9
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i32*, i32** %9
%32 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64* %8)
%33 = icmp ne i32 1, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 (...) @abort()
unreachable
36: ; preds = %30
%37 = load i32*, i32** %9
%38 = call i32 @fclose(i32* %37)
br label %41
39: ; preds = %26
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %36
%42 = load i64, i64* %8
%43 = icmp eq i64 0, %42
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (...) @abort()
unreachable
46: ; preds = %41
%47 = load i32, i32* @O_WRONLY
%48 = load i32, i32* @O_CREAT
%49 = or i32 %47, %48
%50 = load i32, i32* @O_TRUNC
%51 = or i32 %49, %50
%52 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %51, i32 420)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = call i32 (i32, i8*, ...) @dprintf(i32 %53, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* %6
%56 = call i32 (i32, i8*, ...) @dprintf(i32 %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* %6
%58 = call i32 (i32, i8*, ...) @dprintf(i32 %57, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%59 = load i32, i32* %6
%60 = call i32 (i32, i8*, ...) @dprintf(i32 %59, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%61 = load i32, i32* %6
%62 = call i32 (i32, i8*, ...) @dprintf(i32 %61, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%63 = load i32, i32* %6
%64 = load i64, i64* %7
%65 = call i32 (i32, i8*, ...) @dprintf(i32 %63, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i64 %64)
%66 = load i32, i32* %6
%67 = call i32 (i32, i8*, ...) @dprintf(i32 %66, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
%68 = load i32, i32* %6
%69 = call i32 (i32, i8*, ...) @dprintf(i32 %68, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
%70 = load i32, i32* %6
%71 = call i32 (i32, i8*, ...) @dprintf(i32 %70, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%72 = load i32, i32* %6
%73 = load i64, i64* %8
%74 = call i32 (i32, i8*, ...) @dprintf(i32 %72, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0), i64 %73)
%75 = load i32, i32* %6
%76 = call i32 (i32, i8*, ...) @dprintf(i32 %75, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* @EXIT_SUCCESS
ret i32 %79
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@.str = [11 x i8] c"memsizes.h\00"
@ENOENT = global i64 0
@errno = global i64 0
@.str.1 = [62 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%u\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [29 x i8] c"#ifndef MEM_SIZES_H \0A\00"
@.str.5 = [28 x i8] c"#define MEM_SIZES_H \0A\0A\00"
@.str.6 = [28 x i8] c"#ifdef PAGE_SIZE \0A\00"
@.str.7 = [28 x i8] c"#undef PAGE_SIZE \0A\00"
@.str.8 = [28 x i8] c"#endif \0A\00"
@.str.9 = [27 x i8] c"#define PAGE_SIZE (%ld) \0A\0A\00"
@.str.10 = [34 x i8] c"#ifdef CACHE_LINE_SIZE \0A\00"
@.str.11 = [34 x i8] c"#undef CACHE_LINE_SIZE \0A\00"
@.str.12 = [33 x i8] c"#define CACHE_LINE_SIZE (%ld) \0A\0A\00"
@.str.13 = [29 x i8] c"#endif /* MEM_SIZES_H */ \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = load i32, i32* @_SC_PAGESIZE
%5 = tail call i64 @sysconf(i32 %4)
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = icmp eq i64 %5, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %2
%11 = tail call i64 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = load i64, i64* @ENOENT
%15 = load i64, i64* @errno
%16 = icmp eq i64 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 (...) @abort()
unreachable
19: ; preds = %13, %10
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %31, label %22
22: ; preds = %19
%23 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64* %3)
%24 = icmp eq i32 %23, 1
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %22
%28 = call i32 @fclose(i32* %20)
%29 = load i64, i64* %3
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %35
31: ; preds = %19
%32 = tail call i32 (...) @abort()
unreachable
33: ; preds = %27
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %27
%36 = load i32, i32* @O_WRONLY
%37 = load i32, i32* @O_CREAT
%38 = or i32 %37, %36
%39 = load i32, i32* @O_TRUNC
%40 = or i32 %38, %39
%41 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %40, i32 420)
%42 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%46 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%47 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i64 %5)
%48 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
%49 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
%50 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%51 = load i64, i64* %3
%52 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0), i64 %51)
%53 = call i32 (i32, i8*, ...) @dprintf(i32 %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
%54 = call i32 @close(i32 %41)
%55 = load i32, i32* @EXIT_SUCCESS
ret i32 %55
}