#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*/ die(char *);
int /*<<< orphan*/ die_sans_errno(char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned long *, unsigned long *,
           unsigned long *, unsigned long *, unsigned long *, unsigned long *,
           unsigned long *, unsigned long *, unsigned long *, unsigned long *);
int /*<<< orphan*/ multithread_write(char *, int *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int snprintf(char *, int, char *, double);
int /*<<< orphan*/ timeout(int /*<<< orphan*/, int);
void *cpu_mon(void *thread_id) {
  FILE *procstat = fopen("/proc/stat", "r");
  if (procstat == NULL) {
    die("couldn't open /proc/stat in cpu_mon");
  }
  unsigned long int start_stats[10];
  int values_read =
      fscanf(procstat, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
             start_stats + 0, start_stats + 1, start_stats + 2, start_stats + 3,
             start_stats + 4, start_stats + 5, start_stats + 6, start_stats + 7,
             start_stats + 8, start_stats + 9);
  if (values_read != 10) {
    if (ferror(procstat)) {
      die("first fscanf on /proc/stat in cpu_mon failed");
    } else {
      die_sans_errno(
          "matching error for first fscanf on /proc/stat in cpu_mon");
    }
  }
  timeout(0, 250000000);
  rewind(procstat);
  unsigned long int end_stats[10];
  values_read = fscanf(
      procstat, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", end_stats + 0,
      end_stats + 1, end_stats + 2, end_stats + 3, end_stats + 4, end_stats + 5,
      end_stats + 6, end_stats + 7, end_stats + 8, end_stats + 9);
  if (values_read != 10) {
    if (ferror(procstat)) {
      die("second fscanf on /proc/stat in cpu_mon failed");
    } else {
      die_sans_errno(
          "matching error for second fscanf on /proc/stat in cpu_mon");
    }
  }
  if (fclose(procstat) != 0) {
    die("couldn't close /proc/stat in cpu_mon");
  }
  int i;
  unsigned long int total_starting_cpu_time = 0;
  unsigned long int total_ending_cpu_time = 0;
  for (i = 0; i < 10; i++) {
    total_starting_cpu_time += start_stats[i];
    total_ending_cpu_time += end_stats[i];
  }
  unsigned long int starting_cpu_work = total_starting_cpu_time -
                                        start_stats[3] - start_stats[4] -
                                        start_stats[7];
  unsigned long int ending_cpu_work =
      total_ending_cpu_time - end_stats[3] - end_stats[4] - end_stats[7];
  double percent_cpu_load =
      ((double)(ending_cpu_work - starting_cpu_work) /
       (double)(total_ending_cpu_time - total_starting_cpu_time)) *
      100;
  char out_buffer[20];
  int bytes_written = snprintf(out_buffer, 20, "cpu:%3.0f%%", percent_cpu_load);
  if (bytes_written < 0) {
    die_sans_errno("snprintf in cpu_mon failed");
  }
  multithread_write(out_buffer, (int *)thread_id);
  return NULL;
}


x86 assembly (clang, -O0):
<cpu_mon>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x158,%rsp
mov    %rdi,-0x20(%rbp)
lea    0xe75(%rip),%rdi
lea    0xe79(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e2 <cpu_mon+0x42>
lea    0xe60(%rip),%rdi
call   10b0 <die@plt>
mov    -0x28(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    -0x80(%rbp),%rcx
add    $0x8,%rcx
lea    -0x80(%rbp),%r8
add    $0x10,%r8
lea    -0x80(%rbp),%r9
add    $0x18,%r9
lea    -0x80(%rbp),%r15
add    $0x20,%r15
lea    -0x80(%rbp),%r14
add    $0x28,%r14
lea    -0x80(%rbp),%rbx
add    $0x30,%rbx
lea    -0x80(%rbp),%r11
add    $0x38,%r11
lea    -0x80(%rbp),%r10
add    $0x40,%r10
lea    -0x80(%rbp),%rax
add    $0x48,%rax
lea    0xe28(%rip),%rsi
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1080 <fscanf@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xa,-0x84(%rbp)
je     12a3 <cpu_mon+0x103>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1292 <cpu_mon+0xf2>
lea    0xe05(%rip),%rdi
call   10b0 <die@plt>
jmp    129e <cpu_mon+0xfe>
lea    0xe21(%rip),%rdi
call   10c0 <die_sans_errno@plt>
jmp    12a3 <cpu_mon+0x103>
xor    %edi,%edi
mov    $0xee6b280,%esi
call   1070 <timeout@plt>
mov    -0x28(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x28(%rbp),%rdi
lea    -0xe0(%rbp),%rdx
lea    -0xe0(%rbp),%rcx
add    $0x8,%rcx
lea    -0xe0(%rbp),%r8
add    $0x10,%r8
lea    -0xe0(%rbp),%r9
add    $0x18,%r9
lea    -0xe0(%rbp),%r15
add    $0x20,%r15
lea    -0xe0(%rbp),%r14
add    $0x28,%r14
lea    -0xe0(%rbp),%rbx
add    $0x30,%rbx
lea    -0xe0(%rbp),%r11
add    $0x38,%r11
lea    -0xe0(%rbp),%r10
add    $0x40,%r10
lea    -0xe0(%rbp),%rax
add    $0x48,%rax
lea    0xd34(%rip),%rsi
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1080 <fscanf@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xa,-0x84(%rbp)
je     1397 <cpu_mon+0x1f7>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1386 <cpu_mon+0x1e6>
lea    0xd77(%rip),%rdi
call   10b0 <die@plt>
jmp    1392 <cpu_mon+0x1f2>
lea    0xd94(%rip),%rdi
call   10c0 <die_sans_errno@plt>
jmp    1397 <cpu_mon+0x1f7>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     13b6 <cpu_mon+0x216>
lea    0xdaa(%rip),%rdi
call   10b0 <die@plt>
movq   $0x0,-0xf0(%rbp)
movq   $0x0,-0xf8(%rbp)
movl   $0x0,-0xe4(%rbp)
cmpl   $0xa,-0xe4(%rbp)
jge    142e <cpu_mon+0x28e>
movslq -0xe4(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rax
add    -0xf0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
movslq -0xe4(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rax
ff
add    -0xf8(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    13d6 <cpu_mon+0x236>
mov    -0xf0(%rbp),%rax
mov    -0x68(%rbp),%rdx
mov    -0x60(%rbp),%rcx
sub    %rdx,%rax
sub    %rcx,%rax
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x100(%rbp)
mov    -0xf8(%rbp),%rax
mov    -0xc8(%rbp),%rdx
mov    -0xc0(%rbp),%rcx
sub    %rdx,%rax
sub    %rcx,%rax
mov    -0xa8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    -0x100(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xb76(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xb7a(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0xf8(%rbp),%rax
mov    -0xf0(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xb16(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x110(%rbp)
ff
lea    -0x130(%rbp),%rdi
movsd  -0x110(%rbp),%xmm0
ff
mov    $0x14,%esi
lea    0xc6f(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jge    1535 <cpu_mon+0x395>
lea    0xc5c(%rip),%rdi
call   10c0 <die_sans_errno@plt>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <multithread_write@plt>
xor    %eax,%eax
add    $0x158,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_mon>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc0,%rsp
mov    %rdi,%r14
lea    0xe6e(%rip),%rdi
lea    0xe72(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11da <cpu_mon+0x3a>
lea    0xe60(%rip),%rdi
call   10b0 <die@plt>
lea    0x58(%rsp),%rcx
lea    0x60(%rsp),%r8
lea    0x68(%rsp),%r9
lea    0x70(%rsp),%r10
lea    0x78(%rsp),%r11
lea    0x80(%rsp),%r15
lea    0x88(%rsp),%r12
lea    0x90(%rsp),%r13
lea    0x98(%rsp),%rax
lea    0xe3f(%rip),%rsi
lea    0x50(%rsp),%rdx
mov    %rbx,%rdi
push   %rax
push   %r13
push   %r12
push   %r15
push   %r11
push   %r10
call   1080 <fscanf@plt>
add    $0x30,%rsp
cmp    $0xa,%eax
je     1262 <cpu_mon+0xc2>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1256 <cpu_mon+0xb6>
lea    0xe36(%rip),%rdi
call   10b0 <die@plt>
jmp    1262 <cpu_mon+0xc2>
lea    0xe55(%rip),%rdi
call   10c0 <die_sans_errno@plt>
xor    %edi,%edi
mov    $0xee6b280,%esi
call   1070 <timeout@plt>
mov    %rbx,%rdi
call   1050 <rewind@plt>
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x18(%rsp),%r9
lea    0x20(%rsp),%r10
lea    0x28(%rsp),%r11
lea    0x30(%rsp),%r15
lea    0x38(%rsp),%r12
lea    0x40(%rsp),%r13
lea    0x48(%rsp),%rax
lea    0xdaf(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
push   %rax
push   %r13
push   %r12
push   %r15
push   %r11
push   %r10
call   1080 <fscanf@plt>
add    $0x30,%rsp
cmp    $0xa,%eax
je     12f0 <cpu_mon+0x150>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     12e4 <cpu_mon+0x144>
lea    0xe0e(%rip),%rdi
call   10b0 <die@plt>
jmp    12f0 <cpu_mon+0x150>
lea    0xe2e(%rip),%rdi
call   10c0 <die_sans_errno@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1309 <cpu_mon+0x169>
lea    0xe4f(%rip),%rdi
call   10b0 <die@plt>
mov    0x68(%rsp),%rax
mov    0x70(%rsp),%r9
mov    0x18(%rsp),%rcx
mov    0x20(%rsp),%r8
mov    0x88(%rsp),%rdi
pshufd $0x4e,0x90(%rsp),%xmm0
movq   0x78(%rsp),%xmm1
movq   0x80(%rsp),%xmm2
punpcklqdq %xmm1,%xmm2
paddq  %xmm0,%xmm2
pshufd $0xee,%xmm2,%xmm0
paddq  %xmm2,%xmm0
movq   %xmm0,%rsi
add    0x60(%rsp),%rsi
add    0x58(%rsp),%rsi
add    0x50(%rsp),%rsi
mov    0x38(%rsp),%rbx
add    %rdi,%rsi
pshufd $0x4e,0x40(%rsp),%xmm0
add    %r9,%rsi
movq   0x28(%rsp),%xmm1
movq   0x30(%rsp),%xmm2
punpcklqdq %xmm1,%xmm2
paddq  %xmm0,%xmm2
pshufd $0xee,%xmm2,%xmm0
paddq  %xmm2,%xmm0
movq   %xmm0,%rdx
add    0x10(%rsp),%rdx
add    0x8(%rsp),%rdx
add    %rax,%rsi
add    (%rsp),%rdx
add    %rbx,%rdx
add    %r8,%rdx
add    %rcx,%rdx
sub    %rsi,%rdx
add    %rdx,%rax
add    %r9,%rax
add    %rdi,%rax
add    %r8,%rcx
add    %rbx,%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movdqa 0xc2d(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xc31(%rip),%xmm3
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movq   %rdx,%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
mulsd  0xc0c(%rip),%xmm0
lea    0xd5d(%rip),%rdx
lea    0xa0(%rsp),%rdi
mov    $0x14,%esi
call   1060 <snprintf@plt>
test   %eax,%eax
jns    143d <cpu_mon+0x29d>
lea    0xd4c(%rip),%rdi
call   10c0 <die_sans_errno@plt>
lea    0xa0(%rsp),%rdi
mov    %r14,%rsi
call   1090 <multithread_write@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"couldn't open /proc/stat in cpu_mon\00"
@.str.3 = [44 x i8] c"cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\00"
@.str.4 = [45 x i8] c"first fscanf on /proc/stat in cpu_mon failed\00"
@.str.5 = [57 x i8] c"matching error for first fscanf on /proc/stat in cpu_mon\00"
@.str.6 = [46 x i8] c"second fscanf on /proc/stat in cpu_mon failed\00"
@.str.7 = [58 x i8] c"matching error for second fscanf on /proc/stat in cpu_mon\00"
@.str.8 = [37 x i8] c"couldn't close /proc/stat in cpu_mon\00"
@.str.9 = [12 x i8] c"cpu:%3.0f%%\00"
@.str.10 = [27 x i8] c"snprintf in cpu_mon failed\00"
define i8* @cpu_mon(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [10 x i64]
%5 = alloca i32
%6 = alloca [10 x i64]
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
%13 = alloca [20 x i8]
%14 = alloca i32
store i8* %0, i8** %2
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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** %3
%16 = load i32*, i32** %3
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %1
%21 = load i32*, i32** %3
%22 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%23 = getelementptr inbounds i64, i64* %22, i64 0
%24 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%25 = getelementptr inbounds i64, i64* %24, i64 1
%26 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%27 = getelementptr inbounds i64, i64* %26, i64 2
%28 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%29 = getelementptr inbounds i64, i64* %28, i64 3
%30 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%31 = getelementptr inbounds i64, i64* %30, i64 4
%32 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%33 = getelementptr inbounds i64, i64* %32, i64 5
%34 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%35 = getelementptr inbounds i64, i64* %34, i64 6
%36 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%37 = getelementptr inbounds i64, i64* %36, i64 7
%38 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%39 = getelementptr inbounds i64, i64* %38, i64 8
%40 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%41 = getelementptr inbounds i64, i64* %40, i64 9
%42 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64* %23, i64* %25, i64* %27, i64* %29, i64* %31, i64* %33, i64* %35, i64* %37, i64* %39, i64* %41)
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 10
br i1 %44, label %45, label %54
45: ; preds = %20
%46 = load i32*, i32** %3
%47 = call i64 @ferror(i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %53
51: ; preds = %45
%52 = call i32 @die_sans_errno(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
br label %54
54: ; preds = %53, %20
%55 = call i32 @timeout(i32 0, i32 250000000)
%56 = load i32*, i32** %3
%57 = call i32 @rewind(i32* %56)
%58 = load i32*, i32** %3
%59 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%60 = getelementptr inbounds i64, i64* %59, i64 0
%61 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%62 = getelementptr inbounds i64, i64* %61, i64 1
%63 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%64 = getelementptr inbounds i64, i64* %63, i64 2
%65 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%66 = getelementptr inbounds i64, i64* %65, i64 3
%67 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%68 = getelementptr inbounds i64, i64* %67, i64 4
%69 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%70 = getelementptr inbounds i64, i64* %69, i64 5
%71 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%72 = getelementptr inbounds i64, i64* %71, i64 6
%73 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%74 = getelementptr inbounds i64, i64* %73, i64 7
%75 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%76 = getelementptr inbounds i64, i64* %75, i64 8
%77 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%78 = getelementptr inbounds i64, i64* %77, i64 9
%79 = call i32 @fscanf(i32* %58, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64* %60, i64* %62, i64* %64, i64* %66, i64* %68, i64* %70, i64* %72, i64* %74, i64* %76, i64* %78)
store i32 %79, i32* %5
%80 = load i32, i32* %5
%81 = icmp ne i32 %80, 10
br i1 %81, label %82, label %91
82: ; preds = %54
%83 = load i32*, i32** %3
%84 = call i64 @ferror(i32* %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %82
%87 = call i32 @die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
br label %90
88: ; preds = %82
%89 = call i32 @die_sans_errno(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0))
br label %90
90: ; preds = %88, %86
br label %91
91: ; preds = %90, %54
%92 = load i32*, i32** %3
%93 = call i64 @fclose(i32* %92)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @die(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
br label %97
97: ; preds = %95, %91
store i64 0, i64* %8
store i64 0, i64* %9
store i32 0, i32* %7
br label %98
98: ; preds = %114, %97
%99 = load i32, i32* %7
%100 = icmp slt i32 %99, 10
br i1 %100, label %101, label %117
101: ; preds = %98
%102 = load i32, i32* %7
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 %103
%105 = load i64, i64* %104
%106 = load i64, i64* %8
%107 = add i64 %106, %105
store i64 %107, i64* %8
%108 = load i32, i32* %7
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 %109
%111 = load i64, i64* %110
%112 = load i64, i64* %9
%113 = add i64 %112, %111
store i64 %113, i64* %9
br label %114
114: ; preds = %101
%115 = load i32, i32* %7
%116 = add nsw i32 %115, 1
store i32 %116, i32* %7
br label %98
117: ; preds = %98
%118 = load i64, i64* %8
%119 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 3
%120 = load i64, i64* %119
%121 = sub i64 %118, %120
%122 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 4
%123 = load i64, i64* %122
%124 = sub i64 %121, %123
%125 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 7
%126 = load i64, i64* %125
%127 = sub i64 %124, %126
store i64 %127, i64* %10
%128 = load i64, i64* %9
%129 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 3
%130 = load i64, i64* %129
%131 = sub i64 %128, %130
%132 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 4
%133 = load i64, i64* %132
%134 = sub i64 %131, %133
%135 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 7
%136 = load i64, i64* %135
%137 = sub i64 %134, %136
store i64 %137, i64* %11
%138 = load i64, i64* %11
%139 = load i64, i64* %10
%140 = sub i64 %138, %139
%141 = uitofp i64 %140 to double
%142 = load i64, i64* %9
%143 = load i64, i64* %8
%144 = sub i64 %142, %143
%145 = uitofp i64 %144 to double
%146 = fdiv double %141, %145
%147 = fmul double %146, 1.000000e+02
store double %147, double* %12
%148 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%149 = load double, double* %12
%150 = call i32 @snprintf(i8* %148, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %149)
store i32 %150, i32* %14
%151 = load i32, i32* %14
%152 = icmp slt i32 %151, 0
br i1 %152, label %153, label %155
153: ; preds = %117
%154 = call i32 @die_sans_errno(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %155
155: ; preds = %153, %117
%156 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%157 = load i8*, i8** %2
%158 = bitcast i8* %157 to i32*
%159 = call i32 @multithread_write(i8* %156, i32* %158)
ret i8* null
}

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"couldn't open /proc/stat in cpu_mon\00"
@.str.3 = [44 x i8] c"cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\00"
@.str.4 = [45 x i8] c"first fscanf on /proc/stat in cpu_mon failed\00"
@.str.5 = [57 x i8] c"matching error for first fscanf on /proc/stat in cpu_mon\00"
@.str.6 = [46 x i8] c"second fscanf on /proc/stat in cpu_mon failed\00"
@.str.7 = [58 x i8] c"matching error for second fscanf on /proc/stat in cpu_mon\00"
@.str.8 = [37 x i8] c"couldn't close /proc/stat in cpu_mon\00"
@.str.9 = [12 x i8] c"cpu:%3.0f%%\00"
@.str.10 = [27 x i8] c"snprintf in cpu_mon failed\00"
define noalias i8* @cpu_mon(i8* %0) {
%2 = alloca [10 x i64]
%3 = alloca [10 x i64]
%4 = alloca [20 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = bitcast [10 x i64]* %2 to i8*
%11 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 0
%12 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 1
%13 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 2
%14 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 3
%15 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 4
%16 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 5
%17 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 6
%18 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 7
%19 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 8
%20 = getelementptr inbounds [10 x i64], [10 x i64]* %2, i64 0, i64 9
%21 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64* %11, i64* %12, i64* %13, i64* %14, i64* %15, i64* %16, i64* %17, i64* %18, i64* %19, i64* %20)
%22 = icmp eq i32 %21, 10
br i1 %22, label %30, label %23
23: ; preds = %9
%24 = call i64 @ferror(i32* %5)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 @die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %30
28: ; preds = %23
%29 = call i32 @die_sans_errno(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %26, %28, %9
%31 = call i32 @timeout(i32 0, i32 250000000)
%32 = call i32 @rewind(i32* %5)
%33 = bitcast [10 x i64]* %3 to i8*
%34 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 0
%35 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 1
%36 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 2
%37 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 3
%38 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 4
%39 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 5
%40 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 6
%41 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 7
%42 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 8
%43 = getelementptr inbounds [10 x i64], [10 x i64]* %3, i64 0, i64 9
%44 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64* %34, i64* %35, i64* %36, i64* %37, i64* %38, i64* %39, i64* %40, i64* %41, i64* %42, i64* %43)
%45 = icmp eq i32 %44, 10
br i1 %45, label %53, label %46
46: ; preds = %30
%47 = call i64 @ferror(i32* %5)
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %46
%50 = call i32 @die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
br label %53
51: ; preds = %46
%52 = call i32 @die_sans_errno(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0))
br label %53
53: ; preds = %49, %51, %30
%54 = call i64 @fclose(i32* %5)
%55 = icmp eq i64 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %53
%57 = call i32 @die(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
%59 = load i64, i64* %11
%60 = load i64, i64* %34
%61 = load i64, i64* %12
%62 = load i64, i64* %35
%63 = load i64, i64* %13
%64 = load i64, i64* %36
%65 = load i64, i64* %14
%66 = load i64, i64* %37
%67 = load i64, i64* %15
%68 = load i64, i64* %38
%69 = load i64, i64* %16
%70 = load i64, i64* %39
%71 = load i64, i64* %17
%72 = load i64, i64* %40
%73 = load i64, i64* %18
%74 = load i64, i64* %41
%75 = bitcast i64* %19 to <2 x i64>*
%76 = load <2 x i64>, <2 x i64>* %75
%77 = bitcast i64* %42 to <2 x i64>*
%78 = load <2 x i64>, <2 x i64>* %77
%79 = shufflevector <2 x i64> %76, <2 x i64> poison, <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
%80 = insertelement <4 x i64> %79, i64 %71, i64 2
%81 = insertelement <4 x i64> %80, i64 %69, i64 3
%82 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> %81)
%83 = add i64 %82, %63
%84 = add i64 %83, %61
%85 = add i64 %84, %59
%86 = add i64 %85, %73
%87 = add i64 %86, %67
%88 = add i64 %87, %65
%89 = shufflevector <2 x i64> %78, <2 x i64> poison, <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
%90 = insertelement <4 x i64> %89, i64 %72, i64 2
%91 = insertelement <4 x i64> %90, i64 %70, i64 3
%92 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> %91)
%93 = add i64 %92, %64
%94 = add i64 %93, %62
%95 = add i64 %94, %60
%96 = add i64 %95, %74
%97 = add i64 %96, %68
%98 = add i64 %97, %66
%99 = sub i64 %98, %88
%100 = add i64 %99, %65
%101 = add i64 %100, %67
%102 = add i64 %101, %73
%103 = add i64 %66, %68
%104 = add i64 %103, %74
%105 = sub i64 %102, %104
%106 = uitofp i64 %105 to double
%107 = uitofp i64 %99 to double
%108 = fdiv double %106, %107
%109 = fmul double %108, 1.000000e+02
%110 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%111 = call i32 @snprintf(i8* %110, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %109)
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %58
%114 = call i32 @die_sans_errno(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %115
115: ; preds = %113, %58
%116 = bitcast i8* %0 to i32*
%117 = call i32 @multithread_write(i8* %110, i32* %116)
ret i8* null
}