#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ printf(char *);
double sumfifo(double *fifo, unsigned int lenlista) {
  unsigned int i, j;
  double result;
  if (lenlista % 2 != 0) {
    printf("Error, the fifo size should be 2^n");
    exit(EXIT_FAILURE);
  }
  double *tempfifo = malloc(sizeof(double) * lenlista);
  for (i = 0; i < lenlista; i++) {
    tempfifo[i] = fifo[i];
  }
  for (j = lenlista / 2; j >= 1; j = j / 2) {
    for (i = 0; i < j; i++) {
      tempfifo[i] = tempfifo[2 * i] + tempfifo[2 * i + 1];
    }
  }
  result = tempfifo[0];
  free(tempfifo);
  return result;
}


x86 assembly (clang, -O0):
<sumfifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1178 <sumfifo+0x38>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11c3 <sumfifo+0x83>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1191 <sumfifo+0x51>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jb     123b <sumfifo+0xfb>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1228 <sumfifo+0xe8>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11dd <sumfifo+0x9d>
jmp    122d <sumfifo+0xed>
mov    -0x14(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <sumfifo+0x8c>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sumfifo>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
test   $0x1,%r14b
jne    125c <sumfifo+0x10c>
mov    %rdi,%r15
lea    0x0(,%r14,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
je     1196 <sumfifo+0x46>
mov    %r14d,%edx
shl    $0x3,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <memcpy@plt>
cmp    $0x1,%r14d
jne    11b8 <sumfifo+0x68>
movsd  (%rbx),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%r8
add    $0x18,%r8
jmp    11d5 <sumfifo+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x4,%ecx
jb     1196 <sumfifo+0x46>
cmp    $0x2,%r14d
jb     1196 <sumfifo+0x46>
mov    %r14d,%ecx
shr    %r14d
cmp    $0x2,%r14d
mov    $0x1,%edx
cmovae %r14d,%edx
cmp    $0x4,%ecx
jae    1200 <sumfifo+0xb0>
xor    %esi,%esi
jmp    123b <sumfifo+0xeb>
nopw   0x0(%rax,%rax,1)
mov    %edx,%edi
and    $0xfffffffe,%edi
mov    %r8,%rax
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
movsd  -0x18(%rax),%xmm0
addsd  -0x10(%rax),%xmm0
movsd  %xmm0,(%rbx,%rsi,8)
movsd  -0x8(%rax),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rbx,%rsi,8)
add    $0x2,%rsi
add    $0x20,%rax
cmp    %rsi,%rdi
jne    1210 <sumfifo+0xc0>
test   $0x1,%dl
je     11d0 <sumfifo+0x80>
mov    %rsi,%rax
shl    $0x4,%rax
movsd  (%rbx,%rax,1),%xmm0
addsd  0x8(%rbx,%rax,1),%xmm0
movsd  %xmm0,(%rbx,%rsi,8)
jmp    11d0 <sumfifo+0x80>
lea    0xd9d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"Error, the fifo size should be 2^n\00"
@EXIT_FAILURE = global i32 0
define double @sumfifo(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double*
store double* %0, double** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = urem i32 %9, 2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = mul i64 8, %18
%20 = trunc i64 %19 to i32
%21 = call double* @malloc(i32 %20)
store double* %21, double** %8
store i32 0, i32* %5
br label %22
22: ; preds = %36, %16
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load double*, double** %3
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double*, double** %8
%33 = load i32, i32* %5
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double %31, double* %35
br label %36
36: ; preds = %26
%37 = load i32, i32* %5
%38 = add i32 %37, 1
store i32 %38, i32* %5
br label %22
39: ; preds = %22
%40 = load i32, i32* %4
%41 = udiv i32 %40, 2
store i32 %41, i32* %6
br label %42
42: ; preds = %73, %39
%43 = load i32, i32* %6
%44 = icmp uge i32 %43, 1
br i1 %44, label %45, label %76
45: ; preds = %42
store i32 0, i32* %5
br label %46
46: ; preds = %69, %45
%47 = load i32, i32* %5
%48 = load i32, i32* %6
%49 = icmp ult i32 %47, %48
br i1 %49, label %50, label %72
50: ; preds = %46
%51 = load double*, double** %8
%52 = load i32, i32* %5
%53 = mul i32 2, %52
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = load double*, double** %8
%58 = load i32, i32* %5
%59 = mul i32 2, %58
%60 = add i32 %59, 1
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds double, double* %57, i64 %61
%63 = load double, double* %62
%64 = fadd double %56, %63
%65 = load double*, double** %8
%66 = load i32, i32* %5
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
store double %64, double* %68
br label %69
69: ; preds = %50
%70 = load i32, i32* %5
%71 = add i32 %70, 1
store i32 %71, i32* %5
br label %46
72: ; preds = %46
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = udiv i32 %74, 2
store i32 %75, i32* %6
br label %42
76: ; preds = %42
%77 = load double*, double** %8
%78 = getelementptr inbounds double, double* %77, i64 0
%79 = load double, double* %78
store double %79, double* %7
%80 = load double*, double** %8
%81 = call i32 @free(double* %80)
%82 = load double, double* %7
ret double %82
}

LLVM IR (-O2):
@.str = [35 x i8] c"Error, the fifo size should be 2^n\00"
@EXIT_FAILURE = global i32 0
define double @sumfifo(double* nocapture %0, i32 %1) {
%3 = bitcast double* %0 to i8*
%4 = and i32 %1, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = shl i32 %1, 3
%12 = tail call double* @malloc(i32 %11)
%13 = icmp eq i32 %1, 0
br i1 %13, label %67, label %14
14: ; preds = %10
%15 = bitcast double* %12 to i8*
%16 = zext i32 %1 to i64
%17 = shl nuw nsw i64 %16, 3
%18 = icmp eq i32 %1, 1
br i1 %18, label %67, label %33
19: ; preds = %44, %37
%20 = phi i64 [ 0, %37 ], [ %64, %44 ]
%21 = icmp eq i64 %40, 0
br i1 %21, label %31, label %22
22: ; preds = %19
%23 = shl nuw i64 %20, 1
%24 = getelementptr inbounds double, double* %12, i64 %23
%25 = load double, double* %24
%26 = or i64 %23, 1
%27 = getelementptr inbounds double, double* %12, i64 %26
%28 = load double, double* %27
%29 = fadd double %25, %28
%30 = getelementptr inbounds double, double* %12, i64 %20
store double %29, double* %30
br label %31
31: ; preds = %19, %22
%32 = icmp ult i32 %34, 4
br i1 %32, label %67, label %33
33: ; preds = %14, %31
%34 = phi i32 [ %35, %31 ], [ %1, %14 ]
%35 = lshr i32 %34, 1
%36 = icmp ult i32 %34, 2
br i1 %36, label %67, label %37
37: ; preds = %33
%38 = call i32 @llvm.umax.i32(i32 %35, i32 1)
%39 = zext i32 %38 to i64
%40 = and i64 %39, 1
%41 = icmp ult i32 %34, 4
br i1 %41, label %19, label %42
42: ; preds = %37
%43 = and i64 %39, 2147483646
br label %44
44: ; preds = %44, %42
%45 = phi i64 [ 0, %42 ], [ %64, %44 ]
%46 = phi i64 [ 0, %42 ], [ %65, %44 ]
%47 = shl nuw i64 %45, 1
%48 = getelementptr inbounds double, double* %12, i64 %47
%49 = load double, double* %48
%50 = or i64 %47, 1
%51 = getelementptr inbounds double, double* %12, i64 %50
%52 = load double, double* %51
%53 = fadd double %49, %52
%54 = getelementptr inbounds double, double* %12, i64 %45
store double %53, double* %54
%55 = or i64 %45, 1
%56 = shl nuw i64 %55, 1
%57 = getelementptr inbounds double, double* %12, i64 %56
%58 = load double, double* %57
%59 = or i64 %56, 1
%60 = getelementptr inbounds double, double* %12, i64 %59
%61 = load double, double* %60
%62 = fadd double %58, %61
%63 = getelementptr inbounds double, double* %12, i64 %55
store double %62, double* %63
%64 = add nuw nsw i64 %45, 2
%65 = add nuw i64 %46, 2
%66 = icmp eq i64 %65, %43
br i1 %66, label %19, label %44
67: ; preds = %31, %33, %10, %14
%68 = load double, double* %12
%69 = tail call i32 @free(double* %12)
ret double %68
}