#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 */
float sqrtf(float);
void compute_sqrt(float *in, float *out, int n) {
  for (int i = 0; i < n; i++) {
    if (in[i] > 0)
      out[i] = sqrtf(in[i]);
    else
      out[i] = 0.0;
  }
}


x86 assembly (clang, -O0):
<compute_sqrt>:
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    1196 <compute_sqrt+0x86>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1173 <compute_sqrt+0x63>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1030 <sqrtf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    1183 <compute_sqrt+0x73>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
jmp    1188 <compute_sqrt+0x78>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <compute_sqrt+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_sqrt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    11fc <compute_sqrt+0xec>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
cmp    $0x1,%edx
jne    1165 <compute_sqrt+0x55>
xor    %ebx,%ebx
test   $0x1,%r12b
je     11fc <compute_sqrt+0xec>
movss  (%r15,%rbx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11f6 <compute_sqrt+0xe6>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11ee <compute_sqrt+0xde>
xorps  %xmm1,%xmm1
sqrtss %xmm0,%xmm1
jmp    11f6 <compute_sqrt+0xe6>
mov    %r12d,%r13d
and    $0xfffffffe,%r13d
xor    %ebx,%ebx
xorps  %xmm2,%xmm2
jmp    119b <compute_sqrt+0x8b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movaps %xmm1,%xmm0
call   1030 <sqrtf@plt>
xorps  %xmm2,%xmm2
movss  %xmm0,0x4(%r14,%rbx,4)
add    $0x2,%rbx
cmp    %rbx,%r13
je     1131 <compute_sqrt+0x21>
movss  (%r15,%rbx,4),%xmm1
ucomiss %xmm2,%xmm1
xorps  %xmm0,%xmm0
jbe    11cb <compute_sqrt+0xbb>
jb     11c0 <compute_sqrt+0xb0>
xorps  %xmm0,%xmm0
sqrtss %xmm1,%xmm0
jmp    11cb <compute_sqrt+0xbb>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movaps %xmm1,%xmm0
call   1030 <sqrtf@plt>
xorps  %xmm2,%xmm2
movss  %xmm0,(%r14,%rbx,4)
movss  0x4(%r15,%rbx,4),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jbe    118b <compute_sqrt+0x7b>
ucomiss %xmm2,%xmm1
jb     1180 <compute_sqrt+0x70>
xorps  %xmm0,%xmm0
sqrtss %xmm1,%xmm0
jmp    118b <compute_sqrt+0x7b>
call   1030 <sqrtf@plt>
movaps %xmm0,%xmm1
movss  %xmm1,(%r14,%rbx,4)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @compute_sqrt(float* nocapture %0, float* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %23
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = and i64 %6, 1
%8 = icmp eq i32 %2, 1
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = and i64 %6, 4294967294
br label %24
11: ; preds = %41, %5
%12 = phi i64 [ 0, %5 ], [ %44, %41 ]
%13 = icmp eq i64 %7, 0
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = getelementptr inbounds float, float* %0, i64 %12
%16 = load float, float* %15
%17 = fcmp ogt float %16, 0.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call float @sqrtf(float %16)
br label %20
20: ; preds = %18, %14
%21 = phi float [ %19, %18 ], [ 0.000000e+00, %14 ]
%22 = getelementptr inbounds float, float* %1, i64 %12
store float %21, float* %22
br label %23
23: ; preds = %20, %11, %3
ret void
24: ; preds = %41, %9
%25 = phi i64 [ 0, %9 ], [ %44, %41 ]
%26 = phi i64 [ 0, %9 ], [ %45, %41 ]
%27 = getelementptr inbounds float, float* %0, i64 %25
%28 = load float, float* %27
%29 = fcmp ogt float %28, 0.000000e+00
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = tail call float @sqrtf(float %28)
br label %32
32: ; preds = %24, %30
%33 = phi float [ %31, %30 ], [ 0.000000e+00, %24 ]
%34 = getelementptr inbounds float, float* %1, i64 %25
store float %33, float* %34
%35 = or i64 %25, 1
%36 = getelementptr inbounds float, float* %0, i64 %35
%37 = load float, float* %36
%38 = fcmp ogt float %37, 0.000000e+00
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = tail call float @sqrtf(float %37)
br label %41
41: ; preds = %39, %32
%42 = phi float [ %40, %39 ], [ 0.000000e+00, %32 ]
%43 = getelementptr inbounds float, float* %1, i64 %35
store float %42, float* %43
%44 = add nuw nsw i64 %25, 2
%45 = add i64 %26, 2
%46 = icmp eq i64 %45, %10
br i1 %46, label %11, label %24
}