#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 /*<<< orphan*/ O_RDONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err_exit(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/, int);
size_t read(int, char *, int);
int sscanf(char *, char *, double *, double *, double *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void loadavg(double *av1, double *av5, double *av15) {
  size_t num_bytes_read;
  int fd;
  char read_buf[128];
  fd = open("/proc/loadavg", O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH);
  if (fd != -1) {
    if ((num_bytes_read = read(fd, read_buf, 128)) != -1) {
      if (sscanf(read_buf, "%lf %lf %lf", &(*av1), &(*av5), &(*av15)) == 3) {
        close(fd);
      } else {
        err_exit("Erron on sscanf, %s %d\n", strerror(errno), 64);
      }
    } else {
      err_exit("Erron on read, %s %d\n", strerror(errno), 67);
    }
  } else {
    err_exit("Error on open, %s %d\n", strerror(errno), 70);
  }
}


x86 assembly (clang, -O0):
<loadavg>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    0x2e40(%rip),%rax
or     (%rax),%edx
mov    0x2e2f(%rip),%rax
or     (%rax),%edx
lea    0xe5e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     1257 <loadavg+0xf7>
mov    -0x24(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
call   1040 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0xffffffffffffffff,%rax
je     1231 <loadavg+0xd1>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe1e(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x3,%eax
jne    120b <loadavg+0xab>
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
jmp    122c <loadavg+0xcc>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xdf8(%rip),%rdi
mov    $0x40,%edx
call   1050 <err_exit@plt>
jmp    1252 <loadavg+0xf2>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xdea(%rip),%rdi
mov    $0x43,%edx
call   1050 <err_exit@plt>
jmp    1278 <loadavg+0x118>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xdda(%rip),%rdi
mov    $0x46,%edx
call   1050 <err_exit@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadavg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e6b(%rip),%rax
mov    0x2e3c(%rip),%rcx
mov    0x2e45(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%edx
lea    0xe5f(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11f3 <loadavg+0x93>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x80,%edx
call   1040 <read@plt>
cmp    $0xffffffffffffffff,%rax
je     1211 <loadavg+0xb1>
lea    0xe45(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <sscanf@plt>
cmp    $0x3,%eax
jne    122f <loadavg+0xcf>
mov    %ebp,%edi
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <close@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe40(%rip),%rdi
mov    %eax,%esi
mov    $0x46,%edx
jmp    124b <loadavg+0xeb>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe0c(%rip),%rdi
mov    %eax,%esi
mov    $0x43,%edx
jmp    124b <loadavg+0xeb>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdd6(%rip),%rdi
mov    %eax,%esi
mov    $0x40,%edx
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <err_exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/loadavg\00"
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [12 x i8] c"%lf %lf %lf\00"
@.str.2 = [24 x i8] c"Erron on sscanf, %s %d\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"Erron on read, %s %d\0A\00"
@.str.4 = [22 x i8] c"Error on open, %s %d\0A\00"
define void @loadavg(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [128 x i8]
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%10 = load i32, i32* @O_RDONLY
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IRGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IROTH
%15 = or i32 %13, %14
%16 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %44
19: ; preds = %3
%20 = load i32, i32* %8
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%22 = call i64 @read(i32 %20, i8* %21, i32 128)
store i64 %22, i64* %7
%23 = icmp ne i64 %22, -1
br i1 %23, label %24, label %39
24: ; preds = %19
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%26 = load double*, double** %4
%27 = load double*, double** %5
%28 = load double*, double** %6
%29 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double* %26, double* %27, double* %28)
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32, i32* %8
%33 = call i32 @close(i32 %32)
br label %38
34: ; preds = %24
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 @err_exit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 64)
br label %38
38: ; preds = %34, %31
br label %43
39: ; preds = %19
%40 = load i32, i32* @errno
%41 = call i32 @strerror(i32 %40)
%42 = call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 67)
br label %43
43: ; preds = %39, %38
br label %48
44: ; preds = %3
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 70)
br label %48
48: ; preds = %44, %43
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/loadavg\00"
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [12 x i8] c"%lf %lf %lf\00"
@.str.2 = [24 x i8] c"Erron on sscanf, %s %d\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"Erron on read, %s %d\0A\00"
@.str.4 = [22 x i8] c"Error on open, %s %d\0A\00"
define void @loadavg(double* %0, double* %1, double* %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IRGRP
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IROTH
%11 = or i32 %9, %10
%12 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %30, label %14
14: ; preds = %3
%15 = call i64 @read(i32 %12, i8* %5, i32 128)
%16 = icmp eq i64 %15, -1
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double* %0, double* %1, double* %2)
%19 = icmp eq i32 %18, 3
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @close(i32 %12)
br label %34
22: ; preds = %17
%23 = load i32, i32* @errno
%24 = tail call i32 @strerror(i32 %23)
%25 = tail call i32 @err_exit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 64)
br label %34
26: ; preds = %14
%27 = load i32, i32* @errno
%28 = tail call i32 @strerror(i32 %27)
%29 = tail call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 67)
br label %34
30: ; preds = %3
%31 = load i32, i32* @errno
%32 = tail call i32 @strerror(i32 %31)
%33 = tail call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 70)
br label %34
34: ; preds = %26, %22, %20, %30
ret void
}