#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 */
scalar_t__ sqrt(double);
void do_some_work() {
  int i;
  double sum = 0;
  for (i = 0; i < 1000; i++) {
    sum += sqrt((double)i);
  }
}


x86 assembly (clang, -O0):
<do_some_work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    115b <do_some_work+0x4b>
cvtsi2sdl -0x4(%rbp),%xmm0
call   1030 <sqrt@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1127 <do_some_work+0x17>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_some_work>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm0,%xmm0
mov    $0x7,%ebx
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sqrt@plt>
lea    -0x6(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1030 <sqrt@plt>
lea    -0x5(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1030 <sqrt@plt>
lea    -0x4(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1030 <sqrt@plt>
lea    -0x3(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1030 <sqrt@plt>
lea    -0x2(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1030 <sqrt@plt>
lea    -0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1030 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xe5b(%rip),%xmm0
add    $0x8,%ebx
cmp    $0x3ef,%ebx
jne    1120 <do_some_work+0x10>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @do_some_work() {
%1 = alloca i32
%2 = alloca double
store double 0.000000e+00, double* %2
store i32 0, i32* %1
br label %3
3: ; preds = %13, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 1000
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = load i32, i32* %1
%8 = sitofp i32 %7 to double
%9 = call i64 @sqrt(double %8)
%10 = sitofp i64 %9 to double
%11 = load double, double* %2
%12 = fadd double %11, %10
store double %12, double* %2
br label %13
13: ; preds = %6
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %3
16: ; preds = %3
ret void
}

LLVM IR (-O2):
define void @do_some_work() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %26, %1 ]
%3 = sitofp i32 %2 to double
%4 = tail call i64 @sqrt(double %3)
%5 = or i32 %2, 1
%6 = sitofp i32 %5 to double
%7 = tail call i64 @sqrt(double %6)
%8 = or i32 %2, 2
%9 = sitofp i32 %8 to double
%10 = tail call i64 @sqrt(double %9)
%11 = or i32 %2, 3
%12 = sitofp i32 %11 to double
%13 = tail call i64 @sqrt(double %12)
%14 = or i32 %2, 4
%15 = sitofp i32 %14 to double
%16 = tail call i64 @sqrt(double %15)
%17 = or i32 %2, 5
%18 = sitofp i32 %17 to double
%19 = tail call i64 @sqrt(double %18)
%20 = or i32 %2, 6
%21 = sitofp i32 %20 to double
%22 = tail call i64 @sqrt(double %21)
%23 = or i32 %2, 7
%24 = sitofp i32 %23 to double
%25 = tail call i64 @sqrt(double %24)
%26 = add nuw nsw i32 %2, 8
%27 = icmp eq i32 %26, 1000
br i1 %27, label %28, label %1
28: ; preds = %1
ret void
}