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


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x10000,%ecx
cltd
idiv   %ecx
cvtsi2ss %edx,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
movss  -0x10(%rbp),%xmm0
mov    $0x10000,%ecx
cltd
idiv   %ecx
cvtsi2ss %edx,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    118d <foo+0x7d>
movss  -0x8(%rbp),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <foo+0x4d>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rax
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <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  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1030 <rand@plt>
movss  0x4(%rsp),%xmm2
lea    0xffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffff0000,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  %xmm0,%xmm2
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm2
jbe    1195 <foo+0x85>
mov    $0x1,%eax
movss  (%rsp),%xmm0
nopw   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
addss  %xmm2,%xmm0
add    $0x1,%eax
ucomiss %xmm1,%xmm2
ja     1180 <foo+0x70>
pop    %rax
ret
movss  (%rsp),%xmm0
pop    %rax
ret

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

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