#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 *, double);
int /*<<< orphan*/ pthread_exit(void *);
scalar_t__ random();
void *BusyWork(void *null) {
  int i;
  double result = 0.0;
  for (i = 0; i < 1000000; i++) {
    result = result + (double)random();
  }
  printf("result = %e\n", result);
  pthread_exit((void *)0);
}


x86 assembly (clang, -O0):
<BusyWork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    118a <BusyWork+0x5a>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <BusyWork+0x1b>
movsd  -0x20(%rbp),%xmm0
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BusyWork>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
mov    $0xf4240,%ebx
nopl   (%rax)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1140 <BusyWork+0x10>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <pthread_exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"result = %e\0A\00"
define i8* @BusyWork(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
store i8* %0, i8** %3
store double 0.000000e+00, double* %5
store i32 0, i32* %4
br label %6
6: ; preds = %14, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load double, double* %5
%11 = call i64 (...) @random()
%12 = sitofp i64 %11 to double
%13 = fadd double %10, %12
store double %13, double* %5
br label %14
14: ; preds = %9
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %6
17: ; preds = %6
%18 = load double, double* %5
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %18)
%20 = call i32 @pthread_exit(i8* null)
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@.str = [13 x i8] c"result = %e\0A\00"
define noalias i8* @BusyWork(i8* nocapture readnone %0) {
br label %2
2: ; preds = %1, %2
%3 = phi double [ 0.000000e+00, %1 ], [ %7, %2 ]
%4 = phi i32 [ 0, %1 ], [ %8, %2 ]
%5 = tail call i64 (...) @random()
%6 = sitofp i64 %5 to double
%7 = fadd double %3, %6
%8 = add nuw nsw i32 %4, 1
%9 = icmp eq i32 %8, 1000000
br i1 %9, label %10, label %2
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %7)
%12 = tail call i32 @pthread_exit(i8* null)
ret i8* undef
}