#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 sqrt(float);
void invert_sqrt_vec(int n, float *vec) {
  int i;
  double d;
  float v;
  for (i = 0; i < n; i++) {
    if ((v = vec[i]) > 0.0) {
      d = 1. / sqrt(v);
      vec[i] = (float)d;
    }
  }
}


x86 assembly (clang, -O0):
<invert_sqrt_vec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119d <invert_sqrt_vec+0x8d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x24(%rbp)
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    118a <invert_sqrt_vec+0x7a>
movss  -0x24(%rbp),%xmm0
call   1030 <sqrt@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe95(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    118f <invert_sqrt_vec+0x7f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <invert_sqrt_vec+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invert_sqrt_vec>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
jle    116e <invert_sqrt_vec+0x5e>
mov    %rsi,%r15
mov    %edi,%r14d
xor    %ebx,%ebx
xorps  %xmm1,%xmm1
jmp    1139 <invert_sqrt_vec+0x29>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     116e <invert_sqrt_vec+0x5e>
movss  (%r15,%rbx,4),%xmm0
ucomiss %xmm1,%xmm0
jbe    1130 <invert_sqrt_vec+0x20>
call   1030 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xea8(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
xorps  %xmm1,%xmm1
movss  %xmm0,(%r15,%rbx,4)
jmp    1130 <invert_sqrt_vec+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @invert_sqrt_vec(i32 %0, float* %1) {
%3 = alloca i32
%4 = alloca float*
%5 = alloca i32
%6 = alloca double
%7 = alloca float
store i32 %0, i32* %3
store float* %1, float** %4
store i32 0, i32* %5
br label %8
8: ; preds = %32, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %35
12: ; preds = %8
%13 = load float*, float** %4
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds float, float* %13, i64 %15
%17 = load float, float* %16
store float %17, float* %7
%18 = fpext float %17 to double
%19 = fcmp ogt double %18, 0.000000e+00
br i1 %19, label %20, label %31
20: ; preds = %12
%21 = load float, float* %7
%22 = call i32 @sqrt(float %21)
%23 = sitofp i32 %22 to double
%24 = fdiv double 1.000000e+00, %23
store double %24, double* %6
%25 = load double, double* %6
%26 = fptrunc double %25 to float
%27 = load float*, float** %4
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %27, i64 %29
store float %26, float* %30
br label %31
31: ; preds = %20, %12
br label %32
32: ; preds = %31
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %8
35: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @invert_sqrt_vec(i32 %0, float* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %16
%7 = phi i64 [ 0, %4 ], [ %17, %16 ]
%8 = getelementptr inbounds float, float* %1, i64 %7
%9 = load float, float* %8
%10 = fcmp ogt float %9, 0.000000e+00
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = tail call i32 @sqrt(float %9)
%13 = sitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
%15 = fptrunc double %14 to float
store float %15, float* %8
br label %16
16: ; preds = %6, %11
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %19, label %6
19: ; preds = %16, %2
ret void
}