#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 sqrt(float);
void GradientModulus2D(float *gradient_modulus, float *derivative_along_X,
                       float *derivative_along_Y, int length) {
  register int i;
  register float *norm = gradient_modulus;
  register float *gx = derivative_along_X;
  register float *gy = derivative_along_Y;
  for (i = 0; i < length; i++, norm++, gx++, gy++)
    *norm = sqrt((*gx) * (*gx) + (*gy) * (*gy));
}


x86 assembly (clang, -O0):
<GradientModulus2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b9 <GradientModulus2D+0xa9>
mov    -0x30(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x38(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x38(%rbp),%rax
mulss  (%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
jmp    1146 <GradientModulus2D+0x36>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GradientModulus2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    1202 <GradientModulus2D+0xf2>
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    $0x1,%ecx
je     11d0 <GradientModulus2D+0xc0>
mov    %rcx,(%rsp)
mov    %rcx,%r13
and    $0xfffffffe,%r13d
xor    %r12d,%r12d
xorps  %xmm2,%xmm2
xor    %ebp,%ebp
jmp    116c <GradientModulus2D+0x5c>
nopw   0x0(%rax,%rax,1)
call   1030 <sqrt@plt>
xorps  %xmm2,%xmm2
movss  %xmm0,0x4(%r14,%r12,4)
add    $0xfffffffffffffff8,%rbp
add    $0x2,%r12
cmp    %r12d,%r13d
je     11c3 <GradientModulus2D+0xb3>
movss  (%rbx,%r12,4),%xmm0
movss  (%r15,%r12,4),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss %xmm2,%xmm0
jb     1190 <GradientModulus2D+0x80>
sqrtss %xmm0,%xmm0
jmp    1198 <GradientModulus2D+0x88>
nop
call   1030 <sqrt@plt>
xorps  %xmm2,%xmm2
movss  %xmm0,(%r14,%r12,4)
movss  0x4(%rbx,%r12,4),%xmm0
movss  0x4(%r15,%r12,4),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss %xmm2,%xmm0
jb     1150 <GradientModulus2D+0x40>
sqrtss %xmm0,%xmm0
jmp    1158 <GradientModulus2D+0x48>
sub    %rbp,%r15
sub    %rbp,%rbx
sub    %rbp,%r14
mov    (%rsp),%rcx
test   $0x1,%cl
je     1202 <GradientModulus2D+0xf2>
movss  (%rbx),%xmm0
movss  (%r15),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11f8 <GradientModulus2D+0xe8>
sqrtss %xmm0,%xmm0
jmp    11fd <GradientModulus2D+0xed>
call   1030 <sqrt@plt>
movss  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @GradientModulus2D(float* %0, float* %1, float* %2, i32 %3) {
%5 = alloca float*
%6 = alloca float*
%7 = alloca float*
%8 = alloca i32
%9 = alloca i32
%10 = alloca float*
%11 = alloca float*
%12 = alloca float*
store float* %0, float** %5
store float* %1, float** %6
store float* %2, float** %7
store i32 %3, i32* %8
%13 = load float*, float** %5
store float* %13, float** %10
%14 = load float*, float** %6
store float* %14, float** %11
%15 = load float*, float** %7
store float* %15, float** %12
store i32 0, i32* %9
br label %16
16: ; preds = %33, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %42
20: ; preds = %16
%21 = load float*, float** %11
%22 = load float, float* %21
%23 = load float*, float** %11
%24 = load float, float* %23
%25 = load float*, float** %12
%26 = load float, float* %25
%27 = load float*, float** %12
%28 = load float, float* %27
%29 = fmul float %26, %28
%30 = call float @llvm.fmuladd.f32(float %22, float %24, float %29)
%31 = call float @sqrt(float %30)
%32 = load float*, float** %10
store float %31, float* %32
br label %33
33: ; preds = %20
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
%36 = load float*, float** %10
%37 = getelementptr inbounds float, float* %36, i32 1
store float* %37, float** %10
%38 = load float*, float** %11
%39 = getelementptr inbounds float, float* %38, i32 1
store float* %39, float** %11
%40 = load float*, float** %12
%41 = getelementptr inbounds float, float* %40, i32 1
store float* %41, float** %12
br label %16
42: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @GradientModulus2D(float* nocapture writeonly %0, float* nocapture %1, float* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %45
6: ; preds = %4
%7 = and i32 %3, 1
%8 = icmp eq i32 %3, 1
br i1 %8, label %34, label %9
9: ; preds = %6
%10 = and i32 %3, -2
br label %11
11: ; preds = %11, %9
%12 = phi float* [ %2, %9 ], [ %31, %11 ]
%13 = phi float* [ %1, %9 ], [ %30, %11 ]
%14 = phi float* [ %0, %9 ], [ %29, %11 ]
%15 = phi i32 [ 0, %9 ], [ %32, %11 ]
%16 = load float, float* %13
%17 = load float, float* %12
%18 = fmul float %17, %17
%19 = tail call float @llvm.fmuladd.f32(float %16, float %16, float %18)
%20 = tail call float @sqrt(float %19)
store float %20, float* %14
%21 = getelementptr inbounds float, float* %14, i64 1
%22 = getelementptr inbounds float, float* %13, i64 1
%23 = getelementptr inbounds float, float* %12, i64 1
%24 = load float, float* %22
%25 = load float, float* %23
%26 = fmul float %25, %25
%27 = tail call float @llvm.fmuladd.f32(float %24, float %24, float %26)
%28 = tail call float @sqrt(float %27)
store float %28, float* %21
%29 = getelementptr inbounds float, float* %14, i64 2
%30 = getelementptr inbounds float, float* %13, i64 2
%31 = getelementptr inbounds float, float* %12, i64 2
%32 = add i32 %15, 2
%33 = icmp eq i32 %32, %10
br i1 %33, label %34, label %11
34: ; preds = %11, %6
%35 = phi float* [ %2, %6 ], [ %31, %11 ]
%36 = phi float* [ %1, %6 ], [ %30, %11 ]
%37 = phi float* [ %0, %6 ], [ %29, %11 ]
%38 = icmp eq i32 %7, 0
br i1 %38, label %45, label %39
39: ; preds = %34
%40 = load float, float* %36
%41 = load float, float* %35
%42 = fmul float %41, %41
%43 = tail call float @llvm.fmuladd.f32(float %40, float %40, float %42)
%44 = tail call float @sqrt(float %43)
store float %44, float* %37
br label %45
45: ; preds = %39, %34, %4
ret void
}