#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *, float *,
                          float *);
int /*<<< orphan*/ sprintf(char *, char *, float, float, float);
char *obterLoadAverage() {
  char loadAVG[100];
  float load1;
  float load2;
  float load3;
  FILE *loadavg;
  loadavg = fopen("/proc/loadavg", "r");
  fscanf(loadavg, "%f %f %f", &load1, &load2, &load3);
  fclose(loadavg);
  sprintf(loadAVG, "%1.2f %1.2f %1.2f", load1, load2, load3);
  return loadAVG;
}


x86 assembly (clang, -O0):
<obterLoadAverage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
lea    0xe9d(%rip),%rsi
lea    -0x74(%rbp),%rdx
lea    -0x78(%rbp),%rcx
lea    -0x7c(%rbp),%r8
call   1040 <fscanf@plt>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x70(%rbp),%rdi
movss  -0x74(%rbp),%xmm0
movss  -0x78(%rbp),%xmm1
movss  -0x7c(%rbp),%xmm2
lea    0xe6f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obterLoadAverage>:
push   %rbx
sub    $0x80,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xeab(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
movss  0x4(%rsp),%xmm2
lea    0xe7c(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/loadavg\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%f %f %f\00"
@.str.3 = [18 x i8] c"%1.2f %1.2f %1.2f\00"
define i8* @obterLoadAverage() {
%1 = alloca [100 x i8]
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i32*
%6 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float* %2, float* %3, float* %4)
%9 = load i32*, i32** %5
%10 = call i32 @fclose(i32* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%12 = load float, float* %2
%13 = load float, float* %3
%14 = load float, float* %4
%15 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), float %12, float %13, float %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
ret i8* %16
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/loadavg\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%f %f %f\00"
@.str.3 = [18 x i8] c"%1.2f %1.2f %1.2f\00"
define noalias i8* @obterLoadAverage() {
%1 = alloca [100 x i8]
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = bitcast float* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float* %2, float* %3, float* %4)
%11 = call i32 @fclose(i32* %9)
%12 = load float, float* %2
%13 = load float, float* %3
%14 = load float, float* %4
%15 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), float %12, float %13, float %14)
ret i8* %5
}