#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
long sysconf(int);
long sysconf_wrap(int name) {
  FILE *f;
  int val;
  switch (name) {
  case -1:
    f = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size",
              "r");
    if (!f)
      return 0;
    if (fscanf(f, "%d", &val) != 1)
      return 0;
    fclose(f);
    return val;
  default:
    return sysconf(name);
  }
}


x86 assembly (clang, -O0):
<sysconf_wrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0xffffffff,%eax
jne    11cb <sysconf_wrap+0x8b>
jmp    115c <sysconf_wrap+0x1c>
lea    0xe9d(%rip),%rdi
lea    0xed4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118b <sysconf_wrap+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <sysconf_wrap+0x97>
mov    -0x18(%rbp),%rdi
lea    0xeaa(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11b5 <sysconf_wrap+0x75>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <sysconf_wrap+0x97>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movslq -0x1c(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <sysconf_wrap+0x97>
mov    -0xc(%rbp),%edi
call   1060 <sysconf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysconf_wrap>:
cmp    $0xffffffff,%edi
je     114a <sysconf_wrap+0xa>
jmp    1060 <sysconf@plt>
push   %rbx
sub    $0x10,%rsp
lea    0xeaa(%rip),%rdi
lea    0xee1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1192 <sysconf_wrap+0x52>
mov    %rax,%rbx
lea    0xecf(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1192 <sysconf_wrap+0x52>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movslq 0xc(%rsp),%rax
jmp    1194 <sysconf_wrap+0x54>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [62 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i64 @sysconf_wrap(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %22 [
i32 -1, label %7
]
7: ; preds = %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %7
store i64 0, i64* %2
br label %25
12: ; preds = %7
%13 = load i32*, i32** %4
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %12
store i64 0, i64* %2
br label %25
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
store i64 %21, i64* %2
br label %25
22: ; preds = %1
%23 = load i32, i32* %3
%24 = call i64 @sysconf(i32 %23)
store i64 %24, i64* %2
br label %25
25: ; preds = %22, %17, %16, %11
%26 = load i64, i64* %2
ret i64 %26
}

LLVM IR (-O2):
@.str = [62 x i8] c"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i64 @sysconf_wrap(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i32 %0, -1
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i32 @fclose(i32* %6)
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
br label %17
15: ; preds = %1
%16 = tail call i64 @sysconf(i32 %0)
br label %17
17: ; preds = %8, %5, %15, %11
%18 = phi i64 [ %14, %11 ], [ %16, %15 ], [ 0, %5 ], [ 0, %8 ]
ret i64 %18
}