#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 *malloc(int);
int /*<<< orphan*/ printf(char *, double);
double *b(double *v, int length) {
  int i;
  double sum = 0.0;
  printf("length: %i\n", length);
  for (i = 0; i < length; i++) {
    sum += v[i];
  }
  printf("sum: %f\n", sum);
  double *result = malloc(sizeof(double));
  result[0] = sum;
  return result;
}


x86 assembly (clang, -O0):
<b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1180 <b+0x60>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114f <b+0x2f>
movsd  -0x18(%rbp),%xmm0
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
cvtsi2sd %esi,%xmm0
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
test   %ebp,%ebp
jle    1155 <b+0x35>
mov    %ebp,%ecx
lea    -0x1(%rcx),%rdx
mov    %ecx,%eax
and    $0x7,%eax
cmp    $0x7,%rdx
jae    115b <b+0x3b>
xorpd  %xmm0,%xmm0
xor    %edx,%edx
jmp    11a8 <b+0x88>
xorpd  %xmm0,%xmm0
jmp    11ce <b+0xae>
and    $0xfffffff8,%ecx
xorpd  %xmm0,%xmm0
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addsd  (%rbx,%rdx,8),%xmm0
addsd  0x8(%rbx,%rdx,8),%xmm0
addsd  0x10(%rbx,%rdx,8),%xmm0
addsd  0x18(%rbx,%rdx,8),%xmm0
addsd  0x20(%rbx,%rdx,8),%xmm0
addsd  0x28(%rbx,%rdx,8),%xmm0
addsd  0x30(%rbx,%rdx,8),%xmm0
addsd  0x38(%rbx,%rdx,8),%xmm0
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    1170 <b+0x50>
test   %rax,%rax
je     11ce <b+0xae>
lea    (%rbx,%rdx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rcx,%rdx,8),%xmm0
add    $0x1,%rdx
cmp    %rdx,%rax
jne    11c0 <b+0xa0>
lea    0xe37(%rip),%rdi
movsd  %xmm0,(%rsp)
call   1030 <printf@plt>
mov    $0x8,%edi
call   1040 <malloc@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"length: %i\0A\00"
@.str.1 = [9 x i8] c"sum: %f\0A\00"
define noalias double* @b(double* nocapture %0, i32 %1) {
%3 = sitofp i32 %1 to double
%4 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %3)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %66
6: ; preds = %2
%7 = zext i32 %1 to i64
%8 = add nsw i64 %7, -1
%9 = and i64 %7, 7
%10 = icmp ult i64 %8, 7
br i1 %10, label %51, label %11
11: ; preds = %6
%12 = and i64 %7, 4294967288
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ 0, %11 ], [ %48, %13 ]
%15 = phi double [ 0.000000e+00, %11 ], [ %47, %13 ]
%16 = phi i64 [ 0, %11 ], [ %49, %13 ]
%17 = getelementptr inbounds double, double* %0, i64 %14
%18 = load double, double* %17
%19 = fadd double %15, %18
%20 = or i64 %14, 1
%21 = getelementptr inbounds double, double* %0, i64 %20
%22 = load double, double* %21
%23 = fadd double %19, %22
%24 = or i64 %14, 2
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = load double, double* %25
%27 = fadd double %23, %26
%28 = or i64 %14, 3
%29 = getelementptr inbounds double, double* %0, i64 %28
%30 = load double, double* %29
%31 = fadd double %27, %30
%32 = or i64 %14, 4
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = fadd double %31, %34
%36 = or i64 %14, 5
%37 = getelementptr inbounds double, double* %0, i64 %36
%38 = load double, double* %37
%39 = fadd double %35, %38
%40 = or i64 %14, 6
%41 = getelementptr inbounds double, double* %0, i64 %40
%42 = load double, double* %41
%43 = fadd double %39, %42
%44 = or i64 %14, 7
%45 = getelementptr inbounds double, double* %0, i64 %44
%46 = load double, double* %45
%47 = fadd double %43, %46
%48 = add nuw nsw i64 %14, 8
%49 = add i64 %16, 8
%50 = icmp eq i64 %49, %12
br i1 %50, label %51, label %13
51: ; preds = %13, %6
%52 = phi double [ undef, %6 ], [ %47, %13 ]
%53 = phi i64 [ 0, %6 ], [ %48, %13 ]
%54 = phi double [ 0.000000e+00, %6 ], [ %47, %13 ]
%55 = icmp eq i64 %9, 0
br i1 %55, label %66, label %56
56: ; preds = %51, %56
%57 = phi i64 [ %63, %56 ], [ %53, %51 ]
%58 = phi double [ %62, %56 ], [ %54, %51 ]
%59 = phi i64 [ %64, %56 ], [ 0, %51 ]
%60 = getelementptr inbounds double, double* %0, i64 %57
%61 = load double, double* %60
%62 = fadd double %58, %61
%63 = add nuw nsw i64 %57, 1
%64 = add i64 %59, 1
%65 = icmp eq i64 %64, %9
br i1 %65, label %66, label %56
66: ; preds = %51, %56, %2
%67 = phi double [ 0.000000e+00, %2 ], [ %52, %51 ], [ %62, %56 ]
%68 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %67)
%69 = tail call double* @malloc(i32 8)
store double %67, double* %69
ret double* %69
}