#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 */
double RAND_MAX;
int /*<<< orphan*/ printf(char *, int, double);
scalar_t__ pthread_self();
double rand();
void *threadWork(void *dummy) {
  int i;
  double result = 0;
  for (i = 0; i < 100000; i++) {
    result += 10.0 * rand() / RAND_MAX;
  }
  printf("Thread %d: result = %f\n", (int)pthread_self(), result);
  return (NULL);
}


x86 assembly (clang, -O0):
<threadWork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x186a0,-0xc(%rbp)
jge    1191 <threadWork+0x61>
mov    $0x0,%al
call   1050 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe96(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e73(%rip),%rax
divsd  (%rax),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <threadWork+0x1b>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
movsd  -0x18(%rbp),%xmm0
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threadWork>:
push   %r14
push   %rbx
push   %rax
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x186a0,%ebx
mov    0x2e9f(%rip),%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
mulsd  0xea1(%rip),%xmm0
divsd  (%r14),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
add    $0xffffffff,%ebx
jne    1150 <threadWork+0x20>
xor    %eax,%eax
call   1040 <pthread_self@plt>
lea    0xe83(%rip),%rdi
mov    %eax,%esi
movsd  (%rsp),%xmm0
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
@.str = [24 x i8] c"Thread %d: result = %f\0A\00"
define i8* @threadWork(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca double
store i8* %0, i8** %2
store double 0.000000e+00, double* %4
store i32 0, i32* %3
br label %5
5: ; preds = %15, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100000
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = call double (...) @rand()
%10 = fmul double 1.000000e+01, %9
%11 = load double, double* @RAND_MAX
%12 = fdiv double %10, %11
%13 = load double, double* %4
%14 = fadd double %13, %12
store double %14, double* %4
br label %15
15: ; preds = %8
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %5
18: ; preds = %5
%19 = call i64 (...) @pthread_self()
%20 = trunc i64 %19 to i32
%21 = load double, double* %4
%22 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %20, double %21)
ret i8* null
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@.str = [24 x i8] c"Thread %d: result = %f\0A\00"
define noalias i8* @threadWork(i8* nocapture readnone %0) {
br label %2
2: ; preds = %1, %2
%3 = phi double [ 0.000000e+00, %1 ], [ %9, %2 ]
%4 = phi i32 [ 0, %1 ], [ %10, %2 ]
%5 = tail call double (...) @rand()
%6 = fmul double %5, 1.000000e+01
%7 = load double, double* @RAND_MAX
%8 = fdiv double %6, %7
%9 = fadd double %3, %8
%10 = add nuw nsw i32 %4, 1
%11 = icmp eq i32 %10, 100000
br i1 %11, label %12, label %2
12: ; preds = %2
%13 = tail call i64 (...) @pthread_self()
%14 = trunc i64 %13 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %14, double %9)
ret i8* null
}