// File: A-deLuna[P]encora-cpp-test/main.cpp
// Function: testFindSum()
void testFindSum() {
  struct TestCase {
    uint32_t T;
    std::vector<uint32_t> I;
    bool emptySet;
    uint32_t S;
  };

  std::vector<uint32_t> thousandOnes(1000, 1);
  std::vector<TestCase> cases = {
      {.T = 11, .I = {1, 2, 3, 4, 5, 6, 7}, .emptySet = false, .S = 11},
      {.T = 7, .I = {2, 9, 1, 5}, .emptySet = false, .S = 7},
      {.T = 5, .I = {10, 20}, .emptySet = true, .S = 0},
      {.T = 40, .I = {10, 20}, .emptySet = false, .S = 30},
      {.T = 10,
       .I = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
       .emptySet = false,
       .S = 10},
      {.T = 0, .I = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, .emptySet = true, .S = 0},
      {.T = 10, .I = {}, .emptySet = true, .S = 0},
      {.T = 10, .I = {0, 0, 0}, .emptySet = true, .S = 0},
      {.T = 1000, .I = std::move(thousandOnes), .emptySet = false, .S = 1000},
  };
  int failedCases = 0;

  std::vector<uint32_t> M;
  uint32_t S;
  for (size_t i = 0; i < cases.size(); i++) {
    const TestCase& c = cases[i];
    find_largest_sum(c.T, c.I, M, S);

    if (S != c.S) {
      std::cout << "Error in case " << i << " expected S to be " << c.S << "\n";
      std::cout << "but got " << S << "\n";
      failedCases++;
      continue;
    }
    uint32_t sum = 0;
    for (auto i : M)
      sum += i;

    if (sum != c.S) {
      std::cout << "Error in case " << i << " expected M sum to be " << c.S
                << "\n";
      std::cout << "but got " << sum << "\n";
      failedCases++;
      continue;
    }

    if (M.empty() && !c.emptySet) {
      std::cout << "Error in case " << i
                << " M is empty but was not expected\n";
      failedCases++;
      continue;
    }
    if (!M.empty() && c.emptySet) {
      std::cout << "Error in case " << i
                << " M is not empty but was expected to be\n";
      failedCases++;
      continue;
    }
  }
  if (failedCases == 0) {
    std::cout << "find_largest_sum: All cases succeeded\n";
  } else {
    std::cout << "find_largest_sum: failed a total of " << failedCases
              << " cases\n";
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movl $0x1, -0x1c(%rbp)
leaq -0x1d(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x6630
movq -0x380(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
leaq -0x1c(%rbp), %rdx
callq 0x6650
jmp 0x4fcd
leaq -0x1d(%rbp), %rdi
callq 0x66d0
movb $0x1, -0x316(%rbp)
leaq -0x1c0(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movl $0xb, -0x1c0(%rbp)
leaq -0x1b8(%rbp), %rax
movq %rax, -0x390(%rbp)
movups 0x3112(%rip), %xmm0     # 0x811c
movups %xmm0, -0x1f4(%rbp)
movups 0x30f8(%rip), %xmm0     # 0x8110
movaps %xmm0, -0x200(%rbp)
leaq -0x200(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq $0x7, -0x1d0(%rbp)
leaq -0x201(%rbp), %rdi
movq %rdi, -0x388(%rbp)
callq 0x6630
movq -0x390(%rbp), %rdi
movq -0x388(%rbp), %rcx
movq -0x1d8(%rbp), %rsi
movq -0x1d0(%rbp), %rdx
callq 0x66f0
jmp 0x506e
movb $0x0, -0x1a0(%rbp)
movl $0xb, -0x19c(%rbp)
leaq -0x198(%rbp), %rax
movq %rax, -0x3a8(%rbp)
movq %rax, -0x1c8(%rbp)
movl $0x7, -0x198(%rbp)
leaq -0x190(%rbp), %rax
movq %rax, -0x3a0(%rbp)
movl $0x2, -0x228(%rbp)
movl $0x9, -0x224(%rbp)
movl $0x1, -0x220(%rbp)
movl $0x5, -0x21c(%rbp)
leaq -0x228(%rbp), %rax
movq %rax, -0x218(%rbp)
movq $0x4, -0x210(%rbp)
leaq -0x229(%rbp), %rdi
movq %rdi, -0x398(%rbp)
callq 0x6630
movq -0x3a0(%rbp), %rdi
movq -0x398(%rbp), %rcx
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
callq 0x66f0
jmp 0x5123
movq -0x3a8(%rbp), %rax
movb $0x0, 0x20(%rax)
movl $0x7, 0x24(%rax)
leaq -0x170(%rbp), %rax
movq %rax, -0x3c0(%rbp)
movq %rax, -0x1c8(%rbp)
movl $0x5, -0x170(%rbp)
leaq -0x168(%rbp), %rax
movq %rax, -0x3b8(%rbp)
movl $0xa, -0x248(%rbp)
movl $0x14, -0x244(%rbp)
leaq -0x248(%rbp), %rax
movq %rax, -0x240(%rbp)
movq $0x2, -0x238(%rbp)
leaq -0x249(%rbp), %rdi
movq %rdi, -0x3b0(%rbp)
callq 0x6630
movq -0x3b8(%rbp), %rdi
movq -0x3b0(%rbp), %rcx
movq -0x240(%rbp), %rsi
movq -0x238(%rbp), %rdx
callq 0x66f0
jmp 0x51c5
movq -0x3c0(%rbp), %rax
movb $0x1, 0x20(%rax)
movl $0x0, 0x24(%rax)
leaq -0x148(%rbp), %rax
movq %rax, -0x3d8(%rbp)
movq %rax, -0x1c8(%rbp)
movl $0x28, -0x148(%rbp)
leaq -0x140(%rbp), %rax
movq %rax, -0x3d0(%rbp)
movl $0xa, -0x268(%rbp)
movl $0x14, -0x264(%rbp)
leaq -0x268(%rbp), %rax
movq %rax, -0x260(%rbp)
movq $0x2, -0x258(%rbp)
leaq -0x269(%rbp), %rdi
movq %rdi, -0x3c8(%rbp)
callq 0x6630
movq -0x3d0(%rbp), %rdi
movq -0x3c8(%rbp), %rcx
movq -0x260(%rbp), %rsi
movq -0x258(%rbp), %rdx
callq 0x66f0
jmp 0x5267
movq -0x3d8(%rbp), %rax
movb $0x0, 0x20(%rax)
movl $0x1e, 0x24(%rax)
leaq -0x120(%rbp), %rax
movq %rax, -0x3f0(%rbp)
movq %rax, -0x1c8(%rbp)
movl $0xa, -0x120(%rbp)
leaq -0x118(%rbp), %rax
movq %rax, -0x3e8(%rbp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, -0x290(%rbp)
movups 0x2e7e(%rip), %xmm0     # 0x813c
movaps %xmm0, -0x2a0(%rbp)
movups 0x2e60(%rip), %xmm0     # 0x812c
movaps %xmm0, -0x2b0(%rbp)
leaq -0x2b0(%rbp), %rax
movq %rax, -0x280(%rbp)
movq $0xa, -0x278(%rbp)
leaq -0x2b1(%rbp), %rdi
movq %rdi, -0x3e0(%rbp)
callq 0x6630
movq -0x3e8(%rbp), %rdi
movq -0x3e0(%rbp), %rcx
movq -0x280(%rbp), %rsi
movq -0x278(%rbp), %rdx
callq 0x66f0
jmp 0x5322
movq -0x3f0(%rbp), %rax
movb $0x0, 0x20(%rax)
movl $0xa, 0x24(%rax)
leaq -0xf8(%rbp), %rax
movq %rax, -0x408(%rbp)
movq %rax, -0x1c8(%rbp)
movl $0x0, -0xf8(%rbp)
leaq -0xf0(%rbp), %rax
movq %rax, -0x400(%rbp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, -0x2d0(%rbp)
movups 0x2deb(%rip), %xmm0     # 0x8164
movaps %xmm0, -0x2e0(%rbp)
movups 0x2dcd(%rip), %xmm0     # 0x8154
movaps %xmm0, -0x2f0(%rbp)
leaq -0x2f0(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movq $0xa, -0x2c0(%rbp)
leaq -0x2f1(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x6630
movq -0x400(%rbp), %rdi
movq -0x3f8(%rbp), %rcx
movq -0x2c8(%rbp), %rsi
movq -0x2c0(%rbp), %rdx
callq 0x66f0
jmp 0x53dd
movq -0x408(%rbp), %rax
movb $0x1, 0x20(%rax)
movl $0x0, 0x24(%rax)
leaq -0xd0(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movl $0xa, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, -0xc8(%rbp)
movq $0x0, -0xb8(%rbp)
callq 0x6770
movb $0x1, -0xb0(%rbp)
movl $0x0, -0xac(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x420(%rbp)
movq %rax, -0x1c8(%rbp)
movl $0xa, -0xa8(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x418(%rbp)
movl $0x0, -0x314(%rbp)
movl $0x0, -0x310(%rbp)
movl $0x0, -0x30c(%rbp)
leaq -0x314(%rbp), %rax
movq %rax, -0x308(%rbp)
movq $0x3, -0x300(%rbp)
leaq -0x315(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x6630
movq -0x418(%rbp), %rdi
movq -0x410(%rbp), %rcx
movq -0x308(%rbp), %rsi
movq -0x300(%rbp), %rdx
callq 0x66f0
jmp 0x54d3
movq -0x420(%rbp), %rax
movb $0x1, 0x20(%rax)
movl $0x0, 0x24(%rax)
leaq -0x80(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movl $0x3e8, -0x80(%rbp)     # imm = 0x3E8
leaq -0x78(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x6790
movb $0x0, -0x60(%rbp)
movl $0x3e8, -0x5c(%rbp)     # imm = 0x3E8
movb $0x0, -0x316(%rbp)
leaq -0x1c0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x9, -0x50(%rbp)
leaq -0x317(%rbp), %rdi
movq %rdi, -0x428(%rbp)
callq 0x5c90
movq -0x428(%rbp), %rcx
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x5cb0
jmp 0x5556
leaq -0x317(%rbp), %rdi
callq 0x5d30
leaq -0x1c0(%rbp), %rax
movq %rax, -0x438(%rbp)
addq $0x168, %rax            # imm = 0x168
movq %rax, -0x430(%rbp)
movq -0x430(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x440(%rbp)
callq 0x5d50
movq -0x438(%rbp), %rcx
movq -0x440(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x430(%rbp)
jne 0x557d
leaq -0x315(%rbp), %rdi
callq 0x66d0
leaq -0x2f1(%rbp), %rdi
callq 0x66d0
leaq -0x2b1(%rbp), %rdi
callq 0x66d0
leaq -0x269(%rbp), %rdi
callq 0x66d0
leaq -0x249(%rbp), %rdi
callq 0x66d0
leaq -0x229(%rbp), %rdi
callq 0x66d0
leaq -0x201(%rbp), %rdi
callq 0x66d0
movl $0x0, -0x31c(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x6770
movq $0x0, -0x348(%rbp)
movq -0x348(%rbp), %rax
movq %rax, -0x448(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5d70
movq %rax, %rcx
movq -0x448(%rbp), %rax
cmpq %rcx, %rax
jae 0x5be9
movq -0x348(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x5da0
movq %rax, -0x350(%rbp)
movq -0x350(%rbp), %rsi
movl (%rsi), %edi
addq $0x8, %rsi
leaq -0x338(%rbp), %rdx
leaq -0x33c(%rbp), %rcx
callq 0x24a0
jmp 0x5686
movl -0x33c(%rbp), %eax
movq -0x350(%rbp), %rcx
cmpl 0x24(%rcx), %eax
je 0x594f
movq 0x7935(%rip), %rdi      # 0xcfd8
leaq 0x2bb2(%rip), %rsi      # 0x825c
callq 0x20f0
movq %rax, -0x450(%rbp)
jmp 0x56b8
movq -0x450(%rbp), %rdi
movq -0x348(%rbp), %rsi
callq 0x2040
movq %rax, -0x458(%rbp)
jmp 0x56d4
movq -0x458(%rbp), %rdi
leaq 0x2b89(%rip), %rsi      # 0x826b
callq 0x20f0
movq %rax, -0x460(%rbp)
jmp 0x56f0
movq -0x460(%rbp), %rdi
movq -0x350(%rbp), %rax
movl 0x24(%rax), %esi
callq 0x2120
movq %rax, -0x468(%rbp)
jmp 0x570f
movq -0x468(%rbp), %rdi
leaq 0x2aa3(%rip), %rsi      # 0x81c0
callq 0x20f0
jmp 0x5724
movq 0x78ad(%rip), %rdi      # 0xcfd8
leaq 0x2b4c(%rip), %rsi      # 0x827e
callq 0x20f0
movq %rax, -0x470(%rbp)
jmp 0x5740
movq -0x470(%rbp), %rdi
movl -0x33c(%rbp), %esi
callq 0x2120
movq %rax, -0x478(%rbp)
jmp 0x575b
movq -0x478(%rbp), %rdi
leaq 0x2a57(%rip), %rsi      # 0x81c0
callq 0x20f0
jmp 0x5770
movl -0x31c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x31c(%rbp)
jmp 0x5bd2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1d(%rbp), %rdi
callq 0x66d0
jmp 0x5c87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x58c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x58b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x58a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x589c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5884
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5878
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x317(%rbp), %rdi
callq 0x5d30
leaq -0x1c0(%rbp), %rax
movq %rax, -0x488(%rbp)
addq $0x168, %rax            # imm = 0x168
movq %rax, -0x480(%rbp)
movq -0x480(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x490(%rbp)
callq 0x5d50
movq -0x488(%rbp), %rcx
movq -0x490(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x480(%rbp)
jne 0x5845
jmp 0x5878
leaq -0x315(%rbp), %rdi
callq 0x66d0
leaq -0x2f1(%rbp), %rdi
callq 0x66d0
leaq -0x2b1(%rbp), %rdi
callq 0x66d0
leaq -0x269(%rbp), %rdi
callq 0x66d0
leaq -0x249(%rbp), %rdi
callq 0x66d0
leaq -0x229(%rbp), %rdi
callq 0x66d0
leaq -0x201(%rbp), %rdi
callq 0x66d0
testb $0x1, -0x316(%rbp)
jne 0x58d7
jmp 0x5924
movq -0x1c8(%rbp), %rax
leaq -0x1c0(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x498(%rbp)
je 0x5922
movq -0x498(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x5d50
movq -0x4a0(%rbp), %rax
leaq -0x1c0(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x498(%rbp)
jne 0x58f1
jmp 0x5924
jmp 0x5c7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x6880
leaq -0x48(%rbp), %rdi
callq 0x5dc0
jmp 0x5c7e
movl $0x0, -0x354(%rbp)
leaq -0x338(%rbp), %rax
movq %rax, -0x360(%rbp)
movq -0x360(%rbp), %rdi
callq 0x47d0
movq %rax, -0x368(%rbp)
movq -0x360(%rbp), %rdi
callq 0x4660
movq %rax, -0x370(%rbp)
leaq -0x368(%rbp), %rdi
leaq -0x370(%rbp), %rsi
callq 0x67c0
testb $0x1, %al
jne 0x59a6
jmp 0x59da
leaq -0x368(%rbp), %rdi
callq 0x6800
movl (%rax), %eax
movl %eax, -0x374(%rbp)
movl -0x374(%rbp), %eax
addl -0x354(%rbp), %eax
movl %eax, -0x354(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x6820
jmp 0x598d
movl -0x354(%rbp), %eax
movq -0x350(%rbp), %rcx
cmpl 0x24(%rcx), %eax
je 0x5ad8
movq 0x75e1(%rip), %rdi      # 0xcfd8
leaq 0x285e(%rip), %rsi      # 0x825c
callq 0x20f0
movq %rax, -0x4a8(%rbp)
jmp 0x5a0c
movq -0x4a8(%rbp), %rdi
movq -0x348(%rbp), %rsi
callq 0x2040
movq %rax, -0x4b0(%rbp)
jmp 0x5a28
movq -0x4b0(%rbp), %rdi
leaq 0x2851(%rip), %rsi      # 0x8287
callq 0x20f0
movq %rax, -0x4b8(%rbp)
jmp 0x5a44
movq -0x4b8(%rbp), %rdi
movq -0x350(%rbp), %rax
movl 0x24(%rax), %esi
callq 0x2120
movq %rax, -0x4c0(%rbp)
jmp 0x5a63
movq -0x4c0(%rbp), %rdi
leaq 0x274f(%rip), %rsi      # 0x81c0
callq 0x20f0
jmp 0x5a78
movq 0x7559(%rip), %rdi      # 0xcfd8
leaq 0x27f8(%rip), %rsi      # 0x827e
callq 0x20f0
movq %rax, -0x4c8(%rbp)
jmp 0x5a94
movq -0x4c8(%rbp), %rdi
movl -0x354(%rbp), %esi
callq 0x2120
movq %rax, -0x4d0(%rbp)
jmp 0x5aaf
movq -0x4d0(%rbp), %rdi
leaq 0x2703(%rip), %rsi      # 0x81c0
callq 0x20f0
jmp 0x5ac4
movl -0x31c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x31c(%rbp)
jmp 0x5bd2
leaq -0x338(%rbp), %rdi
callq 0x6840
testb $0x1, %al
jne 0x5aea
jmp 0x5b55
movq -0x350(%rbp), %rax
testb $0x1, 0x20(%rax)
jne 0x5b55
movq 0x74da(%rip), %rdi      # 0xcfd8
leaq 0x2757(%rip), %rsi      # 0x825c
callq 0x20f0
movq %rax, -0x4d8(%rbp)
jmp 0x5b13
movq -0x4d8(%rbp), %rdi
movq -0x348(%rbp), %rsi
callq 0x2040
movq %rax, -0x4e0(%rbp)
jmp 0x5b2f
movq -0x4e0(%rbp), %rdi
leaq 0x2761(%rip), %rsi      # 0x829e
callq 0x20f0
jmp 0x5b44
movl -0x31c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x31c(%rbp)
jmp 0x5bd2
leaq -0x338(%rbp), %rdi
callq 0x6840
testb $0x1, %al
jne 0x5bd0
movq -0x350(%rbp), %rax
testb $0x1, 0x20(%rax)
je 0x5bd0
movq 0x745f(%rip), %rdi      # 0xcfd8
leaq 0x26dc(%rip), %rsi      # 0x825c
callq 0x20f0
movq %rax, -0x4e8(%rbp)
jmp 0x5b8e
movq -0x4e8(%rbp), %rdi
movq -0x348(%rbp), %rsi
callq 0x2040
movq %rax, -0x4f0(%rbp)
jmp 0x5baa
movq -0x4f0(%rbp), %rdi
leaq 0x2708(%rip), %rsi      # 0x82c0
callq 0x20f0
jmp 0x5bbf
movl -0x31c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x31c(%rbp)
jmp 0x5bd2
jmp 0x5bd2
movq -0x348(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x348(%rbp)
jmp 0x5623
cmpl $0x0, -0x31c(%rbp)
jne 0x5c09
movq 0x73df(%rip), %rdi      # 0xcfd8
leaq 0x26e8(%rip), %rsi      # 0x82e8
callq 0x20f0
jmp 0x5c07
jmp 0x5c57
movq 0x73c8(%rip), %rdi      # 0xcfd8
leaq 0x26f8(%rip), %rsi      # 0x830f
callq 0x20f0
movq %rax, -0x4f8(%rbp)
jmp 0x5c25
movq -0x4f8(%rbp), %rdi
movl -0x31c(%rbp), %esi
callq 0x2180
movq %rax, -0x500(%rbp)
jmp 0x5c40
movq -0x500(%rbp), %rdi
leaq 0x2606(%rip), %rsi      # 0x8254
callq 0x20f0
jmp 0x5c55
jmp 0x5c57
leaq -0x338(%rbp), %rdi
callq 0x6880
leaq -0x48(%rbp), %rdi
callq 0x5dc0
leaq -0x18(%rbp), %rdi
callq 0x6880
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
leaq -0x18(%rbp), %rdi
callq 0x6880
movq -0x28(%rbp), %rdi
callq 0x2190