#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 *io_mon(void *thread_id) {
  FILE *procstat = fopen("/proc/stat", "r");
  if (procstat == NULL) {
    die("couldn't open /proc/stat in io_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 io_mon failed");
    } else {
      die_sans_errno("matching error for first fscanf on /proc/stat in io_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 io_mon failed");
    } else {
      die_sans_errno(
          "matching error for second fscanf on /proc/stat in io_mon");
    }
  }
  if (fclose(procstat) != 0) {
    die("couldn't close /proc/stat in io_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];
  }
  double percent_iowait =
      ((double)(end_stats[4] - start_stats[4]) /
       (double)(total_ending_cpu_time - total_starting_cpu_time)) *
      100;
  char out_buffer[20];
  int bytes_written = snprintf(out_buffer, 20, "io:%3.0f%%", percent_iowait);
  if (bytes_written < 0) {
    die_sans_errno("snprintf in io_mon failed");
  }
  multithread_write(out_buffer, (int *)thread_id);
  return NULL;
}


x86 assembly (clang, -O0):
<io_mon>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x148,%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 <io_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    0xe27(%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 <io_mon+0x103>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1292 <io_mon+0xf2>
lea    0xe04(%rip),%rdi
call   10b0 <die@plt>
jmp    129e <io_mon+0xfe>
lea    0xe1f(%rip),%rdi
call   10c0 <die_sans_errno@plt>
jmp    12a3 <io_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    0xd33(%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 <io_mon+0x1f7>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1386 <io_mon+0x1e6>
lea    0xd74(%rip),%rdi
call   10b0 <die@plt>
jmp    1392 <io_mon+0x1f2>
lea    0xd90(%rip),%rdi
call   10c0 <die_sans_errno@plt>
jmp    1397 <io_mon+0x1f7>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     13b6 <io_mon+0x216>
lea    0xda5(%rip),%rdi
call   10b0 <die@plt>
movq   $0x0,-0xf0(%rbp)
movq   $0x0,-0xf8(%rbp)
movl   $0x0,-0xe4(%rbp)
cmpl   $0xa,-0xe4(%rbp)
jge    142e <io_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 <io_mon+0x236>
mov    -0xc0(%rbp),%rax
mov    -0x60(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xbc8(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xbcc(%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  0xb68(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x100(%rbp)
ff
lea    -0x120(%rbp),%rdi
movsd  -0x100(%rbp),%xmm0
ff
mov    $0x14,%esi
lea    0xcbb(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jge    14e3 <io_mon+0x343>
lea    0xca7(%rip),%rdi
call   10c0 <die_sans_errno@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <multithread_write@plt>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_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 <io_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    0xe3e(%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 <io_mon+0xc2>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1256 <io_mon+0xb6>
lea    0xe35(%rip),%rdi
call   10b0 <die@plt>
jmp    1262 <io_mon+0xc2>
lea    0xe53(%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    0xdae(%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 <io_mon+0x150>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     12e4 <io_mon+0x144>
lea    0xe0b(%rip),%rdi
call   10b0 <die@plt>
jmp    12f0 <io_mon+0x150>
lea    0xe2a(%rip),%rdi
call   10c0 <die_sans_errno@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1309 <io_mon+0x169>
lea    0xe4a(%rip),%rdi
call   10b0 <die@plt>
mov    0x70(%rsp),%rax
mov    0x20(%rsp),%rcx
movdqa 0x90(%rsp),%xmm0
movq   0x88(%rsp),%xmm1
punpcklqdq %xmm1,%xmm0
movq   0x78(%rsp),%xmm1
movq   0x80(%rsp),%xmm2
punpcklqdq %xmm1,%xmm2
movq   0x60(%rsp),%xmm1
movq   0x68(%rsp),%xmm3
punpcklqdq %xmm1,%xmm3
paddq  %xmm0,%xmm3
movq   0x50(%rsp),%xmm0
movq   0x58(%rsp),%xmm1
punpcklqdq %xmm0,%xmm1
paddq  %xmm2,%xmm1
paddq  %xmm3,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddq  %xmm1,%xmm0
movq   %xmm0,%rdx
add    %rax,%rdx
movdqa 0x40(%rsp),%xmm0
movq   0x38(%rsp),%xmm1
punpcklqdq %xmm1,%xmm0
movq   0x28(%rsp),%xmm1
movq   0x30(%rsp),%xmm2
punpcklqdq %xmm1,%xmm2
movq   0x10(%rsp),%xmm1
movq   0x18(%rsp),%xmm3
punpcklqdq %xmm1,%xmm3
paddq  %xmm0,%xmm3
movq   (%rsp),%xmm0
movq   0x8(%rsp),%xmm1
punpcklqdq %xmm0,%xmm1
paddq  %xmm2,%xmm1
paddq  %xmm3,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddq  %xmm1,%xmm0
movq   %xmm0,%rsi
add    0x98(%rsp),%rdx
add    %rcx,%rsi
add    0x48(%rsp),%rsi
sub    %rdx,%rsi
sub    %rax,%rcx
movq   %rcx,%xmm1
movdqa 0xc0b(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xc0f(%rip),%xmm3
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movq   %rsi,%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
mulsd  0xbea(%rip),%xmm0
lea    0xd35(%rip),%rdx
lea    0xa0(%rsp),%rdi
mov    $0x14,%esi
call   1060 <snprintf@plt>
test   %eax,%eax
jns    145f <io_mon+0x2bf>
lea    0xd23(%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 = [35 x i8] c"couldn't open /proc/stat in io_mon\00"
@.str.3 = [44 x i8] c"cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\00"
@.str.4 = [44 x i8] c"first fscanf on /proc/stat in io_mon failed\00"
@.str.5 = [56 x i8] c"matching error for first fscanf on /proc/stat in io_mon\00"
@.str.6 = [45 x i8] c"second fscanf on /proc/stat in io_mon failed\00"
@.str.7 = [57 x i8] c"matching error for second fscanf on /proc/stat in io_mon\00"
@.str.8 = [36 x i8] c"couldn't close /proc/stat in io_mon\00"
@.str.9 = [11 x i8] c"io:%3.0f%%\00"
@.str.10 = [26 x i8] c"snprintf in io_mon failed\00"
define i8* @io_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 double
%11 = alloca [20 x i8]
%12 = alloca i32
store i8* %0, i8** %2
%13 = 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* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @die(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
%19 = load i32*, i32** %3
%20 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%21 = getelementptr inbounds i64, i64* %20, i64 0
%22 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%23 = getelementptr inbounds i64, i64* %22, i64 1
%24 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%25 = getelementptr inbounds i64, i64* %24, i64 2
%26 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%27 = getelementptr inbounds i64, i64* %26, i64 3
%28 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%29 = getelementptr inbounds i64, i64* %28, i64 4
%30 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%31 = getelementptr inbounds i64, i64* %30, i64 5
%32 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%33 = getelementptr inbounds i64, i64* %32, i64 6
%34 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%35 = getelementptr inbounds i64, i64* %34, i64 7
%36 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%37 = getelementptr inbounds i64, i64* %36, i64 8
%38 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 0
%39 = getelementptr inbounds i64, i64* %38, i64 9
%40 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64* %21, i64* %23, i64* %25, i64* %27, i64* %29, i64* %31, i64* %33, i64* %35, i64* %37, i64* %39)
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, 10
br i1 %42, label %43, label %52
43: ; preds = %18
%44 = load i32*, i32** %3
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %51
49: ; preds = %43
%50 = call i32 @die_sans_errno(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
br label %52
52: ; preds = %51, %18
%53 = call i32 @timeout(i32 0, i32 250000000)
%54 = load i32*, i32** %3
%55 = call i32 @rewind(i32* %54)
%56 = load i32*, i32** %3
%57 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%58 = getelementptr inbounds i64, i64* %57, i64 0
%59 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%60 = getelementptr inbounds i64, i64* %59, i64 1
%61 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%62 = getelementptr inbounds i64, i64* %61, i64 2
%63 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%64 = getelementptr inbounds i64, i64* %63, i64 3
%65 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%66 = getelementptr inbounds i64, i64* %65, i64 4
%67 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%68 = getelementptr inbounds i64, i64* %67, i64 5
%69 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%70 = getelementptr inbounds i64, i64* %69, i64 6
%71 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%72 = getelementptr inbounds i64, i64* %71, i64 7
%73 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%74 = getelementptr inbounds i64, i64* %73, i64 8
%75 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 0
%76 = getelementptr inbounds i64, i64* %75, i64 9
%77 = call i32 @fscanf(i32* %56, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64* %58, i64* %60, i64* %62, i64* %64, i64* %66, i64* %68, i64* %70, i64* %72, i64* %74, i64* %76)
store i32 %77, i32* %5
%78 = load i32, i32* %5
%79 = icmp ne i32 %78, 10
br i1 %79, label %80, label %89
80: ; preds = %52
%81 = load i32*, i32** %3
%82 = call i64 @ferror(i32* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = call i32 @die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %88
86: ; preds = %80
%87 = call i32 @die_sans_errno(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
br label %88
88: ; preds = %86, %84
br label %89
89: ; preds = %88, %52
%90 = load i32*, i32** %3
%91 = call i64 @fclose(i32* %90)
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %95
95: ; preds = %93, %89
store i64 0, i64* %8
store i64 0, i64* %9
store i32 0, i32* %7
br label %96
96: ; preds = %112, %95
%97 = load i32, i32* %7
%98 = icmp slt i32 %97, 10
br i1 %98, label %99, label %115
99: ; preds = %96
%100 = load i32, i32* %7
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 %101
%103 = load i64, i64* %102
%104 = load i64, i64* %8
%105 = add i64 %104, %103
store i64 %105, i64* %8
%106 = load i32, i32* %7
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 %107
%109 = load i64, i64* %108
%110 = load i64, i64* %9
%111 = add i64 %110, %109
store i64 %111, i64* %9
br label %112
112: ; preds = %99
%113 = load i32, i32* %7
%114 = add nsw i32 %113, 1
store i32 %114, i32* %7
br label %96
115: ; preds = %96
%116 = getelementptr inbounds [10 x i64], [10 x i64]* %6, i64 0, i64 4
%117 = load i64, i64* %116
%118 = getelementptr inbounds [10 x i64], [10 x i64]* %4, i64 0, i64 4
%119 = load i64, i64* %118
%120 = sub i64 %117, %119
%121 = uitofp i64 %120 to double
%122 = load i64, i64* %9
%123 = load i64, i64* %8
%124 = sub i64 %122, %123
%125 = uitofp i64 %124 to double
%126 = fdiv double %121, %125
%127 = fmul double %126, 1.000000e+02
store double %127, double* %10
%128 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%129 = load double, double* %10
%130 = call i32 @snprintf(i8* %128, i32 20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), double %129)
store i32 %130, i32* %12
%131 = load i32, i32* %12
%132 = icmp slt i32 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %115
%134 = call i32 @die_sans_errno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %135
135: ; preds = %133, %115
%136 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%137 = load i8*, i8** %2
%138 = bitcast i8* %137 to i32*
%139 = call i32 @multithread_write(i8* %136, i32* %138)
ret i8* null
}

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"couldn't open /proc/stat in io_mon\00"
@.str.3 = [44 x i8] c"cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\00"
@.str.4 = [44 x i8] c"first fscanf on /proc/stat in io_mon failed\00"
@.str.5 = [56 x i8] c"matching error for first fscanf on /proc/stat in io_mon\00"
@.str.6 = [45 x i8] c"second fscanf on /proc/stat in io_mon failed\00"
@.str.7 = [57 x i8] c"matching error for second fscanf on /proc/stat in io_mon\00"
@.str.8 = [36 x i8] c"couldn't close /proc/stat in io_mon\00"
@.str.9 = [11 x i8] c"io:%3.0f%%\00"
@.str.10 = [26 x i8] c"snprintf in io_mon failed\00"
define noalias i8* @io_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 ([35 x i8], [35 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 ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %30
28: ; preds = %23
%29 = call i32 @die_sans_errno(i8* getelementptr inbounds ([56 x i8], [56 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 ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %53
51: ; preds = %46
%52 = call i32 @die_sans_errno(i8* getelementptr inbounds ([57 x i8], [57 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 ([36 x i8], [36 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 = shufflevector <2 x i64> %76, <2 x i64> poison, <8 x i32> <i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%78 = insertelement <8 x i64> %77, i64 %73, i64 1
%79 = insertelement <8 x i64> %78, i64 %71, i64 2
%80 = insertelement <8 x i64> %79, i64 %69, i64 3
%81 = insertelement <8 x i64> %80, i64 %65, i64 4
%82 = insertelement <8 x i64> %81, i64 %63, i64 5
%83 = insertelement <8 x i64> %82, i64 %61, i64 6
%84 = insertelement <8 x i64> %83, i64 %59, i64 7
%85 = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %84)
%86 = add i64 %85, %67
%87 = bitcast i64* %42 to <2 x i64>*
%88 = load <2 x i64>, <2 x i64>* %87
%89 = shufflevector <2 x i64> %88, <2 x i64> poison, <8 x i32> <i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%90 = insertelement <8 x i64> %89, i64 %74, i64 1
%91 = insertelement <8 x i64> %90, i64 %72, i64 2
%92 = insertelement <8 x i64> %91, i64 %70, i64 3
%93 = insertelement <8 x i64> %92, i64 %66, i64 4
%94 = insertelement <8 x i64> %93, i64 %64, i64 5
%95 = insertelement <8 x i64> %94, i64 %62, i64 6
%96 = insertelement <8 x i64> %95, i64 %60, i64 7
%97 = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %96)
%98 = add i64 %97, %68
%99 = load i64, i64* %20
%100 = add i64 %99, %86
%101 = load i64, i64* %43
%102 = add i64 %101, %98
%103 = sub i64 %68, %67
%104 = uitofp i64 %103 to double
%105 = sub i64 %102, %100
%106 = uitofp i64 %105 to double
%107 = fdiv double %104, %106
%108 = fmul double %107, 1.000000e+02
%109 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%110 = call i32 @snprintf(i8* %109, i32 20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), double %108)
%111 = icmp slt i32 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %58
%113 = call i32 @die_sans_errno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %114
114: ; preds = %112, %58
%115 = bitcast i8* %0 to i32*
%116 = call i32 @multithread_write(i8* %109, i32* %115)
ret i8* null
}