#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
scalar_t__ get_line(int, char *);
int open(char *, int, ...);
int /*<<< orphan*/ sprintf(char *, char *, int, float, float, float,
                           unsigned int, unsigned int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, unsigned int *,
                          unsigned int *, unsigned int *, unsigned int *,
                          unsigned int *, unsigned int *, unsigned int *,
                          unsigned int *, unsigned int *, unsigned int *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  char buff[255];
  int load;
  int nrun, itick;
  unsigned int user, system, nice, total;
  unsigned int sw, jf;
  unsigned int idle, tot, sched, heavy;
  int fd = open("load.txt", O_RDONLY);
  int out = open("grin3.txt", O_WRONLY | O_CREAT, 0777);
  while (get_line(fd, buff) >= 0) {
    sscanf(buff,
           "<6>Oink %d ||"
           "%u %u||"
           "%u %u %u %u||"
           "%u %u||"
           "%u %u %u %u",
           &load, &itick, &nrun, &user, &system, &nice, &total, &sw, &jf, &idle,
           &tot, &sched, &heavy);
    sprintf(buff, "%u %f %f %f %u %u %d\n", nrun, ((float)user) / total,
            ((float)system) / total, ((float)nice) / total, sw, jf, load);
    write(out, buff, strlen(buff));
    get_line(fd, buff);
  }
  close(fd);
  close(out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x148(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
lea    0xe51(%rip),%rdi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14c(%rbp)
mov    -0x148(%rbp),%edi
lea    -0x110(%rbp),%rsi
call   1040 <get_line@plt>
cmp    $0x0,%rax
jl     133e <main+0x1ce>
mov    %rsp,%rax
mov    %rax,-0x170(%rbp)
lea    -0x144(%rbp),%rcx
mov    %rcx,0x40(%rax)
lea    -0x140(%rbp),%rcx
mov    %rcx,0x38(%rax)
lea    -0x13c(%rbp),%rcx
mov    %rcx,0x30(%rax)
lea    -0x138(%rbp),%rcx
mov    %rcx,0x28(%rax)
lea    -0x134(%rbp),%rcx
mov    %rcx,0x20(%rax)
lea    -0x130(%rbp),%rcx
mov    %rcx,0x18(%rax)
lea    -0x12c(%rbp),%rcx
mov    %rcx,0x10(%rax)
lea    -0x128(%rbp),%rcx
mov    %rcx,0x8(%rax)
lea    -0x124(%rbp),%rcx
mov    %rcx,(%rax)
lea    0xdba(%rip),%rsi
lea    -0x110(%rbp),%rdi
mov    %rdi,-0x168(%rbp)
lea    -0x114(%rbp),%rdx
lea    -0x11c(%rbp),%rcx
lea    -0x118(%rbp),%r8
lea    -0x120(%rbp),%r9
call   1070 <sscanf@plt>
mov    -0x168(%rbp),%rdi
mov    -0x118(%rbp),%edx
mov    -0x120(%rbp),%eax
cvtsi2ss %rax,%xmm0
mov    -0x12c(%rbp),%eax
cvtsi2ss %rax,%xmm3
divss  %xmm3,%xmm0
mov    -0x124(%rbp),%eax
cvtsi2ss %rax,%xmm1
divss  %xmm3,%xmm1
mov    -0x128(%rbp),%eax
cvtsi2ss %rax,%xmm2
divss  %xmm3,%xmm2
mov    -0x130(%rbp),%ecx
mov    -0x134(%rbp),%r8d
mov    -0x114(%rbp),%r9d
lea    0xd5f(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x14c(%rbp),%eax
mov    %eax,-0x15c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x15c(%rbp),%edi
mov    -0x158(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x148(%rbp),%edi
lea    -0x110(%rbp),%rsi
call   1040 <get_line@plt>
jmp    11ca <main+0x5a>
mov    -0x148(%rbp),%edi
call   1060 <close@plt>
mov    -0x14c(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebx
mov    0x2e27(%rip),%rax
mov    0x2e50(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe56(%rip),%rdi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%r15d
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
call   1040 <get_line@plt>
test   %rax,%rax
js     12cc <main+0x15c>
lea    0x40(%rsp),%rbp
lea    0x24(%rsp),%r14
lea    0x20(%rsp),%r12
lea    0xe5a(%rip),%r13
nopl   (%rax)
sub    $0x8,%rsp
mov    %rbp,%rdi
lea    0xe15(%rip),%rsi
lea    0x30(%rsp),%rdx
lea    0x44(%rsp),%rcx
mov    %r14,%r8
mov    %r12,%r9
lea    0x34(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
lea    0x4c(%rsp),%rax
push   %rax
lea    0x58(%rsp),%rax
push   %rax
lea    0x34(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
lea    0x4c(%rsp),%rax
push   %rax
lea    0x58(%rsp),%rax
push   %rax
lea    0x64(%rsp),%rax
push   %rax
call   1070 <sscanf@plt>
add    $0x50,%rsp
mov    0x20(%rsp),%eax
cvtsi2ss %rax,%xmm0
mov    0x14(%rsp),%eax
cvtsi2ss %rax,%xmm3
mov    0x24(%rsp),%edx
divss  %xmm3,%xmm0
mov    0x1c(%rsp),%eax
cvtsi2ss %rax,%xmm1
divss  %xmm3,%xmm1
mov    0x18(%rsp),%eax
cvtsi2ss %rax,%xmm2
divss  %xmm3,%xmm2
mov    0x10(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x28(%rsp),%r9d
mov    %rbp,%rdi
mov    %r13,%rsi
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1040 <get_line@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1040 <get_line@plt>
test   %rax,%rax
jns    11f0 <main+0x80>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"load.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"grin3.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [52 x i8] c"<6>Oink %d ||%u %u||%u %u %u %u||%u %u||%u %u %u %u\00"
@.str.3 = [22 x i8] c"%u %f %f %f %u %u %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %1
%18 = load i32, i32* @O_RDONLY
%19 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %16
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %20, %21
%23 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 511)
store i32 %23, i32* %17
br label %24
24: ; preds = %29, %0
%25 = load i32, i32* %16
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%27 = call i64 @get_line(i32 %25, i8* %26)
%28 = icmp sge i64 %27, 0
br i1 %28, label %29, label %61
29: ; preds = %24
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%31 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %5, i32* %4, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %14, i32* %15)
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%33 = load i32, i32* %4
%34 = load i32, i32* %6
%35 = uitofp i32 %34 to float
%36 = load i32, i32* %9
%37 = uitofp i32 %36 to float
%38 = fdiv float %35, %37
%39 = load i32, i32* %7
%40 = uitofp i32 %39 to float
%41 = load i32, i32* %9
%42 = uitofp i32 %41 to float
%43 = fdiv float %40, %42
%44 = load i32, i32* %8
%45 = uitofp i32 %44 to float
%46 = load i32, i32* %9
%47 = uitofp i32 %46 to float
%48 = fdiv float %45, %47
%49 = load i32, i32* %10
%50 = load i32, i32* %11
%51 = load i32, i32* %3
%52 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %33, float %38, float %43, float %48, i32 %49, i32 %50, i32 %51)
%53 = load i32, i32* %17
%54 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%55 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @write(i32 %53, i8* %54, i32 %56)
%58 = load i32, i32* %16
%59 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%60 = call i64 @get_line(i32 %58, i8* %59)
br label %24
61: ; preds = %24
%62 = load i32, i32* %16
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* %17
%65 = call i32 @close(i32 %64)
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@.str = [9 x i8] c"load.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"grin3.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [52 x i8] c"<6>Oink %d ||%u %u||%u %u %u %u||%u %u||%u %u %u %u\00"
@.str.3 = [22 x i8] c"%u %f %f %f %u %u %d\0A\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%16 = bitcast i32* %2 to i8*
%17 = bitcast i32* %3 to i8*
%18 = bitcast i32* %4 to i8*
%19 = bitcast i32* %5 to i8*
%20 = bitcast i32* %6 to i8*
%21 = bitcast i32* %7 to i8*
%22 = bitcast i32* %8 to i8*
%23 = bitcast i32* %9 to i8*
%24 = bitcast i32* %10 to i8*
%25 = bitcast i32* %11 to i8*
%26 = bitcast i32* %12 to i8*
%27 = bitcast i32* %13 to i8*
%28 = bitcast i32* %14 to i8*
%29 = load i32, i32* @O_RDONLY
%30 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* @O_WRONLY
%32 = load i32, i32* @O_CREAT
%33 = or i32 %32, %31
%34 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 511)
%35 = call i64 @get_line(i32 %30, i8* %15)
%36 = icmp sgt i64 %35, -1
br i1 %36, label %37, label %60
37: ; preds = %0, %37
%38 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %4, i32* %3, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %14)
%39 = load i32, i32* %3
%40 = load i32, i32* %5
%41 = uitofp i32 %40 to float
%42 = load i32, i32* %8
%43 = uitofp i32 %42 to float
%44 = fdiv float %41, %43
%45 = load i32, i32* %6
%46 = uitofp i32 %45 to float
%47 = fdiv float %46, %43
%48 = load i32, i32* %7
%49 = uitofp i32 %48 to float
%50 = fdiv float %49, %43
%51 = load i32, i32* %9
%52 = load i32, i32* %10
%53 = load i32, i32* %2
%54 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %39, float %44, float %47, float %50, i32 %51, i32 %52, i32 %53)
%55 = call i32 @strlen(i8* %15)
%56 = call i32 @write(i32 %34, i8* %15, i32 %55)
%57 = call i64 @get_line(i32 %30, i8* %15)
%58 = call i64 @get_line(i32 %30, i8* %15)
%59 = icmp sgt i64 %58, -1
br i1 %59, label %37, label %60
60: ; preds = %37, %0
%61 = call i32 @close(i32 %30)
%62 = call i32 @close(i32 %34)
ret i32 0
}