#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 linear_add() {
  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 linear add\n");
  while (1) {
    dosum((long int)times2 * n);
    usleep((precision - n) * precision);
    if (n > precision) {
      n = step;
      printf("n is begining\n");
    }
    n += step;
  }
  return 0;
}


x86 assembly (clang, -O0):
<linear_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x186a0,%edi
mov    $0x1,%esi
call   1030 <get_times@plt>
mov    %rax,-0x8(%rbp)
imul   $0x2710,-0x8(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <get_times@plt>
mov    %rax,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
movl   $0xa,-0x18(%rbp)
movl   $0x3e8,-0x1c(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
imul   %rax,%rdi
call   1050 <dosum@plt>
mov    -0x1c(%rbp),%edi
sub    -0x14(%rbp),%edi
imul   -0x1c(%rbp),%edi
call   1060 <usleep@plt>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11d0 <linear_add+0x90>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <linear_add+0x52>

x86 assembly (clang, -O2):
<linear_add>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
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,%r15
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%ebp
lea    0xe98(%rip),%r14
jmp    1193 <linear_add+0x53>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xa,%ebp
movslq %ebp,%rbx
mov    %r15,%rdi
imul   %rbx,%rdi
call   1050 <dosum@plt>
mov    $0x3e8,%eax
sub    %ebx,%eax
imul   $0x3e8,%eax,%edi
call   1060 <usleep@plt>
cmp    $0x3e9,%ebx
jl     1190 <linear_add+0x50>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0xa,%ebp
jmp    1190 <linear_add+0x50>

LLVM IR (-O0):
@.str = [27 x i8] c"cpu load usage linear add\0A\00"
@.str.1 = [15 x i8] c"n is begining\0A\00"
define i32 @linear_add() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i64 @get_times(i64 100000, i32 1)
store i64 %6, i64* %1
%7 = load i64, i64* %1
%8 = mul nsw i64 %7, 10000
%9 = call i64 @get_times(i64 %8, i32 1000)
store i64 %9, i64* %2
store i32 10, i32* %3
store i32 10, i32* %4
store i32 1000, i32* %5
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %0, %29
%12 = load i64, i64* %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = mul nsw i64 %12, %14
%16 = call i32 @dosum(i64 %15)
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = sub nsw i32 %17, %18
%20 = load i32, i32* %5
%21 = mul nsw i32 %19, %20
%22 = call i32 @usleep(i32 %21)
%23 = load i32, i32* %3
%24 = load i32, i32* %5
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %11
%27 = load i32, i32* %4
store i32 %27, i32* %3
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %11
%30 = load i32, i32* %4
%31 = load i32, i32* %3
%32 = add nsw i32 %31, %30
store i32 %32, i32* %3
br label %11
}

LLVM IR (-O2):
@str = [26 x i8] c"cpu load usage linear add\00"
@str.2 = [14 x i8] c"n is begining\00"
define i32 @linear_add() {
%1 = tail call i64 @get_times(i64 100000, i32 1)
%2 = mul nsw i64 %1, 10000
%3 = tail call i64 @get_times(i64 %2, i32 1000)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %16, %0
%6 = phi i32 [ 10, %0 ], [ %18, %16 ]
%7 = sext i32 %6 to i64
%8 = mul nsw i64 %3, %7
%9 = tail call i32 @dosum(i64 %8)
%10 = sub nsw i32 1000, %6
%11 = mul nsw i32 %10, 1000
%12 = tail call i32 @usleep(i32 %11)
%13 = icmp sgt i32 %6, 1000
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %5
%17 = phi i32 [ 10, %14 ], [ %6, %5 ]
%18 = add nsw i32 %17, 10
br label %5
}