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


x86 assembly (clang, -O0):
<up_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    11da <up_sample+0xba>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0xc(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x30(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1154 <up_sample+0x34>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1215 <up_sample+0xf5>
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    11e1 <up_sample+0xc1>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<up_sample>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    (%rdi),%r12
lea    0x0(,%r15,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
cmp    $0x2,%r15d
jl     1261 <up_sample+0x131>
mov    %r15d,%eax
shr    $0x1f,%eax
add    %r15d,%eax
sar    %eax
movslq %eax,%r8
mov    %r8d,%r10d
cmp    $0x2,%r8d
jae    1176 <up_sample+0x46>
xor    %ecx,%ecx
jmp    1225 <up_sample+0xf5>
mov    %r10d,%ecx
and    $0xfffffffe,%ecx
lea    -0x2(%rcx),%rax
mov    %rax,%r9
shr    %r9
add    $0x1,%r9
test   %rax,%rax
je     128f <up_sample+0x15f>
mov    %r9,%rdi
and    $0xfffffffffffffffe,%rdi
lea    0x10(%r12),%rdx
lea    0x20(%r14),%rbx
lea    (%r12,%r8,8),%rax
add    $0x10,%rax
xor    %esi,%esi
nopl   (%rax)
movups -0x10(%rdx,%rsi,8),%xmm0
movups -0x10(%rax,%rsi,8),%xmm1
movaps %xmm0,%xmm2
movlhps %xmm1,%xmm2
unpckhpd %xmm1,%xmm0
movups %xmm0,-0x10(%rbx)
movups %xmm2,-0x20(%rbx)
movups (%rdx,%rsi,8),%xmm0
movups (%rax,%rsi,8),%xmm1
movaps %xmm0,%xmm2
movlhps %xmm1,%xmm2
unpckhpd %xmm1,%xmm0
movups %xmm0,0x10(%rbx)
movups %xmm2,(%rbx)
add    $0x4,%rsi
add    $0x40,%rbx
add    $0xfffffffffffffffe,%rdi
jne    11b0 <up_sample+0x80>
test   $0x1,%r9b
je     1220 <up_sample+0xf0>
movups (%r12,%rsi,8),%xmm0
lea    (%rsi,%r8,1),%rax
movups (%r12,%rax,8),%xmm1
shl    $0x4,%rsi
movaps %xmm0,%xmm2
movlhps %xmm1,%xmm2
unpckhpd %xmm1,%xmm0
movups %xmm0,0x10(%r14,%rsi,1)
movups %xmm2,(%r14,%rsi,1)
cmp    %r10,%rcx
je     1261 <up_sample+0x131>
lea    (%r12,%r8,8),%rax
mov    %rcx,%rdx
shl    $0x4,%rdx
add    %r14,%rdx
add    $0x8,%rdx
nopw   0x0(%rax,%rax,1)
movsd  (%r12,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rdx)
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rdx)
add    $0x1,%rcx
add    $0x10,%rdx
cmp    %rcx,%r10
jne    1240 <up_sample+0x110>
test   %r15d,%r15d
jle    1278 <up_sample+0x148>
mov    %r15d,%edx
shl    $0x3,%rdx
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %esi,%esi
test   $0x1,%r9b
jne    11f9 <up_sample+0xc9>
jmp    1220 <up_sample+0xf0>

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

LLVM IR (-O2):
define double* @up_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 = sdiv i32 %1, 2
%9 = icmp sgt i32 %1, 1
br i1 %9, label %10, label %77
10: ; preds = %2
%11 = sext i32 %8 to i64
%12 = zext i32 %8 to i64
%13 = icmp ult i32 %8, 2
br i1 %13, label %75, label %14
14: ; preds = %10
%15 = and i64 %12, 4294967294
%16 = add nsw i64 %15, -2
%17 = lshr exact i64 %16, 1
%18 = add nuw i64 %17, 1
%19 = and i64 %18, 1
%20 = icmp eq i64 %16, 0
br i1 %20, label %56, label %21
21: ; preds = %14
%22 = and i64 %18, -2
%23 = getelementptr inbounds double, double* %6, i64 -1
%24 = getelementptr inbounds double, double* %6, i64 -1
br label %25
25: ; preds = %25, %21
%26 = phi i64 [ 0, %21 ], [ %53, %25 ]
%27 = phi i64 [ 0, %21 ], [ %54, %25 ]
%28 = getelementptr inbounds double, double* %3, i64 %26
%29 = bitcast double* %28 to <2 x double>*
%30 = load <2 x double>, <2 x double>* %29
%31 = shl nuw nsw i64 %26, 1
%32 = add nsw i64 %26, %11
%33 = getelementptr inbounds double, double* %3, i64 %32
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = or i64 %31, 1
%37 = getelementptr inbounds double, double* %23, i64 %36
%38 = bitcast double* %37 to <4 x double>*
%39 = shufflevector <2 x double> %30, <2 x double> %35, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
store <4 x double> %39, <4 x double>* %38
%40 = or i64 %26, 2
%41 = getelementptr inbounds double, double* %3, i64 %40
%42 = bitcast double* %41 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = shl nuw nsw i64 %40, 1
%45 = add nsw i64 %40, %11
%46 = getelementptr inbounds double, double* %3, i64 %45
%47 = bitcast double* %46 to <2 x double>*
%48 = load <2 x double>, <2 x double>* %47
%49 = or i64 %44, 1
%50 = getelementptr inbounds double, double* %24, i64 %49
%51 = bitcast double* %50 to <4 x double>*
%52 = shufflevector <2 x double> %43, <2 x double> %48, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
store <4 x double> %52, <4 x double>* %51
%53 = add nuw i64 %26, 4
%54 = add nuw i64 %27, 2
%55 = icmp eq i64 %54, %22
br i1 %55, label %56, label %25
56: ; preds = %25, %14
%57 = phi i64 [ 0, %14 ], [ %53, %25 ]
%58 = icmp eq i64 %19, 0
br i1 %58, label %73, label %59
59: ; preds = %56
%60 = getelementptr inbounds double, double* %3, i64 %57
%61 = bitcast double* %60 to <2 x double>*
%62 = load <2 x double>, <2 x double>* %61
%63 = shl nuw nsw i64 %57, 1
%64 = add nsw i64 %57, %11
%65 = getelementptr inbounds double, double* %3, i64 %64
%66 = bitcast double* %65 to <2 x double>*
%67 = load <2 x double>, <2 x double>* %66
%68 = or i64 %63, 1
%69 = getelementptr inbounds double, double* %6, i64 -1
%70 = getelementptr inbounds double, double* %69, i64 %68
%71 = bitcast double* %70 to <4 x double>*
%72 = shufflevector <2 x double> %62, <2 x double> %67, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
store <4 x double> %72, <4 x double>* %71
br label %73
73: ; preds = %56, %59
%74 = icmp eq i64 %15, %12
br i1 %74, label %77, label %75
75: ; preds = %10, %73
%76 = phi i64 [ 0, %10 ], [ %15, %73 ]
br label %82
77: ; preds = %82, %73, %2
%78 = icmp sgt i32 %1, 0
br i1 %78, label %79, label %95
79: ; preds = %77
%80 = zext i32 %1 to i64
%81 = shl nuw nsw i64 %80, 3
br label %95
82: ; preds = %75, %82
%83 = phi i64 [ %93, %82 ], [ %76, %75 ]
%84 = getelementptr inbounds double, double* %3, i64 %83
%85 = load double, double* %84
%86 = shl nuw nsw i64 %83, 1
%87 = getelementptr inbounds double, double* %6, i64 %86
store double %85, double* %87
%88 = add nsw i64 %83, %11
%89 = getelementptr inbounds double, double* %3, i64 %88
%90 = load double, double* %89
%91 = or i64 %86, 1
%92 = getelementptr inbounds double, double* %6, i64 %91
store double %90, double* %92
%93 = add nuw nsw i64 %83, 1
%94 = icmp eq i64 %93, %12
br i1 %94, label %77, label %82
95: ; preds = %79, %77
%96 = tail call i32 @free(double* %6)
ret double* %3
}