#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 RKMath_Abs(float *, int const);
int /*<<< orphan*/ RKMath_Equal(float *, float *, int const);
int /*<<< orphan*/ RKMath_Mul(float *, float *, float *, int const);
int /*<<< orphan*/ RKMath_Set_Vec_Equal_To_A_Const(float *, float, int const);
void RKMath_Norm(float outvec[], float vec[], const int size) {
  float One_Div_By_ABS_Vec[size];
  const float abs = RKMath_Abs(vec, size);
  if (abs != 0) {
    RKMath_Set_Vec_Equal_To_A_Const(One_Div_By_ABS_Vec, 1.0f / abs, size);
    RKMath_Mul(outvec, vec, One_Div_By_ABS_Vec, size);
  } else {
    RKMath_Equal(outvec, vec, size);
  }
}


x86 assembly (clang, -O0):
<RKMath_Norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <RKMath_Abs@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11a7 <RKMath_Norm+0x67>
jp     11a7 <RKMath_Norm+0x67>
jmp    11d9 <RKMath_Norm+0x99>
mov    -0x38(%rbp),%rdi
movss  0xe4d(%rip),%xmm0
divss  -0x2c(%rbp),%xmm0
mov    -0x14(%rbp),%esi
call   1060 <RKMath_Set_Vec_Equal_To_A_Const@plt>
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
call   1040 <RKMath_Mul@plt>
jmp    11e9 <RKMath_Norm+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <RKMath_Equal@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RKMath_Norm>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsi,%rdi
mov    %edx,%esi
call   1030 <RKMath_Abs@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    117f <RKMath_Norm+0x3f>
jnp    11b7 <RKMath_Norm+0x77>
movss  0xe79(%rip),%xmm1
divss  %xmm0,%xmm1
mov    %rbx,%rdi
movaps %xmm1,%xmm0
mov    %r12d,%esi
call   1060 <RKMath_Set_Vec_Equal_To_A_Const@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
call   1040 <RKMath_Mul@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <RKMath_Equal@plt>

LLVM IR (-O0):
define void @RKMath_Norm(float* %0, float* %1, i32 %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca float
store float* %0, float** %4
store float* %1, float** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca float, i64 %11
store i64 %11, i64* %8
%14 = load float*, float** %5
%15 = load i32, i32* %6
%16 = call float @RKMath_Abs(float* %14, i32 %15)
store float %16, float* %9
%17 = load float, float* %9
%18 = fcmp une float %17, 0.000000e+00
br i1 %18, label %19, label %28
19: ; preds = %3
%20 = load float, float* %9
%21 = fdiv float 1.000000e+00, %20
%22 = load i32, i32* %6
%23 = call i32 @RKMath_Set_Vec_Equal_To_A_Const(float* %13, float %21, i32 %22)
%24 = load float*, float** %4
%25 = load float*, float** %5
%26 = load i32, i32* %6
%27 = call i32 @RKMath_Mul(float* %24, float* %25, float* %13, i32 %26)
br label %33
28: ; preds = %3
%29 = load float*, float** %4
%30 = load float*, float** %5
%31 = load i32, i32* %6
%32 = call i32 @RKMath_Equal(float* %29, float* %30, i32 %31)
br label %33
33: ; preds = %28, %19
%34 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
define void @RKMath_Norm(float* %0, float* %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca float, i64 %4
%6 = tail call float @RKMath_Abs(float* %1, i32 %2)
%7 = fcmp une float %6, 0.000000e+00
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = fdiv float 1.000000e+00, %6
%10 = call i32 @RKMath_Set_Vec_Equal_To_A_Const(float* %5, float %9, i32 %2)
%11 = call i32 @RKMath_Mul(float* %0, float* %1, float* %5, i32 %2)
br label %14
12: ; preds = %3
%13 = tail call i32 @RKMath_Equal(float* %0, float* %1, i32 %2)
br label %14
14: ; preds = %12, %8
ret void
}