#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*/ forceCpuLoadSlice(int, int const);
int /*<<< orphan*/ printf(char *, int, int);
int forceCpuLoad(int cpuLoad, int duration) {
  const int sliceDuration = 1000000;
  int loopCount;
  int i;
  printf("Force CPU load : %d%% during %d seconds\n", cpuLoad, duration);
  loopCount = (duration * 1000000) / sliceDuration;
  for (i = 0; i < loopCount; i++)
    forceCpuLoadSlice(cpuLoad, sliceDuration);
  return 0;
}


x86 assembly (clang, -O0):
<forceCpuLoad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0xf4240,-0xc(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
imul   $0xf4240,-0x8(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1187 <forceCpuLoad+0x67>
mov    -0x4(%rbp),%edi
mov    $0xf4240,%esi
call   1040 <forceCpuLoadSlice@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <forceCpuLoad+0x40>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forceCpuLoad>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xed2(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
test   %ebx,%ebx
jle    1151 <forceCpuLoad+0x31>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    $0xf4240,%esi
call   1040 <forceCpuLoadSlice@plt>
add    $0xffffffff,%ebx
jne    1140 <forceCpuLoad+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Force CPU load : %d%% during %d seconds\0A\00"
define i32 @forceCpuLoad(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1000000, i32* %5
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %4
%12 = mul nsw i32 %11, 1000000
%13 = sdiv i32 %12, 1000000
store i32 %13, i32* %6
store i32 0, i32* %7
br label %14
14: ; preds = %21, %2
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %3
%20 = call i32 @forceCpuLoadSlice(i32 %19, i32 1000000)
br label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %14
24: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"Force CPU load : %d%% during %d seconds\0A\00"
define i32 @forceCpuLoad(i32 %0, i32 %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %10
5: ; preds = %2, %5
%6 = phi i32 [ %8, %5 ], [ 0, %2 ]
%7 = tail call i32 @forceCpuLoadSlice(i32 %0, i32 1000000)
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i32 %8, %1
br i1 %9, label %10, label %5
10: ; preds = %5, %2
ret i32 0
}