#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*/ assert(double *);
double vectord_mean(double *, size_t);
void vectord_remove_mean_inplace(double *self, size_t size) {
  assert(self);
  double mean = vectord_mean(self, size);
  for (size_t i = 0; i < size; i++)
    self[i] -= mean;
}


x86 assembly (clang, -O0):
<vectord_remove_mean_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <vectord_mean@plt>
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118d <vectord_remove_mean_inplace+0x6d>
movsd  -0x18(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1153 <vectord_remove_mean_inplace+0x33>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vectord_remove_mean_inplace>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <vectord_mean@plt>
test   %r14,%r14
je     1207 <vectord_remove_mean_inplace+0xe7>
cmp    $0x4,%r14
jae    1150 <vectord_remove_mean_inplace+0x30>
xor    %eax,%eax
jmp    11f0 <vectord_remove_mean_inplace+0xd0>
mov    %r14,%rax
and    $0xfffffffffffffffc,%rax
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rax),%rcx
mov    %rcx,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
test   %rcx,%rcx
je     120f <vectord_remove_mean_inplace+0xef>
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %ecx,%ecx
movupd (%rbx,%rcx,8),%xmm2
movupd 0x10(%rbx,%rcx,8),%xmm3
movupd 0x20(%rbx,%rcx,8),%xmm4
movupd 0x30(%rbx,%rcx,8),%xmm5
subpd  %xmm1,%xmm2
subpd  %xmm1,%xmm3
movupd %xmm2,(%rbx,%rcx,8)
movupd %xmm3,0x10(%rbx,%rcx,8)
subpd  %xmm1,%xmm4
subpd  %xmm1,%xmm5
movupd %xmm4,0x20(%rbx,%rcx,8)
movupd %xmm5,0x30(%rbx,%rcx,8)
add    $0x8,%rcx
add    $0xfffffffffffffffe,%rsi
jne    1180 <vectord_remove_mean_inplace+0x60>
test   $0x1,%dl
je     11eb <vectord_remove_mean_inplace+0xcb>
movupd (%rbx,%rcx,8),%xmm2
movupd 0x10(%rbx,%rcx,8),%xmm3
subpd  %xmm1,%xmm2
subpd  %xmm1,%xmm3
movupd %xmm2,(%rbx,%rcx,8)
movupd %xmm3,0x10(%rbx,%rcx,8)
cmp    %r14,%rax
je     1207 <vectord_remove_mean_inplace+0xe7>
movsd  (%rbx,%rax,8),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %rax,%r14
jne    11f0 <vectord_remove_mean_inplace+0xd0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %ecx,%ecx
test   $0x1,%dl
jne    11cd <vectord_remove_mean_inplace+0xad>
jmp    11eb <vectord_remove_mean_inplace+0xcb>

LLVM IR (-O0):
define void @vectord_remove_mean_inplace(double* %0, i64 %1) {
%3 = alloca double*
%4 = alloca i64
%5 = alloca double
%6 = alloca i64
store double* %0, double** %3
store i64 %1, i64* %4
%7 = load double*, double** %3
%8 = call i32 @assert(double* %7)
%9 = load double*, double** %3
%10 = load i64, i64* %4
%11 = call double @vectord_mean(double* %9, i64 %10)
store double %11, double* %5
store i64 0, i64* %6
br label %12
12: ; preds = %23, %2
%13 = load i64, i64* %6
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load double, double* %5
%18 = load double*, double** %3
%19 = load i64, i64* %6
%20 = getelementptr inbounds double, double* %18, i64 %19
%21 = load double, double* %20
%22 = fsub double %21, %17
store double %22, double* %20
br label %23
23: ; preds = %16
%24 = load i64, i64* %6
%25 = add i64 %24, 1
store i64 %25, i64* %6
br label %12
26: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @vectord_remove_mean_inplace(double* %0, i64 %1) {
%3 = tail call i32 @assert(double* %0)
%4 = tail call double @vectord_mean(double* %0, i64 %1)
%5 = icmp eq i64 %1, 0
br i1 %5, label %66, label %6
6: ; preds = %2
%7 = icmp ult i64 %1, 4
br i1 %7, label %64, label %8
8: ; preds = %6
%9 = and i64 %1, -4
%10 = insertelement <2 x double> poison, double %4, i64 0
%11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
%12 = insertelement <2 x double> poison, double %4, i64 0
%13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> zeroinitializer
%14 = add i64 %9, -4
%15 = lshr exact i64 %14, 2
%16 = add nuw nsw i64 %15, 1
%17 = and i64 %16, 1
%18 = icmp eq i64 %14, 0
br i1 %18, label %48, label %19
19: ; preds = %8
%20 = and i64 %16, 9223372036854775806
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %45, %21 ]
%23 = phi i64 [ 0, %19 ], [ %46, %21 ]
%24 = getelementptr inbounds double, double* %0, i64 %22
%25 = bitcast double* %24 to <2 x double>*
%26 = load <2 x double>, <2 x double>* %25
%27 = getelementptr inbounds double, double* %24, i64 2
%28 = bitcast double* %27 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = fsub <2 x double> %26, %11
%31 = fsub <2 x double> %29, %13
%32 = bitcast double* %24 to <2 x double>*
store <2 x double> %30, <2 x double>* %32
%33 = bitcast double* %27 to <2 x double>*
store <2 x double> %31, <2 x double>* %33
%34 = or i64 %22, 4
%35 = getelementptr inbounds double, double* %0, i64 %34
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %35, i64 2
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = fsub <2 x double> %37, %11
%42 = fsub <2 x double> %40, %13
%43 = bitcast double* %35 to <2 x double>*
store <2 x double> %41, <2 x double>* %43
%44 = bitcast double* %38 to <2 x double>*
store <2 x double> %42, <2 x double>* %44
%45 = add nuw i64 %22, 8
%46 = add i64 %23, 2
%47 = icmp eq i64 %46, %20
br i1 %47, label %48, label %21
48: ; preds = %21, %8
%49 = phi i64 [ 0, %8 ], [ %45, %21 ]
%50 = icmp eq i64 %17, 0
br i1 %50, label %62, label %51
51: ; preds = %48
%52 = getelementptr inbounds double, double* %0, i64 %49
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = getelementptr inbounds double, double* %52, i64 2
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = fsub <2 x double> %54, %11
%59 = fsub <2 x double> %57, %13
%60 = bitcast double* %52 to <2 x double>*
store <2 x double> %58, <2 x double>* %60
%61 = bitcast double* %55 to <2 x double>*
store <2 x double> %59, <2 x double>* %61
br label %62
62: ; preds = %48, %51
%63 = icmp eq i64 %9, %1
br i1 %63, label %66, label %64
64: ; preds = %6, %62
%65 = phi i64 [ 0, %6 ], [ %9, %62 ]
br label %67
66: ; preds = %67, %62, %2
ret void
67: ; preds = %64, %67
%68 = phi i64 [ %72, %67 ], [ %65, %64 ]
%69 = getelementptr inbounds double, double* %0, i64 %68
%70 = load double, double* %69
%71 = fsub double %70, %4
store double %71, double* %69
%72 = add nuw i64 %68, 1
%73 = icmp eq i64 %72, %1
br i1 %73, label %66, label %67
}