// File: yukimasano[P]cpp_matrix/Vector.cpp
// Function: operator+(Vector const&, Vector const&)
Vector operator+(const Vector& v1, 
                        const Vector& v2)
{
  int n;

  //  set n to be the length of the longest vector and create a vector
  //  of that length to be returned
  if (v1.mSize > v2.mSize)
    {
      n = v1.mSize;
    }
  else
    {
      n = v2.mSize;
    }
  Vector w(n);


  //  add the vectors
  //  if one vector is shorter than the other assume missing entries are 0
  if (v1.mSize == v2.mSize)
  {
      for (int i=0; i<v1.mSize; i++)
	{
	  w.mData[i] = v1.mData[i] + v2.mData[i];
	}
  }
  else if (v1.mSize > v2.mSize)
  {
      for (int i=0; i<v2.mSize; i++)
	{
	  w.mData[i] = v1.mData[i] + v2.mData[i];
	}
      for (int i=v2.mSize; i<v1.mSize; i++)
	{
	  w.mData[i] = v1.mData[i];
	}
      std::cerr<<"vector add - vectors different lengths\n";
      std::cerr<<"extra entries of shorter vector assumed to be 0.0\n";
  }

  else
  {
      for (int i=0; i<v1.mSize; i++)
	{
	  w.mData[i] = v1.mData[i] + v2.mData[i];
	}
      for (int i=v1.mSize; i<v2.mSize; i++)
	{
	  w.mData[i] = v2.mData[i];
	}
      std::cerr<<"vector add - vectors different lengths\n";
      std::cerr<<"extra entries of shorter vector assumed to be 0.0\n";
  }
  return w;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, (%rsp)
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x40(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jle 0xd1df
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x3c(%rsp)
jmp 0xd1eb
movq 0x40(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x3c(%rsp)
movq (%rsp), %rdi
movb $0x0, 0x3b(%rsp)
movl 0x3c(%rsp), %esi
callq 0xd040
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x40(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jne 0xd26c
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xd267
movq (%rsp), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x34(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x34(%rsp), %rdx
addsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rax
movslq 0x34(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0xd217
jmp 0xd43f
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x40(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jle 0xd36f
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xd2da
movq (%rsp), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x30(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x30(%rsp), %rdx
addsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rax
movslq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0xd28a
movq 0x40(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xd324
movq (%rsp), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x2c(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rax
movslq 0x2c(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xd2e6
movq 0x4cc5(%rip), %rdi      # 0x11ff0
leaq 0x21ae(%rip), %rsi      # 0xf4e0
callq 0x2110
jmp 0xd339
movq 0x4cb0(%rip), %rdi      # 0x11ff0
leaq 0x21c1(%rip), %rsi      # 0xf508
callq 0x2110
jmp 0xd34e
jmp 0xd43d
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
callq 0xd170
jmp 0xd45e
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xd3c7
movq (%rsp), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x18(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x18(%rsp), %rdx
addsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rax
movslq 0x18(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0xd377
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xd411
movq (%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x14(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xd3d3
movq 0x4bd8(%rip), %rdi      # 0x11ff0
leaq 0x20c1(%rip), %rsi      # 0xf4e0
callq 0x2110
jmp 0xd426
movq 0x4bc3(%rip), %rdi      # 0x11ff0
leaq 0x20d4(%rip), %rsi      # 0xf508
callq 0x2110
jmp 0xd43b
jmp 0xd43d
jmp 0xd43f
movb $0x1, 0x3b(%rsp)
testb $0x1, 0x3b(%rsp)
jne 0xd454
movq (%rsp), %rdi
callq 0xd170
movq 0x8(%rsp), %rax
addq $0x58, %rsp
retq
movq 0x20(%rsp), %rdi
callq 0x21e0
nopl (%rax,%rax)