#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 fabs(double);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
void clean_zeros(double **values, int *M) {
  double *new, *tmp;
  int i;
  i = *M - 1;
  while (fabs((*values)[i]) < 1e-10)
    i--;
  i++;
  if (i < *M) {
    *M = i;
    new = (double *)malloc(*M * sizeof(double));
    for (i = 0; i < *M; i++)
      new[i] = (*values)[i];
    tmp = *values;
    *values = new;
    free(tmp);
  }
}


x86 assembly (clang, -O0):
<clean_zeros>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe93(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1185 <clean_zeros+0x55>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <clean_zeros+0x1c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    121c <clean_zeros+0xec>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11fd <clean_zeros+0xcd>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c3 <clean_zeros+0x93>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_zeros>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movslq (%rsi),%rbp
lea    0x8(,%rbp,8),%r12d
lea    0x1(%rbp),%ebx
add    $0xffffffffffffffff,%rbp
mov    (%r15),%rax
movsd  (%rax,%rbp,8),%xmm0
call   1040 <fabs@plt>
add    $0xfffffff8,%r12d
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rbp
test   %eax,%eax
jle    1150 <clean_zeros+0x20>
cmp    %ebx,(%r14)
jle    122c <clean_zeros+0xfc>
mov    %ebx,(%r14)
mov    %r12d,%edi
call   1050 <malloc@plt>
mov    (%r14),%ebx
mov    (%r15),%rdi
test   %ebx,%ebx
jle    1304 <clean_zeros+0x1d4>
cmp    $0x4,%ebx
jb     11ad <clean_zeros+0x7d>
lea    (%rdi,%rbx,8),%rcx
cmp    %rcx,%rax
jae    1235 <clean_zeros+0x105>
lea    (%rax,%rbx,8),%rcx
cmp    %rcx,%rdi
jae    1235 <clean_zeros+0x105>
xor    %edx,%edx
mov    %rdx,%rsi
not    %rsi
add    %rbx,%rsi
mov    %rbx,%rcx
and    $0x3,%rcx
je     11e4 <clean_zeros+0xb4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rdx,8),%xmm0
movsd  %xmm0,(%rax,%rdx,8)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
jne    11d0 <clean_zeros+0xa0>
cmp    $0x3,%rsi
jb     1304 <clean_zeros+0x1d4>
xchg   %ax,%ax
movsd  (%rdi,%rdx,8),%xmm0
movsd  %xmm0,(%rax,%rdx,8)
movsd  0x8(%rdi,%rdx,8),%xmm0
movsd  %xmm0,0x8(%rax,%rdx,8)
movsd  0x10(%rdi,%rdx,8),%xmm0
movsd  %xmm0,0x10(%rax,%rdx,8)
movsd  0x18(%rdi,%rdx,8),%xmm0
movsd  %xmm0,0x18(%rax,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%rbx
jne    11f0 <clean_zeros+0xc0>
jmp    1304 <clean_zeros+0x1d4>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edx
and    $0xfffffffc,%edx
lea    -0x4(%rdx),%rcx
mov    %rcx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%r8d
and    $0x3,%r8d
cmp    $0xc,%rcx
jae    125a <clean_zeros+0x12a>
xor    %ebp,%ebp
jmp    12b8 <clean_zeros+0x188>
and    $0xfffffffffffffffc,%rsi
xor    %ebp,%ebp
movups (%rdi,%rbp,8),%xmm0
movups 0x10(%rdi,%rbp,8),%xmm1
movups %xmm0,(%rax,%rbp,8)
movups %xmm1,0x10(%rax,%rbp,8)
movups 0x20(%rdi,%rbp,8),%xmm0
movups 0x30(%rdi,%rbp,8),%xmm1
movups %xmm0,0x20(%rax,%rbp,8)
movups %xmm1,0x30(%rax,%rbp,8)
movups 0x40(%rdi,%rbp,8),%xmm0
movups 0x50(%rdi,%rbp,8),%xmm1
movups %xmm0,0x40(%rax,%rbp,8)
movups %xmm1,0x50(%rax,%rbp,8)
movups 0x60(%rdi,%rbp,8),%xmm0
movups 0x70(%rdi,%rbp,8),%xmm1
movups %xmm0,0x60(%rax,%rbp,8)
movups %xmm1,0x70(%rax,%rbp,8)
add    $0x10,%rbp
add    $0xfffffffffffffffc,%rsi
jne    1260 <clean_zeros+0x130>
test   %r8,%r8
je     12fb <clean_zeros+0x1cb>
lea    (%rax,%rbp,8),%rcx
add    $0x10,%rcx
lea    (%rdi,%rbp,8),%rsi
add    $0x10,%rsi
shl    $0x5,%r8
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups -0x10(%rsi,%rbp,1),%xmm0
movups (%rsi,%rbp,1),%xmm1
movups %xmm0,-0x10(%rcx,%rbp,1)
movups %xmm1,(%rcx,%rbp,1)
add    $0x20,%rbp
cmp    %rbp,%r8
jne    12e0 <clean_zeros+0x1b0>
cmp    %rbx,%rdx
jne    11af <clean_zeros+0x7f>
mov    %rax,(%r15)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @clean_zeros(double** %0, i32* %1) {
%3 = alloca double**
%4 = alloca i32*
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
store double** %0, double*** %3
store i32* %1, i32** %4
%8 = load i32*, i32** %4
%9 = load i32, i32* %8
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %7
br label %11
11: ; preds = %21, %2
%12 = load double**, double*** %3
%13 = load double*, double** %12
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = call i32 @fabs(double %17)
%19 = sitofp i32 %18 to double
%20 = fcmp olt double %19, 1.000000e-10
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* %7
%23 = add nsw i32 %22, -1
store i32 %23, i32* %7
br label %11
24: ; preds = %11
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = load i32*, i32** %4
%29 = load i32, i32* %28
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %67
31: ; preds = %24
%32 = load i32, i32* %7
%33 = load i32*, i32** %4
store i32 %32, i32* %33
%34 = load i32*, i32** %4
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 8
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to double*
store double* %40, double** %5
store i32 0, i32* %7
br label %41
41: ; preds = %57, %31
%42 = load i32, i32* %7
%43 = load i32*, i32** %4
%44 = load i32, i32* %43
%45 = icmp slt i32 %42, %44
br i1 %45, label %46, label %60
46: ; preds = %41
%47 = load double**, double*** %3
%48 = load double*, double** %47
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = load double*, double** %5
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
store double %52, double* %56
br label %57
57: ; preds = %46
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %41
60: ; preds = %41
%61 = load double**, double*** %3
%62 = load double*, double** %61
store double* %62, double** %6
%63 = load double*, double** %5
%64 = load double**, double*** %3
store double* %63, double** %64
%65 = load double*, double** %6
%66 = call i32 @free(double* %65)
br label %67
67: ; preds = %60, %24
ret void
}

LLVM IR (-O2):
define void @clean_zeros(double** nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = sext i32 %3 to i64
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ %7, %5 ], [ %4, %2 ]
%7 = add nsw i64 %6, -1
%8 = load double*, double** %0
%9 = getelementptr inbounds double, double* %8, i64 %7
%10 = load double, double* %9
%11 = tail call i32 @fabs(double %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %5, label %13
13: ; preds = %5
%14 = trunc i64 %6 to i32
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, %14
br i1 %16, label %17, label %153
17: ; preds = %13
store i32 %14, i32* %1
%18 = shl i32 %14, 3
%19 = tail call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double*
%21 = inttoptr i64 %19 to i8*
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 0
%24 = load double*, double** %0
br i1 %23, label %25, label %151
25: ; preds = %17
%26 = zext i32 %22 to i64
%27 = icmp ult i32 %22, 4
br i1 %27, label %114, label %28
28: ; preds = %25
%29 = getelementptr double, double* %20, i64 %26
%30 = getelementptr double, double* %24, i64 %26
%31 = bitcast double* %30 to i8*
%32 = icmp ult i8* %21, %31
%33 = icmp ult double* %24, %29
%34 = and i1 %32, %33
br i1 %34, label %114, label %35
35: ; preds = %28
%36 = and i64 %26, 4294967292
%37 = add nsw i64 %36, -4
%38 = lshr exact i64 %37, 2
%39 = add nuw nsw i64 %38, 1
%40 = and i64 %39, 3
%41 = icmp ult i64 %37, 12
br i1 %41, label %93, label %42
42: ; preds = %35
%43 = and i64 %39, 9223372036854775804
br label %44
44: ; preds = %44, %42
%45 = phi i64 [ 0, %42 ], [ %90, %44 ]
%46 = phi i64 [ 0, %42 ], [ %91, %44 ]
%47 = getelementptr inbounds double, double* %24, i64 %45
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = getelementptr inbounds double, double* %47, i64 2
%51 = bitcast double* %50 to <2 x double>*
%52 = load <2 x double>, <2 x double>* %51
%53 = getelementptr inbounds double, double* %20, i64 %45
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %49, <2 x double>* %54
%55 = getelementptr inbounds double, double* %53, i64 2
%56 = bitcast double* %55 to <2 x double>*
store <2 x double> %52, <2 x double>* %56
%57 = or i64 %45, 4
%58 = getelementptr inbounds double, double* %24, i64 %57
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = getelementptr inbounds double, double* %58, i64 2
%62 = bitcast double* %61 to <2 x double>*
%63 = load <2 x double>, <2 x double>* %62
%64 = getelementptr inbounds double, double* %20, i64 %57
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %60, <2 x double>* %65
%66 = getelementptr inbounds double, double* %64, i64 2
%67 = bitcast double* %66 to <2 x double>*
store <2 x double> %63, <2 x double>* %67
%68 = or i64 %45, 8
%69 = getelementptr inbounds double, double* %24, i64 %68
%70 = bitcast double* %69 to <2 x double>*
%71 = load <2 x double>, <2 x double>* %70
%72 = getelementptr inbounds double, double* %69, i64 2
%73 = bitcast double* %72 to <2 x double>*
%74 = load <2 x double>, <2 x double>* %73
%75 = getelementptr inbounds double, double* %20, i64 %68
%76 = bitcast double* %75 to <2 x double>*
store <2 x double> %71, <2 x double>* %76
%77 = getelementptr inbounds double, double* %75, i64 2
%78 = bitcast double* %77 to <2 x double>*
store <2 x double> %74, <2 x double>* %78
%79 = or i64 %45, 12
%80 = getelementptr inbounds double, double* %24, i64 %79
%81 = bitcast double* %80 to <2 x double>*
%82 = load <2 x double>, <2 x double>* %81
%83 = getelementptr inbounds double, double* %80, i64 2
%84 = bitcast double* %83 to <2 x double>*
%85 = load <2 x double>, <2 x double>* %84
%86 = getelementptr inbounds double, double* %20, i64 %79
%87 = bitcast double* %86 to <2 x double>*
store <2 x double> %82, <2 x double>* %87
%88 = getelementptr inbounds double, double* %86, i64 2
%89 = bitcast double* %88 to <2 x double>*
store <2 x double> %85, <2 x double>* %89
%90 = add nuw i64 %45, 16
%91 = add nuw i64 %46, 4
%92 = icmp eq i64 %91, %43
br i1 %92, label %93, label %44
93: ; preds = %44, %35
%94 = phi i64 [ 0, %35 ], [ %90, %44 ]
%95 = icmp eq i64 %40, 0
br i1 %95, label %112, label %96
96: ; preds = %93, %96
%97 = phi i64 [ %109, %96 ], [ %94, %93 ]
%98 = phi i64 [ %110, %96 ], [ 0, %93 ]
%99 = getelementptr inbounds double, double* %24, i64 %97
%100 = bitcast double* %99 to <2 x double>*
%101 = load <2 x double>, <2 x double>* %100
%102 = getelementptr inbounds double, double* %99, i64 2
%103 = bitcast double* %102 to <2 x double>*
%104 = load <2 x double>, <2 x double>* %103
%105 = getelementptr inbounds double, double* %20, i64 %97
%106 = bitcast double* %105 to <2 x double>*
store <2 x double> %101, <2 x double>* %106
%107 = getelementptr inbounds double, double* %105, i64 2
%108 = bitcast double* %107 to <2 x double>*
store <2 x double> %104, <2 x double>* %108
%109 = add nuw i64 %97, 4
%110 = add i64 %98, 1
%111 = icmp eq i64 %110, %40
br i1 %111, label %112, label %96
112: ; preds = %96, %93
%113 = icmp eq i64 %36, %26
br i1 %113, label %151, label %114
114: ; preds = %28, %25, %112
%115 = phi i64 [ 0, %28 ], [ 0, %25 ], [ %36, %112 ]
%116 = xor i64 %115, -1
%117 = add nsw i64 %116, %26
%118 = and i64 %26, 3
%119 = icmp eq i64 %118, 0
br i1 %119, label %129, label %120
120: ; preds = %114, %120
%121 = phi i64 [ %126, %120 ], [ %115, %114 ]
%122 = phi i64 [ %127, %120 ], [ 0, %114 ]
%123 = getelementptr inbounds double, double* %24, i64 %121
%124 = load double, double* %123
%125 = getelementptr inbounds double, double* %20, i64 %121
store double %124, double* %125
%126 = add nuw nsw i64 %121, 1
%127 = add i64 %122, 1
%128 = icmp eq i64 %127, %118
br i1 %128, label %129, label %120
129: ; preds = %120, %114
%130 = phi i64 [ %115, %114 ], [ %126, %120 ]
%131 = icmp ult i64 %117, 3
br i1 %131, label %151, label %132
132: ; preds = %129, %132
%133 = phi i64 [ %149, %132 ], [ %130, %129 ]
%134 = getelementptr inbounds double, double* %24, i64 %133
%135 = load double, double* %134
%136 = getelementptr inbounds double, double* %20, i64 %133
store double %135, double* %136
%137 = add nuw nsw i64 %133, 1
%138 = getelementptr inbounds double, double* %24, i64 %137
%139 = load double, double* %138
%140 = getelementptr inbounds double, double* %20, i64 %137
store double %139, double* %140
%141 = add nuw nsw i64 %133, 2
%142 = getelementptr inbounds double, double* %24, i64 %141
%143 = load double, double* %142
%144 = getelementptr inbounds double, double* %20, i64 %141
store double %143, double* %144
%145 = add nuw nsw i64 %133, 3
%146 = getelementptr inbounds double, double* %24, i64 %145
%147 = load double, double* %146
%148 = getelementptr inbounds double, double* %20, i64 %145
store double %147, double* %148
%149 = add nuw nsw i64 %133, 4
%150 = icmp eq i64 %149, %26
br i1 %150, label %151, label %132
151: ; preds = %129, %132, %112, %17
store double* %20, double** %0
%152 = tail call i32 @free(double* %24)
br label %153
153: ; preds = %151, %13
ret void
}