#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ buf;
typedef scalar_t__ XtPointer;
typedef int /*<<< orphan*/ Widget;
struct TYPE_2__ {
  char *decimal_point;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
TYPE_1__ *localeconv();
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *memchr(char *, char, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int sscanf(char *, char *, double *);
void GetLoadPoint(Widget w, XtPointer closure, XtPointer call_data) {
  static int fd = -1;
  int n;
  char buf[10] = {
      0,
  };
  char *dp;
  static char ldp = 0;
  if (fd < 0) {
    if (fd == -2 || (fd = open("/proc/loadavg", O_RDONLY)) < 0) {
      fd = -2;
      *(double *)call_data = 0.0;
      return;
    }
    ldp = *localeconv()->decimal_point;
  } else
    lseek(fd, 0, 0);
  if ((n = read(fd, buf, sizeof(buf) - 1)) > 0) {
    if (ldp != '.')
      while ((dp = memchr(buf, '.', sizeof(buf) - 1)) != NULL) {
        *(char *)dp = ldp;
      }
    if (sscanf(buf, "%lf", (double *)call_data) == 1)
      return;
  }
  *(double *)call_data = 0.0;
  return;
}


x86 assembly (clang, -O0):
<GetLoadPoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x26(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
cmpl   $0x0,0x2ebe(%rip)
jge    1202 <GetLoadPoint+0x92>
cmpl   $0xfffffffe,0x2eb1(%rip)
je     11d1 <GetLoadPoint+0x61>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1090 <open@plt>
mov    %eax,0x2e90(%rip)
cmp    $0x0,%eax
jge    11eb <GetLoadPoint+0x7b>
movl   $0xfffffffe,0x2e7d(%rip)
ff ff ff
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    12af <GetLoadPoint+0x13f>
mov    $0x0,%al
call   1030 <localeconv@plt>
mov    (%rax),%rax
mov    (%rax),%al
mov    %al,0x2e63(%rip)
jmp    1211 <GetLoadPoint+0xa1>
mov    0x2e50(%rip),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <lseek@plt>
mov    0x2e41(%rip),%edi
lea    -0x26(%rbp),%rsi
mov    $0x9,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12a4 <GetLoadPoint+0x134>
movsbl 0x2e28(%rip),%eax
cmp    $0x2e,%eax
je     127d <GetLoadPoint+0x10d>
jmp    1246 <GetLoadPoint+0xd6>
lea    -0x26(%rbp),%rdi
mov    $0x2e,%esi
mov    $0x9,%edx
call   1060 <memchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1278 <GetLoadPoint+0x108>
mov    0x2df3(%rip),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
jmp    1246 <GetLoadPoint+0xd6>
jmp    127d <GetLoadPoint+0x10d>
lea    -0x26(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd82(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    129f <GetLoadPoint+0x12f>
jmp    12af <GetLoadPoint+0x13f>
jmp    12a4 <GetLoadPoint+0x134>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetLoadPoint>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
movw   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2ed0(%rip),%edi
test   %edi,%edi
js     121b <GetLoadPoint+0xbb>
xor    %esi,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    0x2eb9(%rip),%edi
lea    0x8(%rsp),%rsi
mov    $0x9,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1260 <GetLoadPoint+0x100>
cmpb   $0x2e,0x2ea3(%rip)
je     1200 <GetLoadPoint+0xa0>
lea    0x8(%rsp),%rdi
mov    $0x2e,%esi
mov    $0x9,%edx
call   1050 <memchr@plt>
test   %rax,%rax
je     1200 <GetLoadPoint+0xa0>
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x2e71(%rip),%ecx
mov    %cl,(%rax)
mov    %rbx,%rdi
mov    $0x2e,%esi
mov    $0x9,%edx
call   1050 <memchr@plt>
test   %rax,%rax
jne    11e0 <GetLoadPoint+0x80>
lea    0xe07(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r14,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1260 <GetLoadPoint+0x100>
jmp    1267 <GetLoadPoint+0x107>
cmp    $0xfffffffe,%edi
je     1256 <GetLoadPoint+0xf6>
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    0xdd0(%rip),%rdi
call   1080 <open@plt>
mov    %eax,0x2e15(%rip)
test   %eax,%eax
js     1256 <GetLoadPoint+0xf6>
xor    %eax,%eax
call   1030 <localeconv@plt>
mov    (%rax),%rax
mov    (%rax),%al
mov    %al,0x2e07(%rip)
jmp    1191 <GetLoadPoint+0x31>
movl   $0xfffffffe,0x2df0(%rip)
ff ff ff
movq   $0x0,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i8* }
@GetLoadPoint.fd = internal global i32 -1
@GetLoadPoint.ldp = internal global i8 0
@.str = [14 x i8] c"/proc/loadavg\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%lf\00"
define void @GetLoadPoint(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca [10 x i8]
%9 = alloca i8*
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%10 = bitcast [10 x i8]* %8 to i8*
%11 = load i32, i32* @GetLoadPoint.fd
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %3
%14 = load i32, i32* @GetLoadPoint.fd
%15 = icmp eq i32 %14, -2
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* @GetLoadPoint.fd
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16, %13
store i32 -2, i32* @GetLoadPoint.fd
%21 = load i64, i64* %6
%22 = inttoptr i64 %21 to double*
store double 0.000000e+00, double* %22
br label %60
23: ; preds = %16
%24 = call %struct.TYPE_2__* (...) @localeconv()
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
store i8 %27, i8* @GetLoadPoint.ldp
br label %31
28: ; preds = %3
%29 = load i32, i32* @GetLoadPoint.fd
%30 = call i32 @lseek(i32 %29, i32 0, i32 0)
br label %31
31: ; preds = %28, %23
%32 = load i32, i32* @GetLoadPoint.fd
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 9)
store i32 %34, i32* %7
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %57
36: ; preds = %31
%37 = load i8, i8* @GetLoadPoint.ldp
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 46
br i1 %39, label %40, label %49
40: ; preds = %36
br label %41
41: ; preds = %45, %40
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%43 = call i8* @memchr(i8* %42, i8 signext 46, i32 9)
store i8* %43, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i8, i8* @GetLoadPoint.ldp
%47 = load i8*, i8** %9
store i8 %46, i8* %47
br label %41
48: ; preds = %41
br label %49
49: ; preds = %48, %36
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%51 = load i64, i64* %6
%52 = inttoptr i64 %51 to double*
%53 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %52)
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %56
55: ; preds = %49
br label %60
56: ; preds = %49
br label %57
57: ; preds = %56, %31
%58 = load i64, i64* %6
%59 = inttoptr i64 %58 to double*
store double 0.000000e+00, double* %59
br label %60
60: ; preds = %57, %55, %20
ret void
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i8* }
@GetLoadPoint.fd = internal unnamed_addr global i32 -1
@GetLoadPoint.ldp = internal unnamed_addr global i8 0
@.str = [14 x i8] c"/proc/loadavg\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%lf\00"
define void @GetLoadPoint(i32 %0, i64 %1, i64 %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @GetLoadPoint.fd
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %3
%9 = icmp eq i32 %6, -2
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* @GetLoadPoint.fd
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10, %8
store i32 -2, i32* @GetLoadPoint.fd
%15 = inttoptr i64 %2 to double*
br label %44
16: ; preds = %10
%17 = tail call %struct.TYPE_2__* (...) @localeconv()
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
store i8 %20, i8* @GetLoadPoint.ldp
br label %23
21: ; preds = %3
%22 = tail call i32 @lseek(i32 %6, i32 0, i32 0)
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* @GetLoadPoint.fd
%25 = call i32 @read(i32 %24, i8* %5, i32 9)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = inttoptr i64 %2 to double*
br label %44
29: ; preds = %23
%30 = load i8, i8* @GetLoadPoint.ldp
%31 = icmp eq i8 %30, 46
br i1 %31, label %40, label %32
32: ; preds = %29
%33 = call i8* @memchr(i8* %5, i8 signext 46, i32 9)
%34 = icmp eq i8* %33, null
br i1 %34, label %40, label %35
35: ; preds = %32, %35
%36 = phi i8* [ %38, %35 ], [ %33, %32 ]
%37 = load i8, i8* @GetLoadPoint.ldp
store i8 %37, i8* %36
%38 = call i8* @memchr(i8* %5, i8 signext 46, i32 9)
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %35
40: ; preds = %35, %32, %29
%41 = inttoptr i64 %2 to double*
%42 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %46, label %44
44: ; preds = %40, %27, %14
%45 = phi double* [ %15, %14 ], [ %28, %27 ], [ %41, %40 ]
store double 0.000000e+00, double* %45
br label %46
46: ; preds = %44, %40
ret void
}