#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 */
int getloadavg(double *, int);
int /*<<< orphan*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
int _get_load(char **s, int l) {
  int i;
  char buf[5];
  double a[3];
  i = getloadavg(a, 3);
  if (i < 0) {
    return i;
  }
  sprintf(buf, "%0.2f", a[l - 1]);
  strncpy(*s, buf, strlen(buf));
  return 0;
}


x86 assembly (clang, -O0):
<_get_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
call   1040 <getloadavg@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1175 <_get_load+0x35>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <_get_load+0x85>
lea    -0x1d(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x40(%rbp,%rax,8),%xmm0
lea    0xe72(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
lea    -0x1d(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x1d(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_load>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x3,%esi
call   1040 <getloadavg@plt>
test   %eax,%eax
js     1195 <_get_load+0x55>
movslq %ebp,%rax
movsd  0x8(%rsp,%rax,8),%xmm0
lea    0xe92(%rip),%rsi
lea    0xb(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <sprintf@plt>
mov    (%rbx),%rbx
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%0.2f\00"
define i32 @_get_load(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x i8]
%8 = alloca [3 x double]
store i8** %0, i8*** %4
store i32 %1, i32* %5
%9 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%10 = call i32 @getloadavg(double* %9, i32 3)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %6
store i32 %14, i32* %3
br label %29
15: ; preds = %2
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 %19
%21 = load double, double* %20
%22 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %21)
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @strncpy(i8* %24, i8* %25, i32 %27)
store i32 0, i32* %3
br label %29
29: ; preds = %15, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [6 x i8] c"%0.2f\00"
define i32 @_get_load(i8** nocapture %0, i32 %1) {
%3 = alloca [5 x i8]
%4 = alloca [3 x double]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = bitcast [3 x double]* %4 to i8*
%7 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%8 = call i32 @getloadavg(double* %7, i32 3)
%9 = icmp slt i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %2
%11 = add nsw i32 %1, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 %12
%14 = load double, double* %13
%15 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %14)
%16 = load i8*, i8** %0
%17 = call i32 @strlen(i8* %5)
%18 = call i32 @strncpy(i8* %16, i8* %5, i32 %17)
br label %19
19: ; preds = %2, %10
%20 = phi i32 [ 0, %10 ], [ %8, %2 ]
ret i32 %20
}