#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*/ printf(char *, double, double, double);
int /*<<< orphan*/ vec_normalize(double *, double *);
void test_in_place_normalize() {
  double vec1[3] = {1, 1, 1};
  double result[3] = {0.0};
  vec_normalize(vec1, result);
  printf("normalize(vec1) -> result == {%f, %f, %f}\n", result[0], result[1],
         result[2]);
  vec_normalize(vec1, vec1);
  printf("normalize(vec1) -> vec1 == {%f, %f, %f}\n", vec1[0], vec1[1],
         vec1[2]);
}


x86 assembly (clang, -O0):
<test_in_place_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <vec_normalize@plt>
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <vec_normalize@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_in_place_normalize>:
push   %rbx
sub    $0x40,%rsp
mov    0xee4(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x20(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <vec_normalize@plt>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <vec_normalize@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
movsd  0x30(%rsp),%xmm2
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_in_place_normalize.vec1 = [3 x double] [double 1.000000e+00, double 1.000000e+00, double 1.000000e+00]
@.str = [43 x i8] c"normalize(vec1) -> result == {%f, %f, %f}\0A\00"
@.str.1 = [41 x i8] c"normalize(vec1) -> vec1 == {%f, %f, %f}\0A\00"
define void @test_in_place_normalize() {
%1 = alloca [3 x double]
%2 = alloca [3 x double]
%3 = bitcast [3 x double]* %1 to i8*
%4 = bitcast [3 x double]* %2 to i8*
%5 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%6 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%7 = call i32 @vec_normalize(double* %5, double* %6)
%8 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%9 = load double, double* %8
%10 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 1
%11 = load double, double* %10
%12 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 2
%13 = load double, double* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %9, double %11, double %13)
%15 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%16 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%17 = call i32 @vec_normalize(double* %15, double* %16)
%18 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%19 = load double, double* %18
%20 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 1
%21 = load double, double* %20
%22 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 2
%23 = load double, double* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double %19, double %21, double %23)
ret void
}

LLVM IR (-O2):
@__const.test_in_place_normalize.vec1 = [3 x double] [double 1.000000e+00, double 1.000000e+00, double 1.000000e+00]
@.str = [43 x i8] c"normalize(vec1) -> result == {%f, %f, %f}\0A\00"
@.str.1 = [41 x i8] c"normalize(vec1) -> vec1 == {%f, %f, %f}\0A\00"
define void @test_in_place_normalize() {
%1 = alloca [3 x double]
%2 = alloca [3 x double]
%3 = bitcast [3 x double]* %1 to i8*
%4 = bitcast [3 x double]* %2 to i8*
%5 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%6 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%7 = call i32 @vec_normalize(double* %5, double* %6)
%8 = load double, double* %6
%9 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 1
%10 = load double, double* %9
%11 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 2
%12 = load double, double* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %8, double %10, double %12)
%14 = call i32 @vec_normalize(double* %5, double* %5)
%15 = load double, double* %5
%16 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 1
%17 = load double, double* %16
%18 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 2
%19 = load double, double* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double %15, double %17, double %19)
ret void
}