#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 {
  float *loads;
};

/* Variables and functions */
int SI_LOAD_SHIFT;
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, float, float, float);
char *strdup(char *);
int sysinfo(struct sysinfo *);
char *myuptime_get_load() {
  int str_len = 512;
  char *str;
  char *str_res;
  struct sysinfo si;
  str = calloc(str_len, sizeof(char));
  if (str == NULL)
    return NULL;
  if (sysinfo(&si) == -1)
    return NULL;
  sprintf(str, "%.2f, %.2f, %.2f", si.loads[0] / (float)(1 << SI_LOAD_SHIFT),
          si.loads[1] / (float)(1 << SI_LOAD_SHIFT),
          si.loads[2] / (float)(1 << SI_LOAD_SHIFT));
  str_res = strdup(str);
  free(str);
  return str_res;
}


x86 assembly (clang, -O0):
<myuptime_get_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x200,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1188 <myuptime_get_load+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1237 <myuptime_get_load+0xe7>
lea    -0x28(%rbp),%rdi
call   1050 <sysinfo@plt>
cmp    $0xffffffff,%eax
jne    11a7 <myuptime_get_load+0x57>
movq   $0x0,-0x8(%rbp)
jmp    1237 <myuptime_get_load+0xe7>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
movss  (%rax),%xmm0
mov    0x2e26(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    0x2e05(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm2
divss  %xmm2,%xmm1
mov    -0x28(%rbp),%rax
movss  0x8(%rax),%xmm2
mov    0x2de4(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm3
divss  %xmm3,%xmm2
lea    0xdec(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myuptime_get_load>:
push   %r14
push   %rbx
push   %rax
mov    $0x200,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     11ce <myuptime_get_load+0x7e>
mov    %rax,%r14
mov    %rsp,%rdi
call   1050 <sysinfo@plt>
cmp    $0xffffffff,%eax
je     11ce <myuptime_get_load+0x7e>
mov    0x2e61(%rip),%rax
mov    (%rax),%cl
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm3
mov    (%rsp),%rax
movss  (%rax),%xmm0
movss  0x4(%rax),%xmm1
divss  %xmm3,%xmm0
divss  %xmm3,%xmm1
movss  0x8(%rax),%xmm2
divss  %xmm3,%xmm2
lea    0xe4f(%rip),%rsi
mov    %r14,%rdi
call   1060 <sprintf@plt>
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11d0 <myuptime_get_load+0x80>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sysinfo = type { float* }
@.str = [17 x i8] c"%.2f, %.2f, %.2f\00"
@SI_LOAD_SHIFT = global i32 0
define i8* @myuptime_get_load() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.sysinfo
store i32 512, i32* %2
%6 = load i32, i32* %2
%7 = call i8* @calloc(i32 %6, i32 1)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i8* null, i8** %1
br label %47
11: ; preds = %0
%12 = call i32 @sysinfo(%struct.sysinfo* %5)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %11
store i8* null, i8** %1
br label %47
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %5, i32 0, i32 0
%18 = load float*, float** %17
%19 = getelementptr inbounds float, float* %18, i64 0
%20 = load float, float* %19
%21 = load i32, i32* @SI_LOAD_SHIFT
%22 = shl i32 1, %21
%23 = sitofp i32 %22 to float
%24 = fdiv float %20, %23
%25 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %5, i32 0, i32 0
%26 = load float*, float** %25
%27 = getelementptr inbounds float, float* %26, i64 1
%28 = load float, float* %27
%29 = load i32, i32* @SI_LOAD_SHIFT
%30 = shl i32 1, %29
%31 = sitofp i32 %30 to float
%32 = fdiv float %28, %31
%33 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %5, i32 0, i32 0
%34 = load float*, float** %33
%35 = getelementptr inbounds float, float* %34, i64 2
%36 = load float, float* %35
%37 = load i32, i32* @SI_LOAD_SHIFT
%38 = shl i32 1, %37
%39 = sitofp i32 %38 to float
%40 = fdiv float %36, %39
%41 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), float %24, float %32, float %40)
%42 = load i8*, i8** %3
%43 = call i8* @strdup(i8* %42)
store i8* %43, i8** %4
%44 = load i8*, i8** %3
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %4
store i8* %46, i8** %1
br label %47
47: ; preds = %15, %14, %10
%48 = load i8*, i8** %1
ret i8* %48
}

LLVM IR (-O2):
%struct.sysinfo = type { float* }
@.str = [17 x i8] c"%.2f, %.2f, %.2f\00"
@SI_LOAD_SHIFT = global i32 0
define noalias i8* @myuptime_get_load() {
%1 = alloca %struct.sysinfo
%2 = bitcast %struct.sysinfo* %1 to i8*
%3 = tail call dereferenceable_or_null(512) i8* @calloc(i32 512, i32 1)
%4 = icmp eq i8* %3, null
br i1 %4, label %25, label %5
5: ; preds = %0
%6 = call i32 @sysinfo(%struct.sysinfo* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %25, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 0
%10 = load float*, float** %9
%11 = load float, float* %10
%12 = load i32, i32* @SI_LOAD_SHIFT
%13 = shl nuw i32 1, %12
%14 = sitofp i32 %13 to float
%15 = fdiv float %11, %14
%16 = getelementptr inbounds float, float* %10, i64 1
%17 = load float, float* %16
%18 = fdiv float %17, %14
%19 = getelementptr inbounds float, float* %10, i64 2
%20 = load float, float* %19
%21 = fdiv float %20, %14
%22 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), float %15, float %18, float %21)
%23 = call i8* @strdup(i8* %3)
%24 = call i32 @free(i8* %3)
br label %25
25: ; preds = %5, %0, %8
%26 = phi i8* [ %23, %8 ], [ null, %0 ], [ null, %5 ]
ret i8* %26
}