#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 */
typedef struct syslinfo TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ info;
struct syslinfo {
  char *sl_date;
  char *sl_time;
  char *sl_load1;
  char *sl_load2;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int load(void) {
  struct syslinfo {
    char sl_date[12];
    char sl_time[8];
    char sl_load1[6];
    char sl_load2[10];
  } info;
  FILE *fl;
  int ld, i, sum;
  static int previous[5];
  static int p_point = -1;
  extern int slow_death;
  if (!(fl = fopen("/tmp/.sysline", "r"))) {
    perror("sysline. (dying)");
    slow_death = 1;
    return (-1);
  }
  if (!fread(&info, sizeof(info), 1, fl)) {
    perror("fread sysline (dying)");
    slow_death = 1;
    return (-1);
  }
  fclose(fl);
  if (p_point < 0) {
    previous[0] = atoi(info.sl_load1);
    for (i = 1; i < 5; i++)
      previous[i] = previous[0];
    p_point = 1;
    return (previous[0]);
  } else {
    previous[p_point] = atoi(info.sl_load1);
    if (++p_point > 4)
      p_point = 0;
    for (i = 0, sum = 0; i < 5; i++)
      sum += previous[i];
    return ((int)sum / 5);
  }
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xea1(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    119e <load+0x4e>
lea    0xe90(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e5c(%rip),%rax
movl   $0x1,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <load+0x191>
lea    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x24,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    11e3 <load+0x93>
lea    0xe5c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e17(%rip),%rax
movl   $0x1,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <load+0x191>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,0x2e55(%rip)
jge    1257 <load+0x107>
lea    -0x28(%rbp),%rdi
add    $0x14,%rdi
call   1070 <atoi@plt>
mov    %eax,0x2e54(%rip)
movl   $0x1,-0x38(%rbp)
cmpl   $0x5,-0x38(%rbp)
jge    123f <load+0xef>
mov    0x2e3d(%rip),%edx
movslq -0x38(%rbp),%rcx
lea    0x2e32(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1213 <load+0xc3>
movl   $0x1,0x2dff(%rip)
mov    0x2e11(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    12e1 <load+0x191>
lea    -0x28(%rbp),%rdi
add    $0x14,%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
movslq 0x2ddb(%rip),%rcx
lea    0x2dec(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    0x2dcb(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2dc2(%rip)
cmp    $0x4,%eax
jle    1299 <load+0x149>
movl   $0x0,0x2daf(%rip)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x5,-0x38(%rbp)
jge    12d3 <load+0x183>
movslq -0x38(%rbp),%rcx
lea    0x2da4(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12a7 <load+0x157>
mov    -0x3c(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %rbx
sub    $0x30,%rsp
lea    0xea4(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1229 <load+0xd9>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x24,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     1232 <load+0xe2>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2ea7(%rip),%ebx
lea    0x1c(%rsp),%rdi
call   1070 <atoi@plt>
test   %ebx,%ebx
js     1206 <load+0xb6>
lea    0x2eaa(%rip),%rcx
mov    %eax,(%rcx,%rbx,4)
lea    0x1(%rbx),%eax
xor    %ecx,%ecx
cmp    $0x4,%ebx
cmovb  %eax,%ecx
mov    %ecx,0x2e7e(%rip)
movdqu 0x2e92(%rip),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
add    0x2e72(%rip),%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
jmp    1250 <load+0x100>
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,0x2e49(%rip)
mov    %eax,0x2e53(%rip)
movl   $0x1,0x2e21(%rip)
jmp    1250 <load+0x100>
lea    0xde0(%rip),%rdi
jmp    1239 <load+0xe9>
lea    0xde8(%rip),%rdi
call   1060 <perror@plt>
mov    0x2da3(%rip),%rax
movl   $0x1,(%rax)
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.syslinfo = type { [12 x i8], [8 x i8], [6 x i8], [10 x i8] }
%struct.syslinfo.0 = type { i8*, i8*, i8*, i8* }
@load.previous = internal global [5 x i32] zeroinitializer
@load.p_point = internal global i32 -1
@.str = [14 x i8] c"/tmp/.sysline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"sysline. (dying)\00"
@slow_death = external global i32
@.str.3 = [22 x i8] c"fread sysline (dying)\00"
define i32 @load() {
%1 = alloca i32
%2 = alloca %struct.syslinfo
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = 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* %7, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* @slow_death
store i32 -1, i32* %1
br label %68
11: ; preds = %0
%12 = bitcast %struct.syslinfo* %2 to %struct.syslinfo.0*
%13 = load i32*, i32** %3
%14 = call i32 @fread(%struct.syslinfo.0* %12, i32 36, i32 1, i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* @slow_death
store i32 -1, i32* %1
br label %68
18: ; preds = %11
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* @load.p_point
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %40
23: ; preds = %18
%24 = getelementptr inbounds %struct.syslinfo, %struct.syslinfo* %2, i32 0, i32 2
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %24, i64 0, i64 0
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* getelementptr inbounds ([5 x i32], [5 x i32]* @load.previous, i64 0, i64 0)
store i32 1, i32* %5
br label %27
27: ; preds = %35, %23
%28 = load i32, i32* %5
%29 = icmp slt i32 %28, 5
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i32, i32* getelementptr inbounds ([5 x i32], [5 x i32]* @load.previous, i64 0, i64 0)
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [5 x i32], [5 x i32]* @load.previous, i64 0, i64 %33
store i32 %31, i32* %34
br label %35
35: ; preds = %30
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %27
38: ; preds = %27
store i32 1, i32* @load.p_point
%39 = load i32, i32* getelementptr inbounds ([5 x i32], [5 x i32]* @load.previous, i64 0, i64 0)
store i32 %39, i32* %1
br label %68
40: ; preds = %18
%41 = getelementptr inbounds %struct.syslinfo, %struct.syslinfo* %2, i32 0, i32 2
%42 = getelementptr inbounds [6 x i8], [6 x i8]* %41, i64 0, i64 0
%43 = call i32 @atoi(i8* %42)
%44 = load i32, i32* @load.p_point
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [5 x i32], [5 x i32]* @load.previous, i64 0, i64 %45
store i32 %43, i32* %46
%47 = load i32, i32* @load.p_point
%48 = add nsw i32 %47, 1
store i32 %48, i32* @load.p_point
%49 = icmp sgt i32 %48, 4
br i1 %49, label %50, label %51
50: ; preds = %40
store i32 0, i32* @load.p_point
br label %51
51: ; preds = %50, %40
store i32 0, i32* %5
store i32 0, i32* %6
br label %52
52: ; preds = %62, %51
%53 = load i32, i32* %5
%54 = icmp slt i32 %53, 5
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [5 x i32], [5 x i32]* @load.previous, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = load i32, i32* %6
%61 = add nsw i32 %60, %59
store i32 %61, i32* %6
br label %62
62: ; preds = %55
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %52
65: ; preds = %52
%66 = load i32, i32* %6
%67 = sdiv i32 %66, 5
store i32 %67, i32* %1
br label %68
68: ; preds = %65, %38, %16, %9
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
%struct.syslinfo = type { [12 x i8], [8 x i8], [6 x i8], [10 x i8] }
%struct.syslinfo.0 = type { i8*, i8*, i8*, i8* }
@load.previous = internal unnamed_addr global [5 x i32] zeroinitializer
@load.p_point = internal unnamed_addr global i32 -1
@.str = [14 x i8] c"/tmp/.sysline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"sysline. (dying)\00"
@slow_death = external global i32
@.str.3 = [22 x i8] c"fread sysline (dying)\00"
define i32 @load() {
%1 = alloca %struct.syslinfo
%2 = getelementptr inbounds %struct.syslinfo, %struct.syslinfo* %1, i64 0, i32 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* @slow_death
br label %33
7: ; preds = %0
%8 = bitcast %struct.syslinfo* %1 to %struct.syslinfo.0*
%9 = call i32 @fread(%struct.syslinfo.0* %8, i32 36, i32 1, i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* @slow_death
br label %33
13: ; preds = %7
%14 = tail call i32 @fclose(i32* %3)
%15 = load i32, i32* @load.p_point
%16 = icmp slt i32 %15, 0
%17 = getelementptr inbounds %struct.syslinfo, %struct.syslinfo* %1, i64 0, i32 2, i64 0
%18 = call i32 @atoi(i8* %17)
br i1 %16, label %19, label %22
19: ; preds = %13
%20 = insertelement <4 x i32> poison, i32 %18, i64 0
%21 = shufflevector <4 x i32> %20, <4 x i32> poison, <4 x i32> zeroinitializer
store <4 x i32> %21, <4 x i32>* bitcast ([5 x i32]* @load.previous to <4 x i32>*)
store i32 %18, i32* getelementptr inbounds ([5 x i32], [5 x i32]* @load.previous, i64 0, i64 4)
store i32 1, i32* @load.p_point
br label %33
22: ; preds = %13
%23 = zext i32 %15 to i64
%24 = getelementptr inbounds [5 x i32], [5 x i32]* @load.previous, i64 0, i64 %23
store i32 %18, i32* %24
%25 = add nuw nsw i32 %15, 1
%26 = icmp ugt i32 %15, 3
%27 = select i1 %26, i32 0, i32 %25
store i32 %27, i32* @load.p_point
%28 = load i32, i32* getelementptr inbounds ([5 x i32], [5 x i32]* @load.previous, i64 0, i64 0)
%29 = load <4 x i32>, <4 x i32>* bitcast (i32* getelementptr inbounds ([5 x i32], [5 x i32]* @load.previous, i64 0, i64 1) to <4 x i32>*)
%30 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %29)
%31 = add nsw i32 %30, %28
%32 = sdiv i32 %31, 5
br label %33
33: ; preds = %22, %19, %11, %5
%34 = phi i32 [ %18, %19 ], [ %32, %22 ], [ -1, %11 ], [ -1, %5 ]
ret i32 %34
}