#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 fscanf(int /*<<< orphan*/ *, char *, float *, float *, float *);
float getFloat(void *context, size_t i) {
  FILE *f = fopen("/proc/loadavg", "r");
  float shortterm, midterm, longterm;
  if (fscanf(f, "%f %f %f", &shortterm, &midterm, &longterm) == 3) {
    fclose(f);
    switch (i) {
    case 0:
      return shortterm;
    case 1:
      return midterm;
    case 2:
      return longterm;
    }
  }
  fclose(f);
  return 0.0;
}


x86 assembly (clang, -O0):
<getFloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xeb9(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xeae(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1040 <fscanf@plt>
cmp    $0x3,%eax
jne    11f3 <getFloat+0xc3>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
test   %rax,%rax
je     11c1 <getFloat+0x91>
jmp    119b <getFloat+0x6b>
mov    -0x38(%rbp),%rax
sub    $0x1,%rax
je     11d0 <getFloat+0xa0>
jmp    11ae <getFloat+0x7e>
mov    -0x38(%rbp),%rax
sub    $0x2,%rax
je     11df <getFloat+0xaf>
jmp    11ee <getFloat+0xbe>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1204 <getFloat+0xd4>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1204 <getFloat+0xd4>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1204 <getFloat+0xd4>
jmp    11f3 <getFloat+0xc3>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFloat>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
lea    0xebf(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xeb9(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x3,%eax
jne    1194 <getFloat+0x64>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x2,%r14
je     11a7 <getFloat+0x77>
cmp    $0x1,%r14
je     11af <getFloat+0x7f>
test   %r14,%r14
jne    1194 <getFloat+0x64>
movss  0x14(%rsp),%xmm0
jmp    119f <getFloat+0x6f>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
movss  0xc(%rsp),%xmm0
jmp    119f <getFloat+0x6f>
movss  0x10(%rsp),%xmm0
jmp    119f <getFloat+0x6f>

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"
define float @getFloat(i8* %0, i64 %1) {
%3 = alloca float
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca float
%8 = alloca float
%9 = alloca float
store i8* %0, i8** %4
store i64 %1, i64* %5
%10 = 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* %10, i32** %6
%11 = load i32*, i32** %6
%12 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float* %7, float* %8, float* %9)
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
%17 = load i64, i64* %5
switch i64 %17, label %24 [
i64 0, label %18
i64 1, label %20
i64 2, label %22
]
18: ; preds = %14
%19 = load float, float* %7
store float %19, float* %3
br label %28
20: ; preds = %14
%21 = load float, float* %8
store float %21, float* %3
br label %28
22: ; preds = %14
%23 = load float, float* %9
store float %23, float* %3
br label %28
24: ; preds = %14
br label %25
25: ; preds = %24, %2
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
store float 0.000000e+00, float* %3
br label %28
28: ; preds = %25, %22, %20, %18
%29 = load float, float* %3
ret float %29
}

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"
define float @getFloat(i8* nocapture readnone %0, i64 %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = 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))
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = bitcast float* %5 to i8*
%10 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float* %3, float* %4, float* %5)
%11 = icmp eq i32 %10, 3
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = call i32 @fclose(i32* %6)
switch i64 %1, label %20 [
i64 0, label %14
i64 1, label %16
i64 2, label %18
]
14: ; preds = %12
%15 = load float, float* %3
br label %22
16: ; preds = %12
%17 = load float, float* %4
br label %22
18: ; preds = %12
%19 = load float, float* %5
br label %22
20: ; preds = %12, %2
%21 = call i32 @fclose(i32* %6)
br label %22
22: ; preds = %20, %18, %16, %14
%23 = phi float [ 0.000000e+00, %20 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ]
ret float %23
}