#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_add(double *, double *, double *);
void test_in_place_add() {
  double vec1[3] = {1, 2, 3};
  double vec2[3] = {4, 5, 6};
  double result[3] = {0.0};
  vec_add(vec1, vec2, result);
  printf("vec1 + vec2 -> result == {%f, %f, %f}\n", result[0], result[1],
         result[2]);
  vec_add(vec1, vec2, vec1);
  printf("vec1 + vec2 -> vec1 == {%f, %f, %f}\n", vec1[0], vec1[1], vec1[2]);
}


x86 assembly (clang, -O0):
<test_in_place_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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)
mov    0xec0(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xebd(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1050 <vec_add@plt>
movsd  -0x60(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <vec_add@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_in_place_add>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0xee2(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0xeea(%rip),%rax
mov    %rax,0x50(%rsp)
movaps 0xece(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x20(%rsp),%rbx
lea    0x40(%rsp),%r14
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <vec_add@plt>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <vec_add@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
movsd  0x30(%rsp),%xmm2
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.test_in_place_add.vec1 = [3 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00]
@__const.test_in_place_add.vec2 = [3 x double] [double 4.000000e+00, double 5.000000e+00, double 6.000000e+00]
@.str = [39 x i8] c"vec1 + vec2 -> result == {%f, %f, %f}\0A\00"
@.str.1 = [37 x i8] c"vec1 + vec2 -> vec1 == {%f, %f, %f}\0A\00"
define void @test_in_place_add() {
%1 = alloca [3 x double]
%2 = alloca [3 x double]
%3 = alloca [3 x double]
%4 = bitcast [3 x double]* %1 to i8*
%5 = bitcast [3 x double]* %2 to i8*
%6 = bitcast [3 x double]* %3 to i8*
%7 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%8 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%9 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%10 = call i32 @vec_add(double* %7, double* %8, double* %9)
%11 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%12 = load double, double* %11
%13 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 1
%14 = load double, double* %13
%15 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 2
%16 = load double, double* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), double %12, double %14, double %16)
%18 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%19 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%20 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%21 = call i32 @vec_add(double* %18, double* %19, double* %20)
%22 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%23 = load double, double* %22
%24 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 1
%25 = load double, double* %24
%26 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 2
%27 = load double, double* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), double %23, double %25, double %27)
ret void
}

LLVM IR (-O2):
@__const.test_in_place_add.vec1 = [3 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00]
@__const.test_in_place_add.vec2 = [3 x double] [double 4.000000e+00, double 5.000000e+00, double 6.000000e+00]
@.str = [39 x i8] c"vec1 + vec2 -> result == {%f, %f, %f}\0A\00"
@.str.1 = [37 x i8] c"vec1 + vec2 -> vec1 == {%f, %f, %f}\0A\00"
define void @test_in_place_add() {
%1 = alloca [3 x double]
%2 = alloca [3 x double]
%3 = alloca [3 x double]
%4 = bitcast [3 x double]* %1 to i8*
%5 = bitcast [3 x double]* %2 to i8*
%6 = bitcast [3 x double]* %3 to i8*
%7 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%8 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%9 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%10 = call i32 @vec_add(double* %7, double* %8, double* %9)
%11 = load double, double* %9
%12 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 1
%13 = load double, double* %12
%14 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 2
%15 = load double, double* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), double %11, double %13, double %15)
%17 = call i32 @vec_add(double* %7, double* %8, double* %7)
%18 = load double, double* %7
%19 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 1
%20 = load double, double* %19
%21 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 2
%22 = load double, double* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), double %18, double %20, double %22)
ret void
}