#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 sqrt(double);
void sqrt_rev(int n, double *sdev) {
  int i;
  double tmp;
  for (i = 0; i < n / 2; i++) {
    tmp = sqrt(sdev[i]);
    sdev[i] = sqrt(sdev[n - i - 1]);
    sdev[n - i - 1] = tmp;
  }
  if (n % 2 == 1)
    sdev[n / 2] = sqrt(sdev[n / 2]);
  return;
}


x86 assembly (clang, -O0):
<sqrt_rev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11aa <sqrt_rev+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sqrt@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <sqrt_rev+0x16>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1205 <sqrt_rev+0xf5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sqrt@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt_rev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
mov    %eax,%r12d
sar    %r12d
and    $0xfffffffe,%eax
mov    %edi,%ebx
sub    %eax,%ebx
cmp    $0x2,%edi
jl     12df <sqrt_rev+0x1cf>
mov    %ebx,0x10(%rsp)
mov    %r12d,0x14(%rsp)
mov    %r12d,%r13d
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
mov    %rdi,0x20(%rsp)
mov    %r13,0x18(%rsp)
jne    1199 <sqrt_rev+0x89>
xor    %ebp,%ebp
testb  $0x1,0x18(%rsp)
mov    0x14(%rsp),%r12d
mov    0x10(%rsp),%ebx
mov    0x20(%rsp),%r15
je     12df <sqrt_rev+0x1cf>
movsd  (%r14,%rbp,8),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     1299 <sqrt_rev+0x189>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    12a6 <sqrt_rev+0x196>
and    $0xfffffffe,%r13d
lea    -0x2(%rdi),%r15d
xor    %ebp,%ebp
xorpd  %xmm1,%xmm1
jmp    11df <sqrt_rev+0xcf>
nopl   0x0(%rax)
movsd  %xmm2,0x8(%rsp)
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%r14,%rbp,8)
movsd  %xmm2,(%r14,%rbx,8)
add    $0x2,%rbp
add    $0xfffffffe,%r15d
cmp    %rbp,%r13
je     1160 <sqrt_rev+0x50>
movsd  (%r14,%rbp,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1200 <sqrt_rev+0xf0>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    120d <sqrt_rev+0xfd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1030 <sqrt@plt>
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
lea    0x1(%r15),%eax
movslq %eax,%r12
movsd  (%r14,%r12,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1230 <sqrt_rev+0x120>
sqrtsd %xmm0,%xmm0
jmp    1245 <sqrt_rev+0x135>
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%r14,%rbp,8)
movsd  %xmm2,(%r14,%r12,8)
movsd  0x8(%r14,%rbp,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1270 <sqrt_rev+0x160>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    127d <sqrt_rev+0x16d>
nopw   0x0(%rax,%rax,1)
call   1030 <sqrt@plt>
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
movslq %r15d,%rbx
movsd  (%r14,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11b0 <sqrt_rev+0xa0>
sqrtsd %xmm0,%xmm0
jmp    11c5 <sqrt_rev+0xb5>
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm1
mov    %ebp,%eax
not    %eax
add    %r15d,%eax
movslq %eax,%r15
movsd  (%r14,%r15,8),%xmm0
ucomisd %xmm2,%xmm0
jb     12c2 <sqrt_rev+0x1b2>
sqrtsd %xmm0,%xmm0
jmp    12d3 <sqrt_rev+0x1c3>
movsd  %xmm1,0x8(%rsp)
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,(%r14,%rbp,8)
movsd  %xmm1,(%r14,%r15,8)
cmp    $0x1,%ebx
jne    1308 <sqrt_rev+0x1f8>
movslq %r12d,%rbx
movsd  (%r14,%rbx,8),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12fd <sqrt_rev+0x1ed>
sqrtsd %xmm0,%xmm0
jmp    1302 <sqrt_rev+0x1f2>
call   1030 <sqrt@plt>
movsd  %xmm0,(%r14,%rbx,8)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sqrt_rev(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
store i32 %0, i32* %3
store double* %1, double** %4
store i32 0, i32* %5
br label %7
7: ; preds = %40, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %3
%10 = sdiv i32 %9, 2
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %43
12: ; preds = %7
%13 = load double*, double** %4
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = call double @sqrt(double %17)
store double %18, double* %6
%19 = load double*, double** %4
%20 = load i32, i32* %3
%21 = load i32, i32* %5
%22 = sub nsw i32 %20, %21
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %19, i64 %24
%26 = load double, double* %25
%27 = call double @sqrt(double %26)
%28 = load double*, double** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
store double %27, double* %31
%32 = load double, double* %6
%33 = load double*, double** %4
%34 = load i32, i32* %3
%35 = load i32, i32* %5
%36 = sub nsw i32 %34, %35
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %33, i64 %38
store double %32, double* %39
br label %40
40: ; preds = %12
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %7
43: ; preds = %7
%44 = load i32, i32* %3
%45 = srem i32 %44, 2
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %60
47: ; preds = %43
%48 = load double*, double** %4
%49 = load i32, i32* %3
%50 = sdiv i32 %49, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %48, i64 %51
%53 = load double, double* %52
%54 = call double @sqrt(double %53)
%55 = load double*, double** %4
%56 = load i32, i32* %3
%57 = sdiv i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %55, i64 %58
store double %54, double* %59
br label %60
60: ; preds = %47, %43
ret void
}

LLVM IR (-O2):
define void @sqrt_rev(i32 %0, double* nocapture %1) {
%3 = sdiv i32 %0, 2
%4 = srem i32 %0, 2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %54
6: ; preds = %2
%7 = zext i32 %3 to i64
%8 = and i64 %7, 1
%9 = and i32 %0, -2
%10 = icmp eq i32 %9, 2
br i1 %10, label %40, label %11
11: ; preds = %6
%12 = and i64 %7, 4294967294
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ 0, %11 ], [ %37, %13 ]
%15 = phi i64 [ 0, %11 ], [ %38, %13 ]
%16 = getelementptr inbounds double, double* %1, i64 %14
%17 = load double, double* %16
%18 = tail call double @sqrt(double %17)
%19 = trunc i64 %14 to i32
%20 = xor i32 %19, -1
%21 = add i32 %20, %0
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %1, i64 %22
%24 = load double, double* %23
%25 = tail call double @sqrt(double %24)
store double %25, double* %16
store double %18, double* %23
%26 = or i64 %14, 1
%27 = getelementptr inbounds double, double* %1, i64 %26
%28 = load double, double* %27
%29 = tail call double @sqrt(double %28)
%30 = trunc i64 %26 to i32
%31 = xor i32 %30, -1
%32 = add i32 %31, %0
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %1, i64 %33
%35 = load double, double* %34
%36 = tail call double @sqrt(double %35)
store double %36, double* %27
store double %29, double* %34
%37 = add nuw nsw i64 %14, 2
%38 = add i64 %15, 2
%39 = icmp eq i64 %38, %12
br i1 %39, label %40, label %13
40: ; preds = %13, %6
%41 = phi i64 [ 0, %6 ], [ %37, %13 ]
%42 = icmp eq i64 %8, 0
br i1 %42, label %54, label %43
43: ; preds = %40
%44 = getelementptr inbounds double, double* %1, i64 %41
%45 = load double, double* %44
%46 = tail call double @sqrt(double %45)
%47 = trunc i64 %41 to i32
%48 = xor i32 %47, -1
%49 = add i32 %48, %0
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %1, i64 %50
%52 = load double, double* %51
%53 = tail call double @sqrt(double %52)
store double %53, double* %44
store double %46, double* %51
br label %54
54: ; preds = %43, %40, %2
%55 = icmp eq i32 %4, 1
br i1 %55, label %56, label %61
56: ; preds = %54
%57 = sext i32 %3 to i64
%58 = getelementptr inbounds double, double* %1, i64 %57
%59 = load double, double* %58
%60 = tail call double @sqrt(double %59)
store double %60, double* %58
br label %61
61: ; preds = %56, %54
ret void
}