#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 */
struct sysinfo {
  double *loads;
};

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, double, double, double);
int /*<<< orphan*/ strncat(char *, char *, size_t);
int sysinfo(struct sysinfo *);
int load_average(char *b, size_t s) {
  struct sysinfo Sinfo;
  char buffer[500];
  buffer[0] = '\x0';
  if (sysinfo(&Sinfo) != -1)
    snprintf(buffer, 500, "<b>Load Average:</b> (%.2f), (%.2f), (%.2f)<br>\n",
             ((Sinfo.loads[0]) / 65536.0), ((Sinfo.loads[1]) / 65536.0),
             ((Sinfo.loads[2]) / 65536.0));
  strncat(b, buffer, s);
  return 0;
}


x86 assembly (clang, -O0):
<load_average>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x210(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <sysinfo@plt>
cmp    $0xffffffff,%eax
je     11b2 <load_average+0x82>
lea    -0x210(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe8d(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xe78(%rip),%xmm2
divsd  %xmm2,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
movsd  0xe63(%rip),%xmm3
divsd  %xmm3,%xmm2
mov    $0x1f4,%esi
lea    0xe5b(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <strncat@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_average>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <sysinfo@plt>
cmp    $0xffffffff,%eax
je     118d <load_average+0x5d>
mov    0x8(%rsp),%rax
movsd  0xe9f(%rip),%xmm2
movsd  (%rax),%xmm0
mulsd  %xmm2,%xmm0
movsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm1
mulsd  0x10(%rax),%xmm2
lea    0xe8a(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x1f4,%esi
call   1030 <snprintf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <strncat@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sysinfo = type { double* }
@.str = [49 x i8] c"<b>Load Average:</b> (%.2f), (%.2f), (%.2f)<br>\0A\00"
define i32 @load_average(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.sysinfo
%6 = alloca [500 x i8]
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
store i8 0, i8* %7
%8 = call i32 @sysinfo(%struct.sysinfo* %5)
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %28
10: ; preds = %2
%11 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %5, i32 0, i32 0
%13 = load double*, double** %12
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = fdiv double %15, 6.553600e+04
%17 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %5, i32 0, i32 0
%18 = load double*, double** %17
%19 = getelementptr inbounds double, double* %18, i64 1
%20 = load double, double* %19
%21 = fdiv double %20, 6.553600e+04
%22 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %5, i32 0, i32 0
%23 = load double*, double** %22
%24 = getelementptr inbounds double, double* %23, i64 2
%25 = load double, double* %24
%26 = fdiv double %25, 6.553600e+04
%27 = call i32 @snprintf(i8* %11, i32 500, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), double %16, double %21, double %26)
br label %28
28: ; preds = %10, %2
%29 = load i8*, i8** %3
%30 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%31 = load i64, i64* %4
%32 = call i32 @strncat(i8* %29, i8* %30, i64 %31)
ret i32 0
}

LLVM IR (-O2):
%struct.sysinfo = type { double* }
@.str = [49 x i8] c"<b>Load Average:</b> (%.2f), (%.2f), (%.2f)<br>\0A\00"
define i32 @load_average(i8* %0, i64 %1) {
%3 = alloca %struct.sysinfo
%4 = alloca [500 x i8]
%5 = bitcast %struct.sysinfo* %3 to i8*
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
store i8 0, i8* %6
%7 = call i32 @sysinfo(%struct.sysinfo* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %3, i64 0, i32 0
%11 = load double*, double** %10
%12 = load double, double* %11
%13 = fmul double %12, 0x3EF0000000000000
%14 = getelementptr inbounds double, double* %11, i64 1
%15 = load double, double* %14
%16 = fmul double %15, 0x3EF0000000000000
%17 = getelementptr inbounds double, double* %11, i64 2
%18 = load double, double* %17
%19 = fmul double %18, 0x3EF0000000000000
%20 = call i32 @snprintf(i8* %6, i32 500, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), double %13, double %16, double %19)
br label %21
21: ; preds = %9, %2
%22 = call i32 @strncat(i8* %0, i8* %6, i64 %1)
ret i32 0
}