#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*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getbattery();
int *getcpuload();
char *getdatetime();
float getfreq(char *);
char *getnetusage();
float getpower();
char *malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, int, int, int,
                            int, float, float, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  char *status;
  float cpu0;
  char *datetime;
  int bat0;
  float pwr;
  char *net;
  int *load;
  if ((status = malloc(200)) == NULL)
    exit(1);
  FILE *out = fopen("/tmp/status", "w");
  if (out == NULL) {
    fprintf(stderr, "Can't open outfile!");
    exit(1);
  }
  getnetusage();
  for (;; sleep(1)) {
    cpu0 = getfreq("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq");
    datetime = getdatetime();
    bat0 = getbattery();
    pwr = getpower();
    net = getnetusage();
    load = getcpuload();
    snprintf(status, 200,
             "%s     %d%% %d%% %d%% %d%%     %d%% %0.2fW     %0.2fGHz     %s",
             net, load[0], load[1], load[2], load[3], bat0, pwr, cpu0,
             datetime);
    fprintf(out, "%s\n\n\n", status);
    rewind(out);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
movl   $0x0,-0xc(%rbp)
mov    $0xc8,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1202 <main+0x32>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xdf7(%rip),%rdi
lea    0xdfc(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1246 <main+0x76>
mov    0x2db5(%rip),%rax
movslq (%rax),%rdi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10c0 <getnetusage@plt>
lea    0xdce(%rip),%rdi
call   10e0 <getfreq@plt>
movss  %xmm0,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <getdatetime@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1090 <getbattery@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   10a0 <getpower@plt>
movss  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   10c0 <getnetusage@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getcpuload@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    (%rax),%r8d
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%r9d
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%ebx
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x2c(%rbp),%r10d
movss  -0x30(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
mov    -0x28(%rbp),%rax
mov    $0xc8,%esi
lea    0xd7f(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1050 <snprintf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1040 <rewind@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
jmp    124d <main+0x7d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xc8,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12d6 <main+0xf6>
mov    %rax,%r14
lea    0xdf8(%rip),%rdi
lea    0xdfd(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12e0 <main+0x100>
mov    %rax,%r13
xor    %eax,%eax
call   10c0 <getnetusage@plt>
nopw   0x0(%rax,%rax,1)
lea    0xdeb(%rip),%rdi
call   10f0 <getfreq@plt>
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1070 <getdatetime@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1090 <getbattery@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   10a0 <getpower@plt>
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   10c0 <getnetusage@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <getcpuload@plt>
mov    (%rax),%r8d
mov    0x4(%rax),%r9d
mov    0x8(%rax),%ebx
mov    0xc(%rax),%eax
mov    %r14,%rdi
mov    $0xc8,%esi
lea    0xdc9(%rip),%rdx
mov    %r12,%rcx
movss  (%rsp),%xmm0
movss  0x4(%rsp),%xmm1
push   %rbp
push   %r15
push   %rax
push   %rbx
call   1050 <snprintf@plt>
add    $0x20,%rsp
mov    %r13,%rdi
lea    0xde2(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r13,%rdi
call   1040 <rewind@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
jmp    1230 <main+0x50>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2cf9(%rip),%rax
movslq (%rax),%rcx
lea    0xd1d(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/status\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"Can't open outfile!\00"
@.str.3 = [54 x i8] c"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq\00"
@.str.4 = [63 x i8] c"%s %d%% %d%% %d%% %d%% %d%% %0.2fW %0.2fGHz %s\00"
@.str.5 = [6 x i8] c"%s\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca float
%4 = alloca i8*
%5 = alloca i32
%6 = alloca float
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %1
%10 = call i8* @malloc(i32 200)
store i8* %10, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i32*
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = call i8* (...) @getnetusage()
br label %26
26: ; preds = %57, %24
%27 = call float @getfreq(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
store float %27, float* %3
%28 = call i8* (...) @getdatetime()
store i8* %28, i8** %4
%29 = call i32 (...) @getbattery()
store i32 %29, i32* %5
%30 = call float (...) @getpower()
store float %30, float* %6
%31 = call i8* (...) @getnetusage()
store i8* %31, i8** %7
%32 = call i32* (...) @getcpuload()
store i32* %32, i32** %8
%33 = load i8*, i8** %2
%34 = load i8*, i8** %7
%35 = load i32*, i32** %8
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = load i32*, i32** %8
%39 = getelementptr inbounds i32, i32* %38, i64 1
%40 = load i32, i32* %39
%41 = load i32*, i32** %8
%42 = getelementptr inbounds i32, i32* %41, i64 2
%43 = load i32, i32* %42
%44 = load i32*, i32** %8
%45 = getelementptr inbounds i32, i32* %44, i64 3
%46 = load i32, i32* %45
%47 = load i32, i32* %5
%48 = load float, float* %6
%49 = load float, float* %3
%50 = load i8*, i8** %4
%51 = call i32 @snprintf(i8* %33, i32 200, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 %37, i32 %40, i32 %43, i32 %46, i32 %47, float %48, float %49, i8* %50)
%52 = load i32*, i32** %9
%53 = load i8*, i8** %2
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = load i32*, i32** %9
%56 = call i32 @rewind(i32* %55)
br label %57
57: ; preds = %26
%58 = call i32 @sleep(i32 1)
br label %26
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/status\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"Can't open outfile!\00"
@.str.3 = [54 x i8] c"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq\00"
@.str.4 = [63 x i8] c"%s %d%% %d%% %d%% %d%% %d%% %0.2fW %0.2fGHz %s\00"
@.str.5 = [6 x i8] c"%s\0A\0A\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @exit(i32 1)
unreachable
5: ; preds = %0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 19, i64 1, i32* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = tail call i8* (...) @getnetusage()
br label %16
16: ; preds = %16, %14
%17 = tail call float @getfreq(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i8* (...) @getdatetime()
%19 = tail call i32 (...) @getbattery()
%20 = tail call float (...) @getpower()
%21 = tail call i8* (...) @getnetusage()
%22 = tail call i32* (...) @getcpuload()
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32, i32* %22, i64 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds i32, i32* %22, i64 2
%27 = load i32, i32* %26
%28 = getelementptr inbounds i32, i32* %22, i64 3
%29 = load i32, i32* %28
%30 = tail call i32 @snprintf(i8* %1, i32 200, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i8* %21, i32 %23, i32 %25, i32 %27, i32 %29, i32 %19, float %20, float %17, i8* %18)
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%32 = tail call i32 @rewind(i32* %6)
%33 = tail call i32 @sleep(i32 1)
br label %16
}