#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 */
float foo(float);
int rand();
int main(void) {
  int i;
  float a = 0;
  for (i = 0; i < 1000; i++) {
    a += foo((float)(rand() % 65536)) / ((float)(rand() % 65536));
  }
  return a;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    119c <main+0x7c>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x10000,%ecx
cltd
idiv   %ecx
cvtsi2ss %edx,%xmm0
call   1030 <foo@plt>
movss  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movss  -0x10(%rbp),%xmm0
mov    $0x10000,%ecx
cltd
idiv   %ecx
cvtsi2ss %edx,%xmm1
divss  %xmm1,%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113e <main+0x1e>
cvttss2si -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
mov    $0x3e8,%ebx
nopl   (%rax)
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
lea    0xffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffff0000,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1030 <foo@plt>
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
lea    0xffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffff0000,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
addss  %xmm1,%xmm0
add    $0xffffffff,%ebx
jne    1130 <main+0x10>
cvttss2si %xmm0,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %3
store i32 0, i32* %2
br label %4
4: ; preds = %18, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 1000
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 65536
%10 = sitofp i32 %9 to float
%11 = call float @foo(float %10)
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 65536
%14 = sitofp i32 %13 to float
%15 = fdiv float %11, %14
%16 = load float, float* %3
%17 = fadd float %16, %15
store float %17, float* %3
br label %18
18: ; preds = %7
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %4
21: ; preds = %4
%22 = load float, float* %3
%23 = fptosi float %22 to i32
ret i32 %23
}

LLVM IR (-O2):
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi float [ 0.000000e+00, %0 ], [ %12, %1 ]
%3 = phi i32 [ 0, %0 ], [ %13, %1 ]
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 65536
%6 = sitofp i32 %5 to float
%7 = tail call float @foo(float %6)
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 65536
%10 = sitofp i32 %9 to float
%11 = fdiv float %7, %10
%12 = fadd float %2, %11
%13 = add nuw nsw i32 %3, 1
%14 = icmp eq i32 %13, 1000
br i1 %14, label %15, label %1
15: ; preds = %1
%16 = fptosi float %12 to i32
ret i32 %16
}