#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 fabs(double);
int floor(double);
void unwrap(float *p, int N, double tol) {
  if (N < 2)
    return;
  if (tol <= 3.14159265358979323846)
    tol = 3.14159265358979323846;
  double dp = p[0 + 1] - p[0];
  double dps =
      (dp + 3.14159265358979323846) -
      floor((dp + 3.14159265358979323846) / (2 * 3.14159265358979323846)) *
          (2 * 3.14159265358979323846) -
      3.14159265358979323846;
  if ((dps == -3.14159265358979323846) && (dp > 0.0))
    dps = 3.14159265358979323846;
  double dp_corr = dps - dp;
  if (fabs(dp) < tol)
    dp_corr = 0.0;
  double cumsum;
  double cumsumOld = dp_corr;
  int j;
  for (j = 1; j < N - 1; j++) {
    dp = p[j + 1] - p[j];
    dps = (dp + 3.14159265358979323846) -
          floor((dp + 3.14159265358979323846) / (2 * 3.14159265358979323846)) *
              (2 * 3.14159265358979323846) -
          3.14159265358979323846;
    if ((dps == -3.14159265358979323846) && (dp > 0.0))
      dps = 3.14159265358979323846;
    dp_corr = dps - dp;
    if (fabs(dp) < tol)
      dp_corr = 0.0;
    cumsum = cumsumOld + dp_corr;
    p[j] += (float)cumsumOld;
    cumsumOld = cumsum;
  }
  p[N - 1] += (float)cumsumOld;
}


