#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__ Pfun(int, int);
float accum_ref() {
  int i, k;
  float tmp = 0.0;
  for (i = 0; i < 10000; i++) {
    float tmp1 = 0.0;
    for (k = 0; k < 1024; k++)
      tmp1 += Pfun(i, k);
    tmp += tmp1;
  }
  return tmp;
}


x86 assembly (clang, -O0):
<accum_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x2710,-0x4(%rbp)
jge    1195 <accum_ref+0x85>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    1178 <accum_ref+0x68>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <Pfun@plt>
cvtsi2ss %rax,%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1143 <accum_ref+0x33>
movss  -0x10(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1127 <accum_ref+0x17>
movss  -0xc(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accum_ref>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xorps  %xmm0,%xmm0
nopl   0x0(%rax,%rax,1)
movss  %xmm0,(%rsp)
xorps  %xmm1,%xmm1
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movss  %xmm1,0x4(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <Pfun@plt>
movss  0x4(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm1
add    $0x1,%ebp
cmp    $0x400,%ebp
jne    1130 <accum_ref+0x20>
movss  (%rsp),%xmm0
addss  %xmm1,%xmm0
add    $0x1,%ebx
cmp    $0x2710,%ebx
jne    1120 <accum_ref+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @accum_ref() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
store float 0.000000e+00, float* %3
store i32 0, i32* %1
br label %5
5: ; preds = %26, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 10000
br i1 %7, label %8, label %29
8: ; preds = %5
store float 0.000000e+00, float* %4
store i32 0, i32* %2
br label %9
9: ; preds = %19, %8
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 1024
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = call i64 @Pfun(i32 %13, i32 %14)
%16 = sitofp i64 %15 to float
%17 = load float, float* %4
%18 = fadd float %17, %16
store float %18, float* %4
br label %19
19: ; preds = %12
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %9
22: ; preds = %9
%23 = load float, float* %4
%24 = load float, float* %3
%25 = fadd float %24, %23
store float %25, float* %3
br label %26
26: ; preds = %22
%27 = load i32, i32* %1
%28 = add nsw i32 %27, 1
store i32 %28, i32* %1
br label %5
29: ; preds = %5
%30 = load float, float* %3
ret float %30
}

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