// File: hyrise[P]sql-parser/src/util/sqlhelper.cpp
// Function: hsql::printExpression(hsql::Expr*, unsigned long)
void printExpression(Expr* expr, uintmax_t num_indent) {
  if (!expr) return;
  switch (expr->type) {
    case kExprStar:
      inprint("*", num_indent);
      break;
    case kExprColumnRef:
      inprint(expr->name, num_indent);
      if (expr->table) {
        inprint("Table:", num_indent + 1);
        inprint(expr->table, num_indent + 2);
      }
      break;
    // case kExprTableColumnRef: inprint(expr->table, expr->name, num_indent); break;
    case kExprLiteralFloat:
      inprint(expr->fval, num_indent);
      break;
    case kExprLiteralInt:
      inprint(expr->ival, num_indent);
      break;
    case kExprLiteralString:
      inprint(expr->name, num_indent);
      break;
    case kExprLiteralDate:
      inprint(expr->name, num_indent);
      break;
    case kExprLiteralNull:
      inprint("NULL", num_indent);
      break;
    case kExprLiteralInterval:
      inprint("INTERVAL", num_indent);
      inprint(expr->ival, num_indent + 1);
      inprint(expr->datetimeField, num_indent + 1);
      break;
    case kExprFunctionRef:
      inprint(expr->name, num_indent);
      for (Expr* e : *expr->exprList) {
        printExpression(e, num_indent + 1);
      }

      if (expr->windowDescription) {
        printWindowDescription(expr->windowDescription, num_indent + 1);
      }
      break;
    case kExprExtract:
      inprint("EXTRACT", num_indent);
      inprint(expr->datetimeField, num_indent + 1);
      printExpression(expr->expr, num_indent + 1);
      break;
    case kExprCast:
      inprint("CAST", num_indent);
      inprint(expr->columnType, num_indent + 1);
      printExpression(expr->expr, num_indent + 1);
      break;
    case kExprOperator:
      printOperatorExpression(expr, num_indent);
      break;
    case kExprSelect:
      printSelectStatementInfo(expr->select, num_indent);
      break;
    case kExprParameter:
      inprint(expr->ival, num_indent);
      break;
    case kExprArray:
      for (Expr* e : *expr->exprList) {
        printExpression(e, num_indent + 1);
      }
      break;
    case kExprArrayIndex:
      printExpression(expr->expr, num_indent + 1);
      inprint(expr->ival, num_indent);
      break;
    default:
      std::cerr << "Unrecognized expression type " << expr->type << std::endl;
      return;
  }
  if (expr->alias) {
    inprint("Alias", num_indent + 1);
    inprint(expr->alias, num_indent + 2);
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
cmpq $0x0, 0x50(%rsp)
jne 0x6a35b
jmp 0x6a731
movq 0x50(%rsp), %rax
movl 0x8(%rax), %eax
movq %rax, (%rsp)
subq $0x10, %rax
ja 0x6a6c5
movq (%rsp), %rax
leaq 0x14408(%rip), %rcx     # 0x7e784
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x48(%rsp), %rsi
leaq 0x144cc(%rip), %rdi     # 0x7e85d
callq 0x39830
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x39830
movq 0x50(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0x6a3e6
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
leaq 0x14495(%rip), %rdi     # 0x7e85f
callq 0x39830
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x48(%rsp), %rsi
addq $0x2, %rsi
callq 0x39830
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movsd 0x48(%rax), %xmm0
movq 0x48(%rsp), %rdi
callq 0x39d40
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x384e0
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x39830
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x39830
jmp 0x6a6f9
movq 0x48(%rsp), %rsi
leaq 0x14621(%rip), %rdi     # 0x7ea79
callq 0x39830
jmp 0x6a6f9
movq 0x48(%rsp), %rsi
leaq 0x831e(%rip), %rdi      # 0x7278c
callq 0x39830
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x384e0
movq 0x50(%rsp), %rdi
addq $0x60, %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x39ca0
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x39830
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
callq 0x36b30
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
callq 0x38740
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x39fa0
testb $0x1, %al
jne 0x6a4fa
jmp 0x6a52b
leaq 0x38(%rsp), %rdi
callq 0x37b30
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x37340
leaq 0x38(%rsp), %rdi
callq 0x36f80
jmp 0x6a4e5
movq 0x50(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0x6a554
movq 0x50(%rsp), %rax
movq 0x98(%rax), %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x39000
jmp 0x6a6f9
movq 0x48(%rsp), %rsi
leaq 0x803d(%rip), %rdi      # 0x725a2
callq 0x39830
movq 0x50(%rsp), %rdi
addq $0x60, %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x39ca0
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x37340
jmp 0x6a6f9
movq 0x48(%rsp), %rsi
leaq 0x8001(%rip), %rdi      # 0x725aa
callq 0x39830
movq 0x50(%rsp), %rdi
addq $0x68, %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x394f0
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x37340
jmp 0x6a6f9
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x38f70
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x36610
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x384e0
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x36b30
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
callq 0x38740
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x39fa0
testb $0x1, %al
jne 0x6a666
jmp 0x6a697
leaq 0x18(%rsp), %rdi
callq 0x37b30
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x37340
leaq 0x18(%rsp), %rdi
callq 0x36f80
jmp 0x6a651
jmp 0x6a6f9
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
callq 0x37340
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0x384e0
jmp 0x6a6f9
movq 0x2291c(%rip), %rdi     # 0x8cfe8
leaq 0x14193(%rip), %rsi     # 0x7e866
callq 0x377a0
movq %rax, %rdi
movq 0x50(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x39810
movq %rax, %rdi
movq 0x227b6(%rip), %rsi     # 0x8cea8
callq 0x37a00
jmp 0x6a731
movq 0x50(%rsp), %rax
cmpq $0x0, 0x40(%rax)
je 0x6a731
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
leaq 0x1413d(%rip), %rdi     # 0x7e852
callq 0x39830
movq 0x50(%rsp), %rax
movq 0x40(%rax), %rdi
movq 0x48(%rsp), %rsi
addq $0x2, %rsi
callq 0x39830
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)