#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 *, long, double);
void waste_some_cpu_cycles() {
  double num1 = 1.0;
  double den1 = 1.0;
  double rat1;
  double tot1 = 0.0;
  long i1;
  for (i1 = 0; i1 < 990000000; i1++) {
    rat1 = num1 / den1;
    tot1 += rat1;
    den1 += 1.0;
  }
  printf("total at %ld is %lg\n", i1, tot1);
}


x86 assembly (clang, -O0):
<waste_some_cpu_cycles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  0xee0(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xed3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x3b023380,-0x28(%rbp)
3b
jge    1191 <waste_some_cpu_cycles+0x81>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe8a(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1142 <waste_some_cpu_cycles+0x32>
mov    -0x28(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waste_some_cpu_cycles>:
movsd  0xee8(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    $0x3b023380,%eax
movapd %xmm1,%xmm2
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm1,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
addsd  %xmm1,%xmm2
movapd %xmm1,%xmm4
divsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
addsd  %xmm1,%xmm2
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm4,%xmm0
addsd  %xmm1,%xmm2
add    $0xfffffffffffffffd,%rax
jne    1130 <waste_some_cpu_cycles+0x20>
lea    0xe9b(%rip),%rdi
mov    $0x3b023380,%esi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"total at %ld is %lg\0A\00"
define void @waste_some_cpu_cycles() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i64
store double 1.000000e+00, double* %1
store double 1.000000e+00, double* %2
store double 0.000000e+00, double* %4
store i64 0, i64* %5
br label %6
6: ; preds = %18, %0
%7 = load i64, i64* %5
%8 = icmp slt i64 %7, 990000000
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load double, double* %1
%11 = load double, double* %2
%12 = fdiv double %10, %11
store double %12, double* %3
%13 = load double, double* %3
%14 = load double, double* %4
%15 = fadd double %14, %13
store double %15, double* %4
%16 = load double, double* %2
%17 = fadd double %16, 1.000000e+00
store double %17, double* %2
br label %18
18: ; preds = %9
%19 = load i64, i64* %5
%20 = add nsw i64 %19, 1
store i64 %20, i64* %5
br label %6
21: ; preds = %6
%22 = load i64, i64* %5
%23 = load double, double* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %22, double %23)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"total at %ld is %lg\0A\00"
define void @waste_some_cpu_cycles() {
br label %1
1: ; preds = %1, %0
%2 = phi i64 [ 0, %0 ], [ %14, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %12, %1 ]
%4 = phi double [ 1.000000e+00, %0 ], [ %13, %1 ]
%5 = fdiv double 1.000000e+00, %4
%6 = fadd double %3, %5
%7 = fadd double %4, 1.000000e+00
%8 = fdiv double 1.000000e+00, %7
%9 = fadd double %6, %8
%10 = fadd double %7, 1.000000e+00
%11 = fdiv double 1.000000e+00, %10
%12 = fadd double %9, %11
%13 = fadd double %10, 1.000000e+00
%14 = add nuw nsw i64 %2, 3
%15 = icmp eq i64 %14, 990000000
br i1 %15, label %16, label %1
16: ; preds = %1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 990000000, double %12)
ret void
}