// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/_ash_log.cpp
// Function: main
int main(int argc, char ** argv) {
  if (getenv("ASH_DISABLED")) return FLAGS_exit;

  // Load the config from the environment.
  Config & config = Config::instance();

  // Log the complete command, if debugging.
  stringstream ss;
  ss << "argv = '[0]='" << argv[0] << "'";
  for (int i = 1; i < argc; ++i)
    ss << ",[" << i << "]='" << argv[i] << "'";
  LOG(DEBUG) << ss.str();

  // Show usage if executed with no args.
  if (argc == 1 && !config.sets("HIDE_USAGE_FOR_NO_ARGS")) {
    Flag::parse(&argc, &argv, true);  // Sets the prog name in help output.
    usage(cerr);
  }

  // Parse the flags.
  Flag::parse(&argc, &argv, true);

  // Display the version and stop: -V
  if (FLAGS_version) {
    cout << ASH_VERSION << endl;
    return 0;
  }

  // Display a user alert: -a 'My alert'
  if (!FLAGS_alert.empty()) {
    cerr << FLAGS_alert << endl;
  }

  // Get the filename backing the history database.
  string db_file = config.get_string("HISTORY_DB");
  if (db_file == "") {
    usage(cerr << "\nExpected ASH_CFG_HISTORY_DB to be defined.");
  }

  // Register the tables expected in the program.
  Session::register_table();
  Command::register_table();

  // Emit the current session number, inserting one if none exists: -S
  if (FLAGS_get_session_id) {
    Database db = Database(db_file);
    stringstream ss;
    char * id = getenv("ASH_SESSION_ID");
    if (id) {
      ss << "select count(*) as session_cnt from sessions where id = " << id
         << " and duration is null;";
      ResultSet * rs = db.exec(ss.str());
      if (!rs || rs -> rows != 1) {
        cerr << "ERROR: session_id(" << id << ") not found, "
             << "creating new session." << endl << ss.str() << endl;
        id = 0;
      }
      ss.str("");
    }

    if (id) {
      cout << id << endl;
    } else {
      Session session;
      cout << db.insert(&session) << endl;
    }
  }

  // Insert a command into the DB if there's a command to insert.
  const bool command_flag_used = !FLAGS_command.empty()
    || FLAGS_command_exit
    || !FLAGS_command_pipe_status.empty()
    || FLAGS_command_start
    || FLAGS_command_finish
    || FLAGS_command_number;

  if (command_flag_used) {
    Database db = Database(db_file);
    Command com(FLAGS_command, FLAGS_command_exit, FLAGS_command_start,
      FLAGS_command_finish, FLAGS_command_number, FLAGS_command_pipe_status);
    db.insert(&com);
  }

  // End the current session in the DB: -E
  if (FLAGS_end_session) {
    char * id = getenv("ASH_SESSION_ID");
    if (id == NULL) {
      LOG(ERROR) << "Can't end the current session: ASH_SESSION_ID undefined.";
    } else {
      Session session;
      Database db = Database(db_file);
      db.exec(session.get_close_session_sql());
    }
  }

  // Set the exit code to match what the previous command exited: -e 123
  return FLAGS_exit;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5a8, %rsp            # imm = 0x5A8
movl %edi, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
leaq 0x10fea(%rip), %rdi     # 0x77750
callq 0x7490
testq %rax, %rax
je 0x6677b
movl 0x26b2a(%rip), %ebx     # 0x8d2a0
jmp 0x66fa7
callq 0x682cc
movq %rax, 0x50(%rsp)
leaq 0x420(%rsp), %rdi
callq 0x7260
leaq 0x430(%rsp), %r14
leaq 0x10fbc(%rip), %rsi     # 0x7775d
movl $0xd, %edx
movq %r14, %rdi
callq 0x7430
movq 0x10(%rsp), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x667d3
movq %rbx, %rdi
callq 0x7170
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x7430
jmp 0x667f2
movq 0x430(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x450(%rsp,%rax), %esi
orl $0x1, %esi
callq 0x7640
leaq 0x11afe(%rip), %rsi     # 0x782f7
movl $0x1, %edx
movq %r14, %rdi
callq 0x7430
cmpl $0x2, 0xc(%rsp)
jl 0x668b7
movl $0x1, %r15d
leaq 0x10f49(%rip), %r13     # 0x77767
leaq 0x11ad2(%rip), %rbp     # 0x782f7
movl $0x2, %edx
movq %r14, %rdi
leaq 0x10f37(%rip), %rsi     # 0x7776b
callq 0x7430
movq %r14, %rdi
movl %r15d, %esi
callq 0x7660
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7430
movq 0x10(%rsp), %rax
movq (%rax,%r15,8), %r12
testq %r12, %r12
je 0x6687d
movq %r12, %rdi
callq 0x7170
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x7430
jmp 0x66896
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbx, %rdi
addq %rax, %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x7640
movl $0x1, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7430
incq %r15
movslq 0xc(%rsp), %rax
cmpq %rax, %r15
jl 0x66825
leaq 0x108(%rsp), %rdi
xorl %esi, %esi
callq 0x6cad2
leaq 0x438(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x75d0
leaq 0x110(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
callq 0x7430
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6690e
callq 0x7360
leaq 0x108(%rsp), %rdi
callq 0x6cf72
cmpl $0x1, 0xc(%rsp)
jne 0x66979
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x10e39(%rip), %rsi     # 0x7776e
leaq 0x10e48(%rip), %rdx     # 0x77784
leaq 0x108(%rsp), %rdi
callq 0x67260
leaq 0x108(%rsp), %rsi
movq 0x50(%rsp), %rdi
xorl %edx, %edx
callq 0x68170
movl %eax, %ebx
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0x66971
callq 0x7360
testb %bl, %bl
je 0x66fbb
leaq 0xc(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %edx
callq 0x6af04
cmpb $0x1, 0x26944(%rip)     # 0x8d2d8
jne 0x669e3
movq 0x2461b(%rip), %rbx     # 0x8afb8
leaq 0x10de1(%rip), %rsi     # 0x77785
movl $0x5, %edx
movq %rbx, %rdi
callq 0x7430
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x7390
movsbl %al, %esi
movq 0x245e9(%rip), %rdi     # 0x8afb8
callq 0x7040
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x7220
jmp 0x66f9a
movq 0x266be(%rip), %rdx     # 0x8d0a8
testq %rdx, %rdx
je 0x66a2c
movq 0x266aa(%rip), %rsi     # 0x8d0a0
movq 0x245eb(%rip), %rdi     # 0x8afe8
callq 0x7430
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7390
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7220
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x10d4c(%rip), %rsi     # 0x7778b
leaq 0x10d4f(%rip), %rdx     # 0x77795
leaq 0x108(%rsp), %rdi
callq 0x67260
leaq 0x28(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x10cc1(%rip), %rdx     # 0x77725
leaq 0x18(%rsp), %rdi
movq %rdx, %rsi
callq 0x67260
leaq 0x78(%rsp), %rdi
leaq 0x108(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq 0x50(%rsp), %rsi
callq 0x68274
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x66a9c
callq 0x7360
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0x66aae
callq 0x7360
leaq 0x10c70(%rip), %rsi     # 0x77725
leaq 0x78(%rsp), %rdi
callq 0x70e0
testl %eax, %eax
je 0x66fdb
callq 0x6d090
callq 0x672f8
cmpb $0x1, 0x26838(%rip)     # 0x8d310
jne 0x66d8f
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x685ee
leaq 0x108(%rsp), %rdi
callq 0x7260
leaq 0x10cbe(%rip), %rdi     # 0x777c2
callq 0x7490
testq %rax, %rax
je 0x66d16
movq %rax, %r14
leaq 0x118(%rsp), %rbx
leaq 0x10cad(%rip), %rsi     # 0x777d1
movl $0x38, %edx
movq %rbx, %rdi
callq 0x7430
movq %r14, %rdi
callq 0x7170
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7430
leaq 0x10cbc(%rip), %rsi     # 0x7780a
movl $0x16, %edx
movq %rbx, %rdi
callq 0x7430
leaq 0x120(%rsp), %rbx
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x75d0
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x68be2
movq %rax, %r15
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x66b96
callq 0x7360
testq %r15, %r15
je 0x66ba6
cmpq $0x1, 0x30(%r15)
je 0x66c94
movq 0x2443b(%rip), %rdi     # 0x8afe8
leaq 0x10c6d(%rip), %rsi     # 0x77821
movl $0x12, %edx
callq 0x7430
movq %r14, %rdi
callq 0x7170
movq 0x2441b(%rip), %rdi     # 0x8afe8
movq %r14, %rsi
movq %rax, %rdx
callq 0x7430
movq 0x24409(%rip), %rdi     # 0x8afe8
leaq 0x10c4e(%rip), %rsi     # 0x77834
movl $0xd, %edx
callq 0x7430
movq 0x243f1(%rip), %r14     # 0x8afe8
leaq 0x10c44(%rip), %rsi     # 0x77842
movl $0x15, %edx
movq %r14, %rdi
callq 0x7430
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x7390
movsbl %al, %esi
movq 0x243bf(%rip), %rdi     # 0x8afe8
callq 0x7040
movq %rax, %rdi
callq 0x7220
movq %rax, %r14
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x75d0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x7430
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7390
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7220
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x66c91
callq 0x7360
xorl %r14d, %r14d
leaq 0x18(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x10a82(%rip), %rdx     # 0x77725
movq %rdx, %rsi
callq 0x67260
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x7560
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x66cc7
callq 0x7360
testq %r14, %r14
je 0x66d16
movq %r14, %rdi
callq 0x7170
movq 0x242dd(%rip), %rbx     # 0x8afb8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7430
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x7390
movsbl %al, %esi
movq 0x242b1(%rip), %rdi     # 0x8afb8
callq 0x7040
movq %rax, %rdi
callq 0x7220
jmp 0x66d75
leaq 0x18(%rsp), %rdi
callq 0x6d31c
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x69eb4
movq 0x2427f(%rip), %rdi     # 0x8afb8
movq %rax, %rsi
callq 0x7370
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7390
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7220
leaq 0x18(%rsp), %rdi
callq 0x6d99e
leaq 0x108(%rsp), %rdi
callq 0x7748
leaq 0x98(%rsp), %rdi
callq 0x69538
cmpq $0x0, 0x26361(%rip)     # 0x8d0f8
jne 0x66dcb
cmpl $0x0, 0x263d0(%rip)     # 0x8d170
jne 0x66dcb
cmpq $0x0, 0x263d6(%rip)     # 0x8d180
jne 0x66dcb
cmpl $0x0, 0x26445(%rip)     # 0x8d1f8
jne 0x66dcb
cmpl $0x0, 0x26474(%rip)     # 0x8d230
jne 0x66dcb
cmpl $0x0, 0x264a3(%rip)     # 0x8d268
je 0x66eb4
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x685ee
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x26306(%rip), %rsi     # 0x8d0f0
movq 0x26307(%rip), %rdx     # 0x8d0f8
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x671ca
movl 0x2636c(%rip), %ebx     # 0x8d170
movl 0x263ee(%rip), %ebp     # 0x8d1f8
movl 0x2641f(%rip), %r14d    # 0x8d230
movl 0x26450(%rip), %r15d    # 0x8d268
leaq 0xf8(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x2634d(%rip), %rsi     # 0x8d178
movq 0x2634e(%rip), %rdx     # 0x8d180
addq %rsi, %rdx
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
callq 0x671ca
movq %r12, (%rsp)
leaq 0x108(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movl %ebx, %edx
movl %ebp, %ecx
movl %r14d, %r8d
movl %r15d, %r9d
callq 0x67548
movq 0xe8(%rsp), %rdi
cmpq %r13, %rdi
je 0x66e77
callq 0x7360
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x66e8b
callq 0x7360
leaq 0x18(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x69eb4
leaq 0x108(%rsp), %rdi
callq 0x67b96
leaq 0x18(%rsp), %rdi
callq 0x69538
cmpb $0x1, 0x2648d(%rip)     # 0x8d348
jne 0x66f7e
leaq 0x108fa(%rip), %rdi     # 0x777c2
callq 0x7490
testq %rax, %rax
je 0x66f46
leaq 0x108(%rsp), %rdi
callq 0x6d31c
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x685ee
leaq 0x98(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x6d9f6
leaq 0x18(%rsp), %rdi
leaq 0x98(%rsp), %rsi
xorl %edx, %edx
callq 0x68be2
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66f2d
callq 0x7360
leaq 0x18(%rsp), %rdi
callq 0x69538
leaq 0x108(%rsp), %rdi
callq 0x6d99e
jmp 0x66f7e
leaq 0x108(%rsp), %rdi
movl $0x3, %esi
callq 0x6cad2
leaq 0x110(%rsp), %rdi
leaq 0x108f1(%rip), %rsi     # 0x77858
movl $0x38, %edx
callq 0x7430
leaq 0x108(%rsp), %rdi
callq 0x6cf72
movl 0x2631c(%rip), %ebx     # 0x8d2a0
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66f9a
callq 0x7360
leaq 0x420(%rsp), %rdi
callq 0x7748
movl %ebx, %eax
addq $0x5a8, %rsp            # imm = 0x5A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %edx
callq 0x6af04
movq 0x24012(%rip), %rdi     # 0x8afe8
callq 0x66714
movq 0x24006(%rip), %rdi     # 0x8afe8
leaq 0x107ad(%rip), %rsi     # 0x77796
movl $0x2b, %edx
callq 0x7430
movq 0x23fee(%rip), %rdi     # 0x8afe8
callq 0x66714
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x6cf72
jmp 0x67182
jmp 0x67133
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67037
callq 0x7360
jmp 0x67037
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x69538
jmp 0x67063
jmp 0x670ba
jmp 0x67133
jmp 0x670ba
jmp 0x67133
jmp 0x6717f
jmp 0x67133
jmp 0x6717f
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x6d99e
jmp 0x67182
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x67b96
jmp 0x67116
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r13, %rdi
je 0x670a4
callq 0x7360
jmp 0x670a4
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x67116
callq 0x7360
jmp 0x67116
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x67136
callq 0x7360
jmp 0x67136
jmp 0x6717f
movq %rax, %rbx
jmp 0x67143
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x670f6
callq 0x7360
jmp 0x670f6
jmp 0x670f3
jmp 0x6719e
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
jne 0x67193
jmp 0x671a1
jmp 0x6719e
jmp 0x6717f
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x69538
jmp 0x67182
jmp 0x67133
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x6d99e
jmp 0x67136
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x7748
leaq 0x98(%rsp), %rdi
callq 0x69538
jmp 0x67182
movq %rax, %rbx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67170
callq 0x7360
jmp 0x67170
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x6cf72
jmp 0x671a1
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x671a1
callq 0x7360
jmp 0x671a1
jmp 0x6719e
jmp 0x6719e
movq %rax, %rbx
leaq 0x420(%rsp), %rdi
callq 0x7748
movq %rbx, %rdi
callq 0x76a0
movq %rax, %rdi
callq 0x671be