#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*/ dosum(long);
long get_times(long, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int cpuusage(int usage) {
  long int times1 = get_times(100000, 1);
  long int times2 = get_times(times1 * 10000, 1000);
  int n = 10, step = 10;
  int precision = 1000;
  printf("cpu load usage: %d\n", usage);
  long int cacl_times = usage * times2 / 100;
  printf("cacl times %ld every second\n", cacl_times);
  long long int temp = 1000000 * (times2 - cacl_times) / times2;
  int sleep_time = temp;
  printf("sleep time %d us every second\n", sleep_time);
  while (1) {
    dosum(cacl_times);
    usleep(sleep_time);
    n += step;
    printf(".");
  }
  return 0;
}


x86 assembly (clang, -O0):
<cpuusage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x186a0,%edi
mov    $0x1,%esi
call   1030 <get_times@plt>
mov    %rax,-0x10(%rbp)
imul   $0x2710,-0x10(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <get_times@plt>
mov    %rax,-0x18(%rbp)
movl   $0xa,-0x1c(%rbp)
movl   $0xa,-0x20(%rbp)
movl   $0x3e8,-0x24(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x4(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
sub    -0x30(%rbp),%rax
imul   $0xf4240,%rax,%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <dosum@plt>
mov    -0x3c(%rbp),%edi
call   1060 <usleep@plt>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    %eax,-0x1c(%rbp)
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f4 <cpuusage+0xb4>

x86 assembly (clang, -O2):
<cpuusage>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x186a0,%edi
mov    $0x1,%esi
call   1040 <get_times@plt>
imul   $0x2710,%rax,%rdi
mov    $0x3e8,%esi
call   1040 <get_times@plt>
mov    %rax,%r14
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebx,%rcx
imul   %r14,%rcx
movabs $0xa3d70a3d70a3d70b,%rdx
0a d7 a3
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%r15
add    %rcx,%r15
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x6,%r15
add    %rax,%r15
lea    0xe58(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rax
sub    %r15,%rax
imul   $0xf4240,%rax,%rax
mov    %r14,%rcx
or     %rax,%rcx
shr    $0x20,%rcx
je     11e9 <cpuusage+0x99>
cqto
idiv   %r14
mov    %rax,%rbx
jmp    11f0 <cpuusage+0xa0>
xor    %edx,%edx
div    %r14d
mov    %eax,%ebx
lea    0xe3a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1060 <dosum@plt>
mov    %ebx,%edi
call   1070 <usleep@plt>
mov    $0x2e,%edi
call   1030 <putchar@plt>
jmp    1200 <cpuusage+0xb0>

LLVM IR (-O0):
@.str = [20 x i8] c"cpu load usage: %d\0A\00"
@.str.1 = [29 x i8] c"cacl times %ld every second\0A\00"
@.str.2 = [31 x i8] c"sleep time %d us every second\0A\00"
@.str.3 = [2 x i8] c".\00"
define i32 @cpuusage(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %2
%11 = call i64 @get_times(i64 100000, i32 1)
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = mul nsw i64 %12, 10000
%14 = call i64 @get_times(i64 %13, i32 1000)
store i64 %14, i64* %4
store i32 10, i32* %5
store i32 10, i32* %6
store i32 1000, i32* %7
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = load i64, i64* %4
%20 = mul nsw i64 %18, %19
%21 = sdiv i64 %20, 100
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %22)
%24 = load i64, i64* %4
%25 = load i64, i64* %8
%26 = sub nsw i64 %24, %25
%27 = mul nsw i64 1000000, %26
%28 = load i64, i64* %4
%29 = sdiv i64 %27, %28
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = trunc i64 %30 to i32
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %1, %34
%35 = load i64, i64* %8
%36 = call i32 @dosum(i64 %35)
%37 = load i32, i32* %10
%38 = call i32 @usleep(i32 %37)
%39 = load i32, i32* %6
%40 = load i32, i32* %5
%41 = add nsw i32 %40, %39
store i32 %41, i32* %5
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %34
}

LLVM IR (-O2):
@.str = [20 x i8] c"cpu load usage: %d\0A\00"
@.str.1 = [29 x i8] c"cacl times %ld every second\0A\00"
@.str.2 = [31 x i8] c"sleep time %d us every second\0A\00"
define i32 @cpuusage(i32 %0) {
%2 = tail call i64 @get_times(i64 100000, i32 1)
%3 = mul nsw i64 %2, 10000
%4 = tail call i64 @get_times(i64 %3, i32 1000)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = sext i32 %0 to i64
%7 = mul nsw i64 %4, %6
%8 = sdiv i64 %7, 100
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %8)
%10 = sub nsw i64 %4, %8
%11 = mul nsw i64 %10, 1000000
%12 = sdiv i64 %11, %4
%13 = trunc i64 %12 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %15, %1
%16 = tail call i32 @dosum(i64 %8)
%17 = tail call i32 @usleep(i32 %13)
%18 = tail call i32 @putchar(i32 46)
br label %15
}