#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*/ name;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int HZ;
scalar_t__ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned int *, unsigned int *);
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int __get_hz(void) {
  char name[1024];
  int hz = 0;
  FILE *fp;
  if (getenv("HZ"))
    return atoi(getenv("HZ")) ?: HZ;
  if (getenv("PROC_NET_PSCHED")) {
    snprintf(name, sizeof(name) - 1, "%s", getenv("PROC_NET_PSCHED"));
  } else if (getenv("PROC_ROOT")) {
    snprintf(name, sizeof(name) - 1, "%s/net/psched", getenv("PROC_ROOT"));
  } else {
    strcpy(name, "/proc/net/psched");
  }
  fp = fopen(name, "r");
  if (fp) {
    unsigned nom, denom;
    if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2)
      if (nom == 1000000)
        hz = denom;
    fclose(fp);
  }
  if (hz)
    return hz;
  return HZ;
}


x86 assembly (clang, -O0):
<__get_hz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x414(%rbp)
lea    0xe74(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11f3 <__get_hz+0x83>
lea    0xe5e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
je     11d3 <__get_hz+0x63>
mov    -0x430(%rbp),%rax
mov    %rax,-0x438(%rbp)
jmp    11e4 <__get_hz+0x74>
mov    0x2e06(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1351 <__get_hz+0x1e1>
lea    0xe09(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1243 <__get_hz+0xd3>
lea    -0x410(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    0xde5(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x440(%rbp),%rdi
mov    %rax,%rcx
mov    $0x3ff,%esi
lea    0xdda(%rip),%rdx
call   1060 <snprintf@plt>
jmp    12ab <__get_hz+0x13b>
lea    0xdcc(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1293 <__get_hz+0x123>
lea    -0x410(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    0xda8(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x448(%rbp),%rdi
mov    %rax,%rcx
mov    $0x3ff,%esi
lea    0xd97(%rip),%rdx
call   1060 <snprintf@plt>
jmp    12a6 <__get_hz+0x136>
lea    -0x410(%rbp),%rdi
lea    0xd8d(%rip),%rsi
call   1040 <strcpy@plt>
jmp    12ab <__get_hz+0x13b>
lea    -0x410(%rbp),%rdi
lea    0xd86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     132a <__get_hz+0x1ba>
mov    -0x420(%rbp),%rdi
lea    0xd60(%rip),%rsi
lea    -0x424(%rbp),%rdx
lea    -0x428(%rbp),%rcx
call   1070 <fscanf@plt>
cmp    $0x2,%eax
jne    131e <__get_hz+0x1ae>
cmpl   $0xf4240,-0x424(%rbp)
jne    1319 <__get_hz+0x1a9>
mov    -0x428(%rbp),%eax
mov    %eax,-0x414(%rbp)
jmp    131e <__get_hz+0x1ae>
mov    -0x420(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x414(%rbp)
je     1345 <__get_hz+0x1d5>
mov    -0x414(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1351 <__get_hz+0x1e1>
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__get_hz>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a7 <__get_hz+0x37>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1246 <__get_hz+0xd6>
jmp    124f <__get_hz+0xdf>
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c1 <__get_hz+0x51>
lea    0xe54(%rip),%rdx
jmp    11dd <__get_hz+0x6d>
lea    0xe4e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     125f <__get_hz+0xef>
lea    0xe43(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x3ff,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
lea    0xe49(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1246 <__get_hz+0xd6>
mov    %rax,%r14
lea    0xe32(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1070 <fscanf@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%r15d
mov    0x8(%rsp),%ebx
mov    %r14,%rdi
call   1050 <fclose@plt>
cmp    $0x2,%ebp
jne    1246 <__get_hz+0xd6>
cmp    $0xf4240,%r15d
jne    1246 <__get_hz+0xd6>
test   %ebx,%ebx
jne    124f <__get_hz+0xdf>
mov    0x2d93(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc8(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
jmp    11ef <__get_hz+0x7f>

LLVM IR (-O0):
@.str = [3 x i8] c"HZ\00"
@HZ = global i32 0
@.str.1 = [16 x i8] c"PROC_NET_PSCHED\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [10 x i8] c"PROC_ROOT\00"
@.str.4 = [14 x i8] c"%s/net/psched\00"
@.str.5 = [17 x i8] c"/proc/net/psched\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [19 x i8] c"%*08x%*08x%08x%08x\00"
define i32 @__get_hz() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %3
%7 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %20
9: ; preds = %0
%10 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = call i64 @atoi(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
br label %17
14: ; preds = %9
%15 = load i32, i32* @HZ
%16 = sext i32 %15 to i64
br label %17
17: ; preds = %14, %13
%18 = phi i64 [ %11, %13 ], [ %16, %14 ]
%19 = trunc i64 %18 to i32
store i32 %19, i32* %1
br label %63
20: ; preds = %0
%21 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%25 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @snprintf(i8* %24, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %38
27: ; preds = %20
%28 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%32 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @snprintf(i8* %31, i32 1023, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %37
34: ; preds = %27
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %34, %30
br label %38
38: ; preds = %37, %23
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %40, i32** %4
%41 = load i32*, i32** %4
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %56
43: ; preds = %38
%44 = load i32*, i32** %4
%45 = call i32 @fscanf(i32* %44, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32* %5, i32* %6)
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = load i32, i32* %5
%49 = icmp eq i32 %48, 1000000
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = load i32, i32* %6
store i32 %51, i32* %3
br label %52
52: ; preds = %50, %47
br label %53
53: ; preds = %52, %43
%54 = load i32*, i32** %4
%55 = call i32 @fclose(i32* %54)
br label %56
56: ; preds = %53, %38
%57 = load i32, i32* %3
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i32, i32* %3
store i32 %60, i32* %1
br label %63
61: ; preds = %56
%62 = load i32, i32* @HZ
store i32 %62, i32* %1
br label %63
63: ; preds = %61, %59, %17
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"HZ\00"
@HZ = global i32 0
@.str.1 = [16 x i8] c"PROC_NET_PSCHED\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [10 x i8] c"PROC_ROOT\00"
@.str.4 = [14 x i8] c"%s/net/psched\00"
@.str.5 = [17 x i8] c"/proc/net/psched\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [19 x i8] c"%*08x%*08x%08x%08x\00"
define i32 @__get_hz() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %0
%8 = tail call i64 @atoi(i8* %5)
%9 = icmp eq i64 %8, 0
%10 = load i32, i32* @HZ
%11 = zext i32 %10 to i64
%12 = select i1 %9, i64 %11, i64 %8
%13 = trunc i64 %12 to i32
br label %43
14: ; preds = %0
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @snprintf(i8* %4, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %26
19: ; preds = %14
%20 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @snprintf(i8* %4, i32 1023, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %20)
br label %26
24: ; preds = %19
%25 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %22, %24, %17
%27 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %41, label %29
29: ; preds = %26
%30 = bitcast i32* %2 to i8*
%31 = bitcast i32* %3 to i8*
%32 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32* %2, i32* %3)
%33 = icmp ne i32 %32, 2
%34 = load i32, i32* %2
%35 = icmp ne i32 %34, 1000000
%36 = select i1 %33, i1 true, i1 %35
%37 = load i32, i32* %3
%38 = call i32 @fclose(i32* %27)
%39 = icmp eq i32 %37, 0
%40 = select i1 %36, i1 true, i1 %39
br i1 %40, label %41, label %43
41: ; preds = %26, %29
%42 = load i32, i32* @HZ
br label %43
43: ; preds = %29, %41, %7
%44 = phi i32 [ %13, %7 ], [ %42, %41 ], [ %37, %29 ]
ret i32 %44
}