#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 *, ...);
void print_array(float *r, int length) {
  int i;
  float sum = 0;
  for (i = 0; i < length; i++) {
    printf("%.2f  ", r[i]);
    sum += r[i];
  }
  printf("\n");
  printf("sum: %.2f\n", sum);
}


x86 assembly (clang, -O0):
<print_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117e <print_array+0x6e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xeae(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <print_array+0x1e>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1173 <print_array+0x53>
mov    %rdi,%r12
mov    %esi,%r15d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
lea    0xec2(%rip),%r14
xchg   %ax,%ax
movss  %xmm0,(%rsp)
movss  (%r12,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  (%rsp),%xmm0
addss  (%r12,%rbx,4),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <print_array+0x20>
cvtss2sd %xmm0,%xmm0
jmp    1176 <print_array+0x56>
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe7b(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%.2f \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [11 x i8] c"sum: %.2f\0A\00"
define void @print_array(float* %0, i32 %1) {
%3 = alloca float*
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
store float* %0, float** %3
store i32 %1, i32* %4
store float 0.000000e+00, float* %6
store i32 0, i32* %5
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = load float*, float** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds float, float* %12, i64 %14
%16 = load float, float* %15
%17 = fpext float %16 to double
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %17)
%19 = load float*, float** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds float, float* %19, i64 %21
%23 = load float, float* %22
%24 = load float, float* %6
%25 = fadd float %24, %23
store float %25, float* %6
br label %26
26: ; preds = %11
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %7
29: ; preds = %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = load float, float* %6
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %32)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%.2f \00"
@.str.2 = [11 x i8] c"sum: %.2f\0A\00"
define void @print_array(float* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %15, %6 ]
%8 = phi float [ 0.000000e+00, %4 ], [ %14, %6 ]
%9 = getelementptr inbounds float, float* %0, i64 %7
%10 = load float, float* %9
%11 = fpext float %10 to double
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %11)
%13 = load float, float* %9
%14 = fadd float %8, %13
%15 = add nuw nsw i64 %7, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %17, label %6
17: ; preds = %6
%18 = fpext float %14 to double
br label %19
19: ; preds = %17, %2
%20 = phi double [ 0.000000e+00, %2 ], [ %18, %17 ]
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %20)
ret void
}