#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*/ free(double *);
double *malloc(int);
double *dn_sample(double **a, int N) {
  double *p = *a;
  double *temp;
  int i;
  temp = malloc(N * sizeof(double));
  for (i = 0; i < N; i++) {
    if (0 == i % 2) {
      temp[i / 2] = p[i];
    } else if (1 == i % 2) {
      temp[(i - 1) / 2 + N / 2] = p[i];
    }
  }
  for (i = 0; i < N; i++) {
    p[i] = temp[i];
  }
  free(temp);
  return p;
}


x86 assembly (clang, -O0):
<dn_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1218 <dn_sample+0xf8>
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    11a8 <dn_sample+0x88>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1205 <dn_sample+0xe5>
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x1,%eax
cmp    %edx,%eax
jne    1200 <dn_sample+0xe0>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x38(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1205 <dn_sample+0xe5>
jmp    120a <dn_sample+0xea>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1154 <dn_sample+0x34>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1253 <dn_sample+0x133>
mov    -0x20(%rbp),%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    121f <dn_sample+0xff>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dn_sample>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r15d
mov    (%rdi),%r14
lea    0x0(,%r15,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
jle    11a5 <dn_sample+0x75>
mov    %r15d,%eax
shr    %eax
mov    %r15d,%edx
xor    %ecx,%ecx
jmp    1186 <dn_sample+0x56>
nopl   0x0(%rax)
lea    -0x1(%rcx),%esi
shr    $0x1f,%esi
add    %ecx,%esi
add    $0xffffffff,%esi
sar    %esi
add    %eax,%esi
movslq %esi,%rsi
movsd  (%r14,%rcx,8),%xmm0
movsd  %xmm0,(%rbx,%rsi,8)
add    $0x1,%rcx
cmp    %rcx,%rdx
je     1191 <dn_sample+0x61>
test   $0x1,%cl
jne    1160 <dn_sample+0x30>
mov    %ecx,%esi
shr    %esi
jmp    1172 <dn_sample+0x42>
test   %r15d,%r15d
jle    11a5 <dn_sample+0x75>
shl    $0x3,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @dn_sample(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 double**, double*** %3
%9 = load double*, double** %8
store double* %9, double** %5
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call double* @malloc(i32 %13)
store double* %14, double** %6
store i32 0, i32* %7
br label %15
15: ; preds = %55, %2
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %58
19: ; preds = %15
%20 = load i32, i32* %7
%21 = srem i32 %20, 2
%22 = icmp eq i32 0, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load double*, double** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = load double*, double** %6
%30 = load i32, i32* %7
%31 = sdiv i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %29, i64 %32
store double %28, double* %33
br label %54
34: ; preds = %19
%35 = load i32, i32* %7
%36 = srem i32 %35, 2
%37 = icmp eq i32 1, %36
br i1 %37, label %38, label %53
38: ; preds = %34
%39 = load double*, double** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double*, double** %6
%45 = load i32, i32* %7
%46 = sub nsw i32 %45, 1
%47 = sdiv i32 %46, 2
%48 = load i32, i32* %4
%49 = sdiv i32 %48, 2
%50 = add nsw i32 %47, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %44, i64 %51
store double %43, double* %52
br label %53
53: ; preds = %38, %34
br label %54
54: ; preds = %53, %23
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %15
58: ; preds = %15
store i32 0, i32* %7
br label %59
59: ; preds = %73, %58
%60 = load i32, i32* %7
%61 = load i32, i32* %4
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %76
63: ; preds = %59
%64 = load double*, double** %6
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
%68 = load double, double* %67
%69 = load double*, double** %5
%70 = load i32, i32* %7
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
store double %68, double* %72
br label %73
73: ; preds = %63
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %59
76: ; preds = %59
%77 = load double*, double** %6
%78 = call i32 @free(double* %77)
%79 = load double*, double** %5
ret double* %79
}

LLVM IR (-O2):
define double* @dn_sample(double** nocapture %0, i32 %1) {
%3 = load double*, double** %0
%4 = bitcast double* %3 to i8*
%5 = shl i32 %1, 3
%6 = tail call double* @malloc(i32 %5)
%7 = bitcast double* %6 to i8*
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %36
9: ; preds = %2
%10 = lshr i32 %1, 1
%11 = zext i32 %1 to i64
br label %16
12: ; preds = %31
br i1 %8, label %13, label %36
13: ; preds = %12
%14 = zext i32 %1 to i64
%15 = shl nuw nsw i64 %14, 3
br label %36
16: ; preds = %9, %31
%17 = phi i64 [ 0, %9 ], [ %34, %31 ]
%18 = and i64 %17, 1
%19 = icmp eq i64 %18, 0
%20 = getelementptr inbounds double, double* %3, i64 %17
%21 = load double, double* %20
br i1 %19, label %22, label %25
22: ; preds = %16
%23 = lshr i64 %17, 1
%24 = and i64 %23, 2147483647
br label %31
25: ; preds = %16
%26 = trunc i64 %17 to i32
%27 = add i32 %26, -1
%28 = sdiv i32 %27, 2
%29 = add nsw i32 %28, %10
%30 = sext i32 %29 to i64
br label %31
31: ; preds = %22, %25
%32 = phi i64 [ %24, %22 ], [ %30, %25 ]
%33 = getelementptr inbounds double, double* %6, i64 %32
store double %21, double* %33
%34 = add nuw nsw i64 %17, 1
%35 = icmp eq i64 %34, %11
br i1 %35, label %12, label %16
36: ; preds = %2, %13, %12
%37 = tail call i32 @free(double* %6)
ret double* %3
}