#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 */
scalar_t__ MemAlloc(int);
double *derivate(double *h) {
  double *d;
  int i;
  d = (double *)MemAlloc(sizeof(double) * 32768);
  d[0] = h[1] - h[0];
  d[32767] = h[32767] - h[32766];
  for (i = 1; i < 32767; i++)
    d[i] = (h[i + 1] - h[i - 1]) / 2.0;
  return d;
}


x86 assembly (clang, -O0):
<derivate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x40000,%edi
call   1030 <MemAlloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x3fff8(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x3fff0(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x3fff8(%rax)
movl   $0x1,-0x14(%rbp)
cmpl   $0x7fff,-0x14(%rbp)
jge    11c6 <derivate+0xb6>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  0xe59(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <derivate+0x5e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<derivate>:
push   %rbx
mov    %rdi,%rbx
mov    $0x40000,%edi
call   1030 <MemAlloc@plt>
movsd  0x8(%rbx),%xmm0
subsd  (%rbx),%xmm0
movsd  %xmm0,(%rax)
movsd  0x3fff8(%rbx),%xmm0
subsd  0x3fff0(%rbx),%xmm0
movsd  %xmm0,0x3fff8(%rax)
lea    0x8(%rax),%rcx
lea    0x40000(%rbx),%rdx
cmp    %rdx,%rcx
jae    116b <derivate+0x5b>
mov    %rax,%rdx
add    $0x3fff8,%rdx
mov    $0x1,%ecx
cmp    %rbx,%rdx
ja     11ef <derivate+0xdf>
xor    %ecx,%ecx
movapd 0xe8b(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nop
movupd (%rbx,%rcx,8),%xmm1
movupd 0x10(%rbx,%rcx,8),%xmm2
movupd 0x20(%rbx,%rcx,8),%xmm3
subpd  %xmm2,%xmm3
subpd  %xmm1,%xmm2
mulpd  %xmm0,%xmm2
mulpd  %xmm0,%xmm3
movupd %xmm2,0x8(%rax,%rcx,8)
movupd %xmm3,0x18(%rax,%rcx,8)
cmp    $0x7ff8,%rcx
je     11ea <derivate+0xda>
movupd 0x20(%rbx,%rcx,8),%xmm1
movupd 0x30(%rbx,%rcx,8),%xmm2
movupd 0x40(%rbx,%rcx,8),%xmm3
subpd  %xmm2,%xmm3
subpd  %xmm1,%xmm2
mulpd  %xmm0,%xmm2
mulpd  %xmm0,%xmm3
movupd %xmm2,0x28(%rax,%rcx,8)
movupd %xmm3,0x38(%rax,%rcx,8)
add    $0x8,%rcx
jmp    1180 <derivate+0x70>
mov    $0x7ffd,%ecx
movsd  0xe19(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movsd  0x8(%rbx,%rcx,8),%xmm1
subsd  -0x8(%rbx,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rcx,8)
movsd  0x10(%rbx,%rcx,8),%xmm1
subsd  (%rbx,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rax,%rcx,8)
lea    0x2(%rcx),%rdx
mov    %rdx,%rcx
cmp    $0x7fff,%rdx
jne    1200 <derivate+0xf0>
pop    %rbx
ret

LLVM IR (-O0):
define double* @derivate(double* %0) {
%2 = alloca double*
%3 = alloca double*
%4 = alloca i32
store double* %0, double** %2
%5 = call i64 @MemAlloc(i32 262144)
%6 = inttoptr i64 %5 to double*
store double* %6, double** %3
%7 = load double*, double** %2
%8 = getelementptr inbounds double, double* %7, i64 1
%9 = load double, double* %8
%10 = load double*, double** %2
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = fsub double %9, %12
%14 = load double*, double** %3
%15 = getelementptr inbounds double, double* %14, i64 0
store double %13, double* %15
%16 = load double*, double** %2
%17 = getelementptr inbounds double, double* %16, i64 32767
%18 = load double, double* %17
%19 = load double*, double** %2
%20 = getelementptr inbounds double, double* %19, i64 32766
%21 = load double, double* %20
%22 = fsub double %18, %21
%23 = load double*, double** %3
%24 = getelementptr inbounds double, double* %23, i64 32767
store double %22, double* %24
store i32 1, i32* %4
br label %25
25: ; preds = %47, %1
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 32767
br i1 %27, label %28, label %50
28: ; preds = %25
%29 = load double*, double** %2
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %29, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %2
%36 = load i32, i32* %4
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %35, i64 %38
%40 = load double, double* %39
%41 = fsub double %34, %40
%42 = fdiv double %41, 2.000000e+00
%43 = load double*, double** %3
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
br label %47
47: ; preds = %28
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %25
50: ; preds = %25
%51 = load double*, double** %3
ret double* %51
}

LLVM IR (-O2):
define double* @derivate(double* nocapture %0) {
%2 = tail call i64 @MemAlloc(i32 262144)
%3 = inttoptr i64 %2 to double*
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = load double, double* %0
%7 = fsub double %5, %6
store double %7, double* %3
%8 = getelementptr inbounds double, double* %0, i64 32767
%9 = load double, double* %8
%10 = getelementptr inbounds double, double* %0, i64 32766
%11 = load double, double* %10
%12 = fsub double %9, %11
%13 = getelementptr inbounds double, double* %3, i64 32767
store double %12, double* %13
%14 = getelementptr double, double* %3, i64 1
%15 = getelementptr double, double* %3, i64 32767
%16 = getelementptr double, double* %0, i64 32768
%17 = icmp ult double* %14, %16
%18 = icmp ugt double* %15, %0
%19 = and i1 %17, %18
br i1 %19, label %70, label %20
20: ; preds = %1, %46
%21 = phi i64 [ %69, %46 ], [ 0, %1 ]
%22 = or i64 %21, 1
%23 = or i64 %21, 2
%24 = getelementptr inbounds double, double* %0, i64 %23
%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 = getelementptr inbounds double, double* %0, i64 %21
%31 = bitcast double* %30 to <2 x double>*
%32 = load <2 x double>, <2 x double>* %31
%33 = getelementptr inbounds double, double* %30, i64 2
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = fsub <2 x double> %26, %32
%37 = fsub <2 x double> %29, %35
%38 = fmul <2 x double> %36, <double 5.000000e-01, double 5.000000e-01>
%39 = fmul <2 x double> %37, <double 5.000000e-01, double 5.000000e-01>
%40 = getelementptr inbounds double, double* %3, i64 %22
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> %38, <2 x double>* %41
%42 = getelementptr inbounds double, double* %40, i64 2
%43 = bitcast double* %42 to <2 x double>*
store <2 x double> %39, <2 x double>* %43
%44 = or i64 %21, 4
%45 = icmp eq i64 %44, 32764
br i1 %45, label %70, label %46
46: ; preds = %20
%47 = or i64 %21, 5
%48 = or i64 %21, 6
%49 = getelementptr inbounds double, double* %0, i64 %48
%50 = bitcast double* %49 to <2 x double>*
%51 = load <2 x double>, <2 x double>* %50
%52 = getelementptr inbounds double, double* %49, i64 2
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = getelementptr inbounds double, double* %0, i64 %44
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double, double* %55, i64 2
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = fsub <2 x double> %51, %57
%62 = fsub <2 x double> %54, %60
%63 = fmul <2 x double> %61, <double 5.000000e-01, double 5.000000e-01>
%64 = fmul <2 x double> %62, <double 5.000000e-01, double 5.000000e-01>
%65 = getelementptr inbounds double, double* %3, i64 %47
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %63, <2 x double>* %66
%67 = getelementptr inbounds double, double* %65, i64 2
%68 = bitcast double* %67 to <2 x double>*
store <2 x double> %64, <2 x double>* %68
%69 = add nuw nsw i64 %21, 8
br label %20
70: ; preds = %20, %1
%71 = phi i64 [ 1, %1 ], [ 32765, %20 ]
br label %72
72: ; preds = %72, %70
%73 = phi i64 [ %71, %70 ], [ %83, %72 ]
%74 = add nuw nsw i64 %73, 1
%75 = getelementptr inbounds double, double* %0, i64 %74
%76 = load double, double* %75
%77 = add nsw i64 %73, -1
%78 = getelementptr inbounds double, double* %0, i64 %77
%79 = load double, double* %78
%80 = fsub double %76, %79
%81 = fmul double %80, 5.000000e-01
%82 = getelementptr inbounds double, double* %3, i64 %73
store double %81, double* %82
%83 = add nuw nsw i64 %73, 2
%84 = getelementptr inbounds double, double* %0, i64 %83
%85 = load double, double* %84
%86 = getelementptr inbounds double, double* %0, i64 %73
%87 = load double, double* %86
%88 = fsub double %85, %87
%89 = fmul double %88, 5.000000e-01
%90 = getelementptr inbounds double, double* %3, i64 %74
store double %89, double* %90
%91 = icmp eq i64 %83, 32767
br i1 %91, label %92, label %72
92: ; preds = %72
ret double* %3
}