#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*/ fatalx(char *, double);
double sqrt(double);
void vsqrt(double *a, double *b, int n) {
  int i;
  for (i = 0; i < n; i++) {
    if (b[i] < 0.0)
      fatalx("(vsqrt): negative value %g\n", b[i]);
    if (b[i] == 0.0) {
      a[i] = 0.0;
      continue;
    }
    a[i] = sqrt(b[i]);
  }
}


x86 assembly (clang, -O0):
<vsqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d7 <vsqrt+0xb7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    1175 <vsqrt+0x55>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe90(%rip),%rdi
call   1030 <fatalx@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11aa <vsqrt+0x8a>
jp     11aa <vsqrt+0x8a>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11c9 <vsqrt+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sqrt@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <vsqrt+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vsqrt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    11aa <vsqrt+0x8a>
mov    %rsi,%r13
mov    %rdi,%r14
mov    %edx,%r12d
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
lea    0xebd(%rip),%r15
jmp    116f <vsqrt+0x4f>
call   1040 <sqrt@plt>
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11aa <vsqrt+0x8a>
movsd  0x0(%r13,%rbx,8),%xmm0
ucomisd %xmm0,%xmm2
jbe    118f <vsqrt+0x6f>
mov    %r15,%rdi
call   1030 <fatalx@plt>
xorpd  %xmm2,%xmm2
movsd  0x0(%r13,%rbx,8),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119b <vsqrt+0x7b>
jnp    1160 <vsqrt+0x40>
ucomisd %xmm2,%xmm0
jb     1145 <vsqrt+0x25>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1160 <vsqrt+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"(vsqrt): negative value %g\0A\00"
define void @vsqrt(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %49, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %52
12: ; preds = %8
%13 = load double*, double** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load double*, double** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = call i32 @fatalx(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %24)
br label %26
26: ; preds = %19, %12
%27 = load double*, double** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fcmp oeq double %31, 0.000000e+00
br i1 %32, label %33, label %38
33: ; preds = %26
%34 = load double*, double** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double 0.000000e+00, double* %37
br label %49
38: ; preds = %26
%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 = call double @sqrt(double %43)
%45 = load double*, double** %4
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
store double %44, double* %48
br label %49
49: ; preds = %38, %33
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %8
52: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"(vsqrt): negative value %g\0A\00"
define void @vsqrt(double* nocapture writeonly %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %25
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %20
%8 = phi i64 [ 0, %5 ], [ %23, %20 ]
%9 = getelementptr inbounds double, double* %1, i64 %8
%10 = load double, double* %9
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 @fatalx(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %10)
%14 = load double, double* %9
br label %15
15: ; preds = %12, %7
%16 = phi double [ %14, %12 ], [ %10, %7 ]
%17 = fcmp oeq double %16, 0.000000e+00
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call double @sqrt(double %16)
br label %20
20: ; preds = %15, %18
%21 = phi double [ %19, %18 ], [ 0.000000e+00, %15 ]
%22 = getelementptr inbounds double, double* %0, i64 %8
store double %21, double* %22
%23 = add nuw nsw i64 %8, 1
%24 = icmp eq i64 %23, %6
br i1 %24, label %25, label %7
25: ; preds = %20, %3
ret void
}