x86 assembly (clang, -O0):
<unwrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1133 <unwrap+0x23>
jmp    13df <unwrap+0x2cf>
movsd  0xec5(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1153 <unwrap+0x43>
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
subss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe8b(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe79(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe7c(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <floor@plt>
movsd  -0x50(%rbp),%xmm1
cvtsi2sd %eax,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe4b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe2b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe1d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    121a <unwrap+0x10a>
jp     121a <unwrap+0x10a>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    121a <unwrap+0x10a>
movsd  0xdeb(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
movaps 0xdeb(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1250 <unwrap+0x140>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13bf <unwrap+0x2af>
mov    -0x8(%rbp),%rax
mov    -0x44(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xd5e(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xd4c(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xd4f(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <floor@plt>
movsd  -0x58(%rbp),%xmm1
cvtsi2sd %eax,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd1e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xcfe(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xcf0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1347 <unwrap+0x237>
jp     1347 <unwrap+0x237>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1347 <unwrap+0x237>
movsd  0xcbe(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
movaps 0xcbe(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    137d <unwrap+0x26d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x40(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1261 <unwrap+0x151>
movsd  -0x40(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unwrap>:
cmp    $0x2,%esi
jl     120f <unwrap+0xff>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
movsd  0xecd(%rip),%xmm2
movapd %xmm2,%xmm1
maxsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movss  0x4(%rdi),%xmm0
subss  (%rdi),%xmm0
movss  %xmm0,0x20(%rsp)
cvtss2sd %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
addsd  %xmm2,%xmm0
movapd %xmm0,0x10(%rsp)
divsd  0xe9d(%rip),%xmm0
call   1030 <floor@plt>
movapd 0x10(%rsp),%xmm3
movsd  0xe82(%rip),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe7b(%rip),%xmm0
subsd  %xmm0,%xmm3
movsd  0xe77(%rip),%xmm1
addsd  %xmm1,%xmm3
xorpd  %xmm0,%xmm0
movss  0x20(%rsp),%xmm4
ucomiss %xmm0,%xmm4
ja     11b0 <unwrap+0xa0>
movapd %xmm3,%xmm2
movapd %xmm3,%xmm0
cmpeqsd %xmm1,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm3,%xmm0
orpd   %xmm2,%xmm0
movapd 0x30(%rsp),%xmm1
subsd  %xmm1,%xmm0
andpd  0xe49(%rip),%xmm1
cmpltsd 0x8(%rsp),%xmm1
andnpd %xmm0,%xmm1
lea    -0x1(%r14),%r15d
cmp    $0x2,%r14d
jne    1210 <unwrap+0x100>
movapd %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movslq %r15d,%rax
addss  (%r12,%rax,4),%xmm0
movss  %xmm0,(%r12,%rax,4)
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%r14d
mov    $0x1,%ebp
jmp    1280 <unwrap+0x170>
nopw   0x0(%rax,%rax,1)
movapd %xmm3,%xmm1
cmpeqsd %xmm2,%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm3,%xmm1
orpd   %xmm0,%xmm1
movapd 0x20(%rsp),%xmm2
subsd  %xmm2,%xmm1
andpd  0xdd9(%rip),%xmm2
cmpltsd 0x8(%rsp),%xmm2
andnpd %xmm1,%xmm2
movapd 0x30(%rsp),%xmm0
addsd  %xmm0,%xmm2
cvtsd2ss %xmm0,%xmm0
addss  (%r12,%rbp,4),%xmm0
movss  %xmm0,(%r12,%rbp,4)
mov    %rbx,%rbp
movapd %xmm2,%xmm1
cmp    %rbx,%r14
movapd %xmm2,%xmm0
je     11f0 <unwrap+0xe0>
movapd %xmm1,0x30(%rsp)
movss  0x4(%r12,%rbp,4),%xmm0
subss  (%r12,%rbp,4),%xmm0
movss  %xmm0,0x10(%rsp)
lea    0x1(%rbp),%rbx
cvtss2sd %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,%xmm1
movsd  0xd4f(%rip),%xmm0
addsd  %xmm0,%xmm1
movapd %xmm1,0x40(%rsp)
movapd %xmm1,%xmm0
movsd  0xd41(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <floor@plt>
movapd 0x40(%rsp),%xmm3
movsd  0xd32(%rip),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd1b(%rip),%xmm0
subsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
movss  0x10(%rsp),%xmm0
ucomiss 0xd2e(%rip),%xmm0
movsd  0xcf6(%rip),%xmm0
ja     1220 <unwrap+0x110>
movapd %xmm3,%xmm0
jmp    1220 <unwrap+0x110>

LLVM IR (-O0):
define void @unwrap(float* %0, i32 %1, double %2) {
%4 = alloca float*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store float* %0, float** %4
store i32 %1, i32* %5
store double %2, double* %6
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %3
br label %126
16: ; preds = %3
%17 = load double, double* %6
%18 = fcmp ole double %17, 0x400921FB54442D18
br i1 %18, label %19, label %20
19: ; preds = %16
store double 0x400921FB54442D18, double* %6
br label %20
20: ; preds = %19, %16
%21 = load float*, float** %4
%22 = getelementptr inbounds float, float* %21, i64 1
%23 = load float, float* %22
%24 = load float*, float** %4
%25 = getelementptr inbounds float, float* %24, i64 0
%26 = load float, float* %25
%27 = fsub float %23, %26
%28 = fpext float %27 to double
store double %28, double* %7
%29 = load double, double* %7
%30 = fadd double %29, 0x400921FB54442D18
%31 = load double, double* %7
%32 = fadd double %31, 0x400921FB54442D18
%33 = fdiv double %32, 0x401921FB54442D18
%34 = call i32 @floor(double %33)
%35 = sitofp i32 %34 to double
%36 = fneg double %35
%37 = call double @llvm.fmuladd.f64(double %36, double 0x401921FB54442D18, double %30)
%38 = fsub double %37, 0x400921FB54442D18
store double %38, double* %8
%39 = load double, double* %8
%40 = fcmp oeq double %39, 0xC00921FB54442D18
br i1 %40, label %41, label %45
41: ; preds = %20
%42 = load double, double* %7
%43 = fcmp ogt double %42, 0.000000e+00
br i1 %43, label %44, label %45
44: ; preds = %41
store double 0x400921FB54442D18, double* %8
br label %45
45: ; preds = %44, %41, %20
%46 = load double, double* %8
%47 = load double, double* %7
%48 = fsub double %46, %47
store double %48, double* %9
%49 = load double, double* %7
%50 = call double @llvm.fabs.f64(double %49)
%51 = load double, double* %6
%52 = fcmp olt double %50, %51
br i1 %52, label %53, label %54
53: ; preds = %45
store double 0.000000e+00, double* %9
br label %54
54: ; preds = %53, %45
%55 = load double, double* %9
store double %55, double* %11
store i32 1, i32* %12
br label %56
56: ; preds = %113, %54
%57 = load i32, i32* %12
%58 = load i32, i32* %5
%59 = sub nsw i32 %58, 1
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %116
61: ; preds = %56
%62 = load float*, float** %4
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds float, float* %62, i64 %65
%67 = load float, float* %66
%68 = load float*, float** %4
%69 = load i32, i32* %12
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds float, float* %68, i64 %70
%72 = load float, float* %71
%73 = fsub float %67, %72
%74 = fpext float %73 to double
store double %74, double* %7
%75 = load double, double* %7
%76 = fadd double %75, 0x400921FB54442D18
%77 = load double, double* %7
%78 = fadd double %77, 0x400921FB54442D18
%79 = fdiv double %78, 0x401921FB54442D18
%80 = call i32 @floor(double %79)
%81 = sitofp i32 %80 to double
%82 = fneg double %81
%83 = call double @llvm.fmuladd.f64(double %82, double 0x401921FB54442D18, double %76)
%84 = fsub double %83, 0x400921FB54442D18
store double %84, double* %8
%85 = load double, double* %8
%86 = fcmp oeq double %85, 0xC00921FB54442D18
br i1 %86, label %87, label %91
87: ; preds = %61
%88 = load double, double* %7
%89 = fcmp ogt double %88, 0.000000e+00
br i1 %89, label %90, label %91
90: ; preds = %87
store double 0x400921FB54442D18, double* %8
br label %91
91: ; preds = %90, %87, %61
%92 = load double, double* %8
%93 = load double, double* %7
%94 = fsub double %92, %93
store double %94, double* %9
%95 = load double, double* %7
%96 = call double @llvm.fabs.f64(double %95)
%97 = load double, double* %6
%98 = fcmp olt double %96, %97
br i1 %98, label %99, label %100
99: ; preds = %91
store double 0.000000e+00, double* %9
br label %100
100: ; preds = %99, %91
%101 = load double, double* %11
%102 = load double, double* %9
%103 = fadd double %101, %102
store double %103, double* %10
%104 = load double, double* %11
%105 = fptrunc double %104 to float
%106 = load float*, float** %4
%107 = load i32, i32* %12
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds float, float* %106, i64 %108
%110 = load float, float* %109
%111 = fadd float %110, %105
store float %111, float* %109
%112 = load double, double* %10
store double %112, double* %11
br label %113
113: ; preds = %100
%114 = load i32, i32* %12
%115 = add nsw i32 %114, 1
store i32 %115, i32* %12
br label %56
116: ; preds = %56
%117 = load double, double* %11
%118 = fptrunc double %117 to float
%119 = load float*, float** %4
%120 = load i32, i32* %5
%121 = sub nsw i32 %120, 1
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds float, float* %119, i64 %122
%124 = load float, float* %123
%125 = fadd float %124, %118
store float %125, float* %123
br label %126
126: ; preds = %116, %15
ret void
}

LLVM IR (-O2):
define void @unwrap(float* nocapture %0, i32 %1, double %2) {
%4 = icmp slt i32 %1, 2
br i1 %4, label %69, label %5
5: ; preds = %3
%6 = fcmp ole double %2, 0x400921FB54442D18
%7 = select i1 %6, double 0x400921FB54442D18, double %2
%8 = getelementptr inbounds float, float* %0, i64 1
%9 = load float, float* %8
%10 = load float, float* %0
%11 = fsub float %9, %10
%12 = fpext float %11 to double
%13 = fadd double %12, 0x400921FB54442D18
%14 = fdiv double %13, 0x401921FB54442D18
%15 = tail call i32 @floor(double %14)
%16 = sitofp i32 %15 to double
%17 = fneg double %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double 0x401921FB54442D18, double %13)
%19 = fadd double %18, 0xC00921FB54442D18
%20 = fcmp oeq double %19, 0xC00921FB54442D18
%21 = fcmp ogt float %11, 0.000000e+00
%22 = select i1 %20, i1 %21, i1 false
%23 = select i1 %22, double 0x400921FB54442D18, double %19
%24 = fsub double %23, %12
%25 = tail call double @llvm.fabs.f64(double %12)
%26 = fcmp olt double %25, %7
%27 = select i1 %26, double 0.000000e+00, double %24
%28 = add nsw i32 %1, -1
%29 = icmp eq i32 %1, 2
br i1 %29, label %62, label %30
30: ; preds = %5
%31 = zext i32 %28 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 1, %30 ], [ %35, %32 ]
%34 = phi double [ %27, %30 ], [ %57, %32 ]
%35 = add nuw nsw i64 %33, 1
%36 = getelementptr inbounds float, float* %0, i64 %35
%37 = load float, float* %36
%38 = getelementptr inbounds float, float* %0, i64 %33
%39 = load float, float* %38
%40 = fsub float %37, %39
%41 = fpext float %40 to double
%42 = fadd double %41, 0x400921FB54442D18
%43 = fdiv double %42, 0x401921FB54442D18
%44 = tail call i32 @floor(double %43)
%45 = sitofp i32 %44 to double
%46 = fneg double %45
%47 = tail call double @llvm.fmuladd.f64(double %46, double 0x401921FB54442D18, double %42)
%48 = fadd double %47, 0xC00921FB54442D18
%49 = fcmp oeq double %48, 0xC00921FB54442D18
%50 = fcmp ogt float %40, 0.000000e+00
%51 = select i1 %49, i1 %50, i1 false
%52 = select i1 %51, double 0x400921FB54442D18, double %48
%53 = fsub double %52, %41
%54 = tail call double @llvm.fabs.f64(double %41)
%55 = fcmp olt double %54, %7
%56 = select i1 %55, double 0.000000e+00, double %53
%57 = fadd double %34, %56
%58 = fptrunc double %34 to float
%59 = load float, float* %38
%60 = fadd float %59, %58
store float %60, float* %38
%61 = icmp eq i64 %35, %31
br i1 %61, label %62, label %32
62: ; preds = %32, %5
%63 = phi double [ %27, %5 ], [ %57, %32 ]
%64 = fptrunc double %63 to float
%65 = sext i32 %28 to i64
%66 = getelementptr inbounds float, float* %0, i64 %65
%67 = load float, float* %66
%68 = fadd float %67, %64
store float %68, float* %66
br label %69
69: ; preds = %3, %62
ret void
}