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

/* Variables and functions */
char const *bprintf(char const *, double, double, double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getloadavg(double *, int);
int /*<<< orphan*/ stderr;
const char *load_avg(const char *fmt) {
  double avgs[3];
  if (getloadavg(avgs, 3) < 0) {
    fprintf(stderr, "getloadavg: Could not obtain load average.\n");
    return NULL;
  }
  return bprintf(fmt, avgs[0], avgs[1], avgs[2]);
}


x86 assembly (clang, -O0):
<load_avg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x3,%esi
call   1030 <getloadavg@plt>
cmp    $0x0,%rax
jge    1176 <load_avg+0x46>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1192 <load_avg+0x62>
mov    -0x10(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1040 <bprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_avg>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x3,%esi
call   1030 <getloadavg@plt>
test   %rax,%rax
js     1165 <load_avg+0x35>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mov    %rbx,%rdi
call   1040 <bprintf@plt>
jmp    117c <load_avg+0x4c>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"getloadavg: Could not obtain load average.\0A\00"
define i8* @load_avg(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [3 x double]
store i8* %0, i8** %3
%5 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%6 = call i64 @getloadavg(double* %5, i32 3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %20
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%14 = load double, double* %13
%15 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%16 = load double, double* %15
%17 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%18 = load double, double* %17
%19 = call i8* @bprintf(i8* %12, double %14, double %16, double %18)
store i8* %19, i8** %2
br label %20
20: ; preds = %11, %8
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"getloadavg: Could not obtain load average.\0A\00"
define i8* @load_avg(i8* %0) {
%2 = alloca [3 x double]
%3 = bitcast [3 x double]* %2 to i8*
%4 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%5 = call i64 @getloadavg(double* %4, i32 3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %17
10: ; preds = %1
%11 = load double, double* %4
%12 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 1
%13 = load double, double* %12
%14 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 2
%15 = load double, double* %14
%16 = call i8* @bprintf(i8* %0, double %11, double %13, double %15)
br label %17
17: ; preds = %10, %7
%18 = phi i8* [ null, %7 ], [ %16, %10 ]
ret i8* %18
}