#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 /*<<< orphan*/ printf(char *, double);
scalar_t__ read_stat(unsigned int *, unsigned int *);
int /*<<< orphan*/ usleep(double);
int main(int argc, char **argv) {
  unsigned int length = 1;
  unsigned int current = 0;
  while (1) {
    if (read_stat(&current, &length) == 0)
      printf("[P %f]\n", (double)current / (double)length);
    usleep(0.5 * 1000000);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <read_stat@plt>
cmp    $0x0,%rax
jne    118b <main+0x5b>
mov    -0x18(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe6d(%rip),%xmm0
call   1050 <usleep@plt>
jmp    1154 <main+0x24>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%rbx
lea    0xeae(%rip),%r15
jmp    116d <main+0x3d>
nopl   0x0(%rax)
movsd  0xe98(%rip),%xmm0
call   1050 <usleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <read_stat@plt>
test   %rax,%rax
jne    1160 <main+0x30>
mov    0x8(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0xc(%rsp),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
mov    %r15,%rdi
call   1030 <printf@plt>
jmp    1160 <main+0x30>

LLVM IR (-O0):
@.str = [8 x i8] c"[P %f]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %2, %18
%9 = call i64 @read_stat(i32* %7, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* %7
%13 = uitofp i32 %12 to double
%14 = load i32, i32* %6
%15 = uitofp i32 %14 to double
%16 = fdiv double %13, %15
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %16)
br label %18
18: ; preds = %11, %8
%19 = call i32 @usleep(double 5.000000e+05)
br label %8
}

LLVM IR (-O2):
@.str = [8 x i8] c"[P %f]\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %17, %2
%8 = call i64 @read_stat(i32* %4, i32* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %4
%12 = uitofp i32 %11 to double
%13 = load i32, i32* %3
%14 = uitofp i32 %13 to double
%15 = fdiv double %12, %14
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %15)
br label %17
17: ; preds = %10, %7
%18 = call i32 @usleep(double 5.000000e+05)
br label %7
}