// File: hyrise[P]sql-parser/src/util/sqlhelper.cpp
// Function: hsql::printSelectStatementInfo(hsql::SelectStatement const*, unsigned long)
void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t num_indent) {
  inprint("SelectStatement", num_indent);
  inprint("Fields:", num_indent + 1);
  for (Expr* expr : *stmt->selectList) printExpression(expr, num_indent + 2);

  if (stmt->fromTable) {
    inprint("Sources:", num_indent + 1);
    printTableRefInfo(stmt->fromTable, num_indent + 2);
  }

  if (stmt->whereClause) {
    inprint("Search Conditions:", num_indent + 1);
    printExpression(stmt->whereClause, num_indent + 2);
  }

  if (stmt->groupBy) {
    inprint("GroupBy:", num_indent + 1);
    for (Expr* expr : *stmt->groupBy->columns) printExpression(expr, num_indent + 2);
    if (stmt->groupBy->having) {
      inprint("Having:", num_indent + 1);
      printExpression(stmt->groupBy->having, num_indent + 2);
    }
  }
  if (stmt->lockings) {
    inprint("Lock Info:", num_indent + 1);
    for (LockingClause* lockingClause : *stmt->lockings) {
      inprint("Type", num_indent + 2);
      if (lockingClause->rowLockMode == RowLockMode::ForUpdate) {
        inprint("FOR UPDATE", num_indent + 3);
      } else if (lockingClause->rowLockMode == RowLockMode::ForNoKeyUpdate) {
        inprint("FOR NO KEY UPDATE", num_indent + 3);
      } else if (lockingClause->rowLockMode == RowLockMode::ForShare) {
        inprint("FOR SHARE", num_indent + 3);
      } else if (lockingClause->rowLockMode == RowLockMode::ForKeyShare) {
        inprint("FOR KEY SHARE", num_indent + 3);
      }
      if (lockingClause->tables) {
        inprint("Target tables:", num_indent + 2);
        for (char* dtable : *lockingClause->tables) {
          inprint(dtable, num_indent + 3);
        }
      }
      if (lockingClause->rowLockWaitPolicy != RowLockWaitPolicy::None) {
        inprint("Waiting policy: ", num_indent + 2);
        if (lockingClause->rowLockWaitPolicy == RowLockWaitPolicy::NoWait)
          inprint("NOWAIT", num_indent + 3);
        else
          inprint("SKIP LOCKED", num_indent + 3);
      }
    }
  }

  if (stmt->setOperations) {
    for (SetOperation* setOperation : *stmt->setOperations) {
      switch (setOperation->setType) {
        case SetType::kSetIntersect:
          inprint("Intersect:", num_indent + 1);
          break;
        case SetType::kSetUnion:
          inprint("Union:", num_indent + 1);
          break;
        case SetType::kSetExcept:
          inprint("Except:", num_indent + 1);
          break;
      }

      printSelectStatementInfo(setOperation->nestedSelectStatement, num_indent + 2);

      if (setOperation->resultOrder) {
        inprint("SetResultOrderBy:", num_indent + 1);
        printOrderBy(setOperation->resultOrder, num_indent + 2);
      }

      if (setOperation->resultLimit) {
        if (setOperation->resultLimit->limit) {
          inprint("SetResultLimit:", num_indent + 1);
          printExpression(setOperation->resultLimit->limit, num_indent + 2);
        }

        if (setOperation->resultLimit->offset) {
          inprint("SetResultOffset:", num_indent + 1);
          printExpression(setOperation->resultLimit->offset, num_indent + 2);
        }
      }
    }
  }

  if (stmt->order) {
    inprint("OrderBy:", num_indent + 1);
    printOrderBy(stmt->order, num_indent + 2);
  }

  if (stmt->limit && stmt->limit->limit) {
    inprint("Limit:", num_indent + 1);
    printExpression(stmt->limit->limit, num_indent + 2);
  }

  if (stmt->limit && stmt->limit->offset) {
    inprint("Offset:", num_indent + 1);
    printExpression(stmt->limit->offset, num_indent + 2);
  }
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq 0xa8(%rsp), %rsi
leaq 0x14cf9(%rip), %rdi     # 0x7e8bf
callq 0x39830
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14cf1(%rip), %rdi     # 0x7e8cf
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x36b30
movq %rax, 0x98(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x38740
movq %rax, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x39fa0
testb $0x1, %al
jne 0x69c3c
jmp 0x69c7c
leaq 0x98(%rsp), %rdi
callq 0x37b30
movq (%rax), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
leaq 0x98(%rsp), %rdi
callq 0x36f80
jmp 0x69c21
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x69cc0
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14c39(%rip), %rdi     # 0x7e8d7
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x386c0
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0x69d04
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14bfe(%rip), %rdi     # 0x7e8e0
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x40(%rax)
je 0x69e02
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14bc9(%rip), %rdi     # 0x7e8f3
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rdi
callq 0x36b30
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rdi
callq 0x38740
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x39fa0
testb $0x1, %al
jne 0x69d80
jmp 0x69db4
leaq 0x78(%rsp), %rdi
callq 0x37b30
movq (%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
leaq 0x78(%rsp), %rdi
callq 0x36f80
jmp 0x69d6b
movq 0xb0(%rsp), %rax
movq 0x40(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x69e00
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14b22(%rip), %rdi     # 0x7e8fc
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x10(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
jmp 0x69e02
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x68(%rax)
je 0x6a046
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14adc(%rip), %rdi     # 0x7e904
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x68(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
callq 0x39150
movq %rax, 0x58(%rsp)
movq 0x60(%rsp), %rdi
callq 0x36af0
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x35f70
testb $0x1, %al
jne 0x69e74
jmp 0x6a044
leaq 0x58(%rsp), %rdi
callq 0x38f80
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
leaq 0x14a76(%rip), %rdi     # 0x7e90f
callq 0x39830
movq 0x48(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x69ec2
movq 0xa8(%rsp), %rsi
addq $0x3, %rsi
leaq 0x14a59(%rip), %rdi     # 0x7e914
callq 0x39830
jmp 0x69f32
movq 0x48(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x69ee6
movq 0xa8(%rsp), %rsi
addq $0x3, %rsi
leaq 0x14a40(%rip), %rdi     # 0x7e91f
callq 0x39830
jmp 0x69f30
movq 0x48(%rsp), %rax
cmpl $0x2, (%rax)
jne 0x69f0a
movq 0xa8(%rsp), %rsi
addq $0x3, %rsi
leaq 0x14a2e(%rip), %rdi     # 0x7e931
callq 0x39830
jmp 0x69f2e
movq 0x48(%rsp), %rax
cmpl $0x3, (%rax)
jne 0x69f2c
movq 0xa8(%rsp), %rsi
addq $0x3, %rsi
leaq 0x14a14(%rip), %rdi     # 0x7e93b
callq 0x39830
jmp 0x69f2e
jmp 0x69f30
jmp 0x69f32
movq 0x48(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x69fd1
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
leaq 0x149f4(%rip), %rdi     # 0x7e949
callq 0x39830
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
callq 0x37d80
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
callq 0x399b0
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x392c0
testb $0x1, %al
jne 0x69f9b
jmp 0x69fcf
leaq 0x38(%rsp), %rdi
callq 0x38ff0
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0xa8(%rsp), %rsi
addq $0x3, %rsi
callq 0x39830
leaq 0x38(%rsp), %rdi
callq 0x36eb0
jmp 0x69f86
jmp 0x69fd1
movq 0x48(%rsp), %rax
cmpl $0x2, 0x4(%rax)
je 0x6a033
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
leaq 0x14969(%rip), %rdi     # 0x7e958
callq 0x39830
movq 0x48(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x6a019
movq 0xa8(%rsp), %rsi
addq $0x3, %rsi
leaq 0x87b8(%rip), %rdi      # 0x727ca
callq 0x39830
jmp 0x6a031
movq 0xa8(%rsp), %rsi
addq $0x3, %rsi
leaq 0x1493d(%rip), %rdi     # 0x7e969
callq 0x39830
jmp 0x6a033
jmp 0x6a035
leaq 0x58(%rsp), %rdi
callq 0x377f0
jmp 0x69e5c
jmp 0x6a046
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x48(%rax)
je 0x6a22f
movq 0xb0(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x35800
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
callq 0x39d90
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x37d60
testb $0x1, %al
jne 0x6a0a0
jmp 0x6a22d
leaq 0x18(%rsp), %rdi
callq 0x37190
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x6a0f4
jmp 0x6a0c4
movl 0x4(%rsp), %eax
subl $0x1, %eax
je 0x6a0da
jmp 0x6a0cf
movl 0x4(%rsp), %eax
subl $0x2, %eax
je 0x6a10e
jmp 0x6a126
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14888(%rip), %rdi     # 0x7e975
callq 0x39830
jmp 0x6a126
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14879(%rip), %rdi     # 0x7e980
callq 0x39830
jmp 0x6a126
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14866(%rip), %rdi     # 0x7e987
callq 0x39830
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x36610
movq 0x8(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x6a17e
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14830(%rip), %rdi     # 0x7e98f
callq 0x39830
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x38ee0
movq 0x8(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6a21c
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x6a1d4
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x147f0(%rip), %rdi     # 0x7e9a1
callq 0x39830
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x6a21a
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x147ba(%rip), %rdi     # 0x7e9b1
callq 0x39830
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
jmp 0x6a21c
jmp 0x6a21e
leaq 0x18(%rsp), %rdi
callq 0x38730
jmp 0x6a088
jmp 0x6a22f
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x50(%rax)
je 0x6a273
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14747(%rip), %rdi     # 0x7e998
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x38ee0
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x60(%rax)
je 0x6a2ce
movq 0xb0(%rsp), %rax
movq 0x60(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x6a2ce
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14702(%rip), %rdi     # 0x7e9aa
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
movq 0xb0(%rsp), %rax
cmpq $0x0, 0x60(%rax)
je 0x6a329
movq 0xb0(%rsp), %rax
movq 0x60(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x6a329
movq 0xa8(%rsp), %rsi
addq $0x1, %rsi
leaq 0x146b7(%rip), %rdi     # 0x7e9ba
callq 0x39830
movq 0xb0(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x10(%rax), %rdi
movq 0xa8(%rsp), %rsi
addq $0x2, %rsi
callq 0x37340
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)