// File: /workspace/github_c_makefile_star2_O1/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 $0x5c8, %rsp            # imm = 0x5C8
movl %edi, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
leaq 0x10de2(%rip), %rdi     # 0x77700
callq 0x7490
testq %rax, %rax
je 0x66933
movl 0x26972(%rip), %ebx     # 0x8d2a0
jmp 0x67176
callq 0x684be
movq %rax, 0x50(%rsp)
leaq 0x440(%rsp), %rdi
callq 0x7260
leaq 0x450(%rsp), %r14
leaq 0x10db4(%rip), %rsi     # 0x7770d
movl $0xd, %edx
movq %r14, %rdi
callq 0x7430
movq 0x10(%rsp), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x6698b
movq %rbx, %rdi
callq 0x7170
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x7430
jmp 0x669aa
movq 0x450(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x470(%rsp,%rax), %esi
orl $0x1, %esi
callq 0x7640
leaq 0x118f6(%rip), %rsi     # 0x782a7
movl $0x1, %edx
movq %r14, %rdi
callq 0x7430
cmpl $0x2, 0xc(%rsp)
jl 0x66a6f
movl $0x1, %r15d
leaq 0x10d41(%rip), %r13     # 0x77717
leaq 0x118ca(%rip), %rbp     # 0x782a7
movl $0x2, %edx
movq %r14, %rdi
leaq 0x10d2f(%rip), %rsi     # 0x7771b
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 0x66a35
movq %r12, %rdi
callq 0x7170
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x7430
jmp 0x66a4e
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 0x669dd
leaq 0x128(%rsp), %rdi
xorl %esi, %esi
callq 0x6cd36
leaq 0x458(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x75d0
leaq 0x130(%rsp), %rdi
movq 0xe8(%rsp), %rsi
movq 0xf0(%rsp), %rdx
callq 0x7430
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66ac6
callq 0x7360
leaq 0x128(%rsp), %rdi
callq 0x6d1d6
movl 0xc(%rsp), %ebp
cmpl $0x1, %ebp
jne 0x66b1e
leaq 0xd8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x10c2f(%rip), %rsi     # 0x7771e
leaq 0x10c3e(%rip), %rdx     # 0x77734
leaq 0xc8(%rsp), %rdi
callq 0x6743e
leaq 0xc8(%rsp), %rsi
movq 0x50(%rsp), %rdi
xorl %edx, %edx
callq 0x6834c
movl %eax, %ebx
xorb $0x1, %bl
jmp 0x66b20
xorl %ebx, %ebx
cmpl $0x1, %ebp
jne 0x66b3b
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66b3b
callq 0x7360
testb %bl, %bl
jne 0x6718a
leaq 0xc(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %edx
callq 0x6b144
cmpb $0x1, 0x2677a(%rip)     # 0x8d2d8
jne 0x66bad
movq 0x24451(%rip), %rbx     # 0x8afb8
leaq 0x10bc7(%rip), %rsi     # 0x77735
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 0x2441f(%rip), %rdi     # 0x8afb8
callq 0x7040
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x7220
jmp 0x67169
movq 0x264f4(%rip), %rdx     # 0x8d0a8
testq %rdx, %rdx
je 0x66bf6
movq 0x264e0(%rip), %rsi     # 0x8d0a0
movq 0x24421(%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 0x138(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x10b32(%rip), %rsi     # 0x7773b
leaq 0x10b35(%rip), %rdx     # 0x77745
leaq 0x128(%rsp), %rdi
callq 0x6743e
leaq 0x28(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x10aa7(%rip), %rdx     # 0x776d5
leaq 0x18(%rsp), %rdi
movq %rdx, %rsi
callq 0x6743e
leaq 0x78(%rsp), %rdi
leaq 0x128(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq 0x50(%rsp), %rsi
callq 0x68466
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x66c66
callq 0x7360
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
je 0x66c78
callq 0x7360
leaq 0x10a56(%rip), %rsi     # 0x776d5
leaq 0x78(%rsp), %rdi
callq 0x70e0
testl %eax, %eax
je 0x671aa
callq 0x6d2f4
callq 0x674d0
cmpb $0x1, 0x2666e(%rip)     # 0x8d310
jne 0x66f5e
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x687e6
leaq 0x128(%rsp), %rdi
callq 0x7260
leaq 0x10aa4(%rip), %rdi     # 0x77772
callq 0x7490
testq %rax, %rax
je 0x66e93
movq %rax, %r14
leaq 0x138(%rsp), %rbx
leaq 0x10a93(%rip), %rsi     # 0x77781
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 0x10aa2(%rip), %rsi     # 0x777ba
movl $0x16, %edx
movq %rbx, %rdi
callq 0x7430
leaq 0x140(%rsp), %rbx
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x75d0
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x68dd8
movq %rax, %r15
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x66d60
callq 0x7360
testq %r15, %r15
je 0x66d70
cmpq $0x1, 0x30(%r15)
je 0x66e5e
movq 0x24271(%rip), %rdi     # 0x8afe8
leaq 0x10a53(%rip), %rsi     # 0x777d1
movl $0x12, %edx
callq 0x7430
movq %r14, %rdi
callq 0x7170
movq 0x24251(%rip), %rdi     # 0x8afe8
movq %r14, %rsi
movq %rax, %rdx
callq 0x7430
movq 0x2423f(%rip), %rdi     # 0x8afe8
leaq 0x10a34(%rip), %rsi     # 0x777e4
movl $0xd, %edx
callq 0x7430
movq 0x24227(%rip), %r14     # 0x8afe8
leaq 0x10a2a(%rip), %rsi     # 0x777f2
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 0x241f5(%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 0x66e5b
callq 0x7360
xorl %r14d, %r14d
leaq 0x18(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x10868(%rip), %rdx     # 0x776d5
movq %rdx, %rsi
callq 0x6743e
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x7560
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x66e96
callq 0x7360
jmp 0x66e96
xorl %r14d, %r14d
testq %r14, %r14
je 0x66ee5
movq %r14, %rdi
callq 0x7170
movq 0x2410e(%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 0x240e2(%rip), %rdi     # 0x8afb8
callq 0x7040
movq %rax, %rdi
callq 0x7220
jmp 0x66f44
leaq 0x18(%rsp), %rdi
callq 0x6d580
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x6a0da
movq 0x240b0(%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 0x6dc02
leaq 0x128(%rsp), %rdi
callq 0x7748
leaq 0x98(%rsp), %rdi
callq 0x69774
cmpq $0x0, 0x26192(%rip)     # 0x8d0f8
jne 0x66f9a
cmpl $0x0, 0x26201(%rip)     # 0x8d170
jne 0x66f9a
cmpq $0x0, 0x26207(%rip)     # 0x8d180
jne 0x66f9a
cmpl $0x0, 0x26276(%rip)     # 0x8d1f8
jne 0x66f9a
cmpl $0x0, 0x262a5(%rip)     # 0x8d230
jne 0x66f9a
cmpl $0x0, 0x262d4(%rip)     # 0x8d268
je 0x67083
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x687e6
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x26137(%rip), %rsi     # 0x8d0f0
movq 0x26138(%rip), %rdx     # 0x8d0f8
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x673ae
movl 0x2619d(%rip), %ebx     # 0x8d170
movl 0x2621f(%rip), %ebp     # 0x8d1f8
movl 0x26250(%rip), %r14d    # 0x8d230
movl 0x26281(%rip), %r15d    # 0x8d268
leaq 0x118(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x2617e(%rip), %rsi     # 0x8d178
movq 0x2617f(%rip), %rdx     # 0x8d180
addq %rsi, %rdx
leaq 0x108(%rsp), %r12
movq %r12, %rdi
callq 0x673ae
movq %r12, (%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movl %ebx, %edx
movl %ebp, %ecx
movl %r14d, %r8d
movl %r15d, %r9d
callq 0x67720
movq 0x108(%rsp), %rdi
cmpq %r13, %rdi
je 0x67046
callq 0x7360
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6705a
callq 0x7360
leaq 0x18(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x6a0da
leaq 0x128(%rsp), %rdi
callq 0x67d6e
leaq 0x18(%rsp), %rdi
callq 0x69774
cmpb $0x1, 0x262be(%rip)     # 0x8d348
jne 0x6714d
leaq 0x106db(%rip), %rdi     # 0x77772
callq 0x7490
testq %rax, %rax
je 0x67115
leaq 0x128(%rsp), %rdi
callq 0x6d580
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x687e6
leaq 0x98(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x6dc5a
leaq 0x18(%rsp), %rdi
leaq 0x98(%rsp), %rsi
xorl %edx, %edx
callq 0x68dd8
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x670fc
callq 0x7360
leaq 0x18(%rsp), %rdi
callq 0x69774
leaq 0x128(%rsp), %rdi
callq 0x6dc02
jmp 0x6714d
leaq 0x128(%rsp), %rdi
movl $0x3, %esi
callq 0x6cd36
leaq 0x130(%rsp), %rdi
leaq 0x106d2(%rip), %rsi     # 0x77808
movl $0x38, %edx
callq 0x7430
leaq 0x128(%rsp), %rdi
callq 0x6d1d6
movl 0x2614d(%rip), %ebx     # 0x8d2a0
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67169
callq 0x7360
leaq 0x440(%rsp), %rdi
callq 0x7748
movl %ebx, %eax
addq $0x5c8, %rsp            # imm = 0x5C8
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 0x6b144
movq 0x23e43(%rip), %rdi     # 0x8afe8
callq 0x668cc
movq 0x23e37(%rip), %rdi     # 0x8afe8
leaq 0x1058e(%rip), %rsi     # 0x77746
movl $0x2b, %edx
callq 0x7430
movq 0x23e1f(%rip), %rdi     # 0x8afe8
callq 0x668cc
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x6d1d6
jmp 0x67366
jmp 0x67344
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67206
callq 0x7360
jmp 0x67206
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x69774
jmp 0x67232
jmp 0x6728d
jmp 0x67344
jmp 0x6728d
jmp 0x67344
jmp 0x67363
jmp 0x67344
jmp 0x67363
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x6dc02
jmp 0x67366
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x67d6e
jmp 0x67309
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r13, %rdi
je 0x67273
callq 0x7360
jmp 0x67273
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x67309
callq 0x7360
jmp 0x67309
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x67347
callq 0x7360
jmp 0x67347
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x6dc02
jmp 0x67347
jmp 0x67363
movq %rax, %rbx
jmp 0x67354
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x672de
callq 0x7360
jmp 0x672de
movq %rax, %rbx
movq 0x128(%rsp), %rdi
jmp 0x672f8
jmp 0x67382
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r14, %rdi
jne 0x67377
jmp 0x67385
jmp 0x67382
jmp 0x67363
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x69774
jmp 0x67366
jmp 0x67344
movq %rax, %rbx
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67335
callq 0x7360
jmp 0x67335
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x6d1d6
jmp 0x67385
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x7748
leaq 0x98(%rsp), %rdi
callq 0x69774
jmp 0x67366
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67385
callq 0x7360
jmp 0x67385
jmp 0x67382
jmp 0x67382
movq %rax, %rbx
leaq 0x440(%rsp), %rdi
callq 0x7748
movq %rbx, %rdi
callq 0x76a0
movq %rax, %rdi
callq 0x673a2