// File: /workspace/github_cpp_makefile_star2_O3/solaldunckel[P]webserv/srcs/main.cpp
// Function: main
int main(int argc, char **argv) {
  try {
    InputArgs options(argc, argv);

    options.parse();

    if (options.help()) {
      std::cout << options.helpText() << std::endl;
      return 0;
    }

    Log.setLogLevel(options.log());

    Config config(options.getPath());

    config.parse();

    if (options.test()) {
      Log.print(INFO, "# configuration file " + config.getPath() + "\n\n" + config.getFileContent());
      return 0;
    }

    Log.print(INFO, "# configuration file " + config.getPath());

    config.clear();

    Server serv(config.getServers(), options);

    serv.setup();

    if (config.getWorkers() > 0) {
      g_workers.resize(config.getWorkers());

      pthread_mutex_init(&g_accept, NULL);
	    pthread_mutex_init(&g_write, NULL);

      for (int i = 0; i < config.getWorkers(); i++) {
        g_workers[i].id_ = i + 1;
        g_workers[i].serv_ = new Server(serv);
        pthread_create(&g_workers[i].thr_, NULL, startWorker, &g_workers[i]);
        usleep(500);
      }

      for (int i = 0; i < config.getWorkers(); i++) {
        pthread_join(g_workers[i].thr_, NULL);
        delete g_workers[i].serv_;
      }

      pthread_mutex_destroy(&g_write);
      pthread_mutex_destroy(&g_accept);
    } else {
      serv.run();
    }
  }
  catch (std::exception &e) {
    Log.print(INFO, e.what(), RED, true);
    return 1;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rsi, %rdx
movl %edi, %esi
leaq 0x158(%rsp), %rdi
callq 0x8420
leaq 0x158(%rsp), %rdi
callq 0x8670
leaq 0x158(%rsp), %rdi
callq 0x8dd4
testb %al, %al
je 0x4f89
leaq 0x1c0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x8d2e
movq 0x1c0(%rsp), %rsi
movq 0x1c8(%rsp), %rdx
movq 0x2d088(%rip), %rdi     # 0x31fb8
callq 0x44e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4430
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x42c0
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x53d5
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x53d5
leaq 0x158(%rsp), %rdi
callq 0x8ec8
leaq 0x2d54b(%rip), %rdi     # 0x324e8
movl %eax, %esi
callq 0x20f2a
leaq 0x158(%rsp), %rdi
callq 0x8dce
leaq 0xe0(%rsp), %rdi
movq %rax, %rsi
callq 0x5a28
leaq 0xe0(%rsp), %rdi
callq 0x6264
leaq 0x158(%rsp), %rdi
callq 0x8ecc
testb %al, %al
je 0x504e
leaq 0xe0(%rsp), %rdi
callq 0x659c
leaq 0x20011(%rip), %rsi     # 0x25004
leaq 0xc0(%rsp), %rdi
movq %rax, %rdx
callq 0x568a
leaq 0x20202(%rip), %rsi     # 0x2520c
leaq 0xc0(%rsp), %rdi
callq 0x4840
leaq 0x1d0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5278
movq %rdx, 0x1c0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x1d0(%rsp)
jmp 0x527f
leaq 0xe0(%rsp), %rdi
callq 0x659c
leaq 0x1ffa2(%rip), %rsi     # 0x25004
leaq 0xa0(%rsp), %rdi
movq %rax, %rdx
callq 0x568a
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1ff98(%rip), %rsi     # 0x2501a
leaq 0x1ff96(%rip), %rdx     # 0x2501f
leaq 0x40(%rsp), %rdi
callq 0x579e
leaq 0x2d44e(%rip), %rdi     # 0x324e8
leaq 0xa0(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x20f32
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x50cb
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50ec
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0xe0(%rsp), %rdi
callq 0x5c28
leaq 0xe0(%rsp), %rdi
callq 0x65a0
leaq 0x1c0(%rsp), %rdi
leaq 0x158(%rsp), %rdx
movq %rax, %rsi
callq 0x18512
leaq 0x1c0(%rsp), %rdi
callq 0x18600
leaq 0xe0(%rsp), %rdi
callq 0x65a6
testl %eax, %eax
jle 0x53ac
leaq 0xe0(%rsp), %rdi
callq 0x65a6
movslq %eax, %rsi
leaq 0x2d379(%rip), %rdi     # 0x324d0
callq 0x5750
leaq 0x2d31d(%rip), %rdi     # 0x32480
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x4630
leaq 0x2d334(%rip), %rdi     # 0x324a8
xorl %esi, %esi
callq 0x4630
leaq 0xe0(%rsp), %rbx
leaq 0x1c0(%rsp), %r14
leaq -0x2e6(%rip), %r15      # 0x4eac
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x65a6
cltq
cmpq %rax, %rbp
jge 0x51fd
movq 0x2d326(%rip), %rax     # 0x324d0
leal 0x1(%rbp), %ecx
movl %ecx, 0x8(%rax,%r13)
movl $0x238, %edi            # imm = 0x238
callq 0x4440
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x18384
movq 0x2d2ff(%rip), %rcx     # 0x324d0
leaq (%rcx,%r13), %rdi
addq $0x10, %rdi
addq %r13, %rcx
movq %r12, -0x10(%rdi)
xorl %esi, %esi
movq %r15, %rdx
callq 0x47f0
addq $0x18, %r13
incq %rbp
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x45d0
jmp 0x5194
xorl %r15d, %r15d
leaq 0xe0(%rsp), %rbx
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x65a6
cltq
cmpq %rax, %r12
jge 0x525b
movq 0x2d2af(%rip), %rax     # 0x324d0
movq 0x10(%rax,%r15), %rdi
xorl %esi, %esi
callq 0x43c0
movq 0x2d29c(%rip), %rax     # 0x324d0
movq (%rax,%r15), %r14
testq %r14, %r14
je 0x5245
movq %r14, %rdi
callq 0x18598
movl $0x238, %esi            # imm = 0x238
movq %r14, %rdi
callq 0x4470
incq %r12
addq $0x18, %r15
jmp 0x520b
leaq 0x2d246(%rip), %rdi     # 0x324a8
callq 0x4520
leaq 0x2d212(%rip), %rdi     # 0x32480
callq 0x4520
jmp 0x53bb
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x1c8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xe0(%rsp), %rdi
callq 0x65aa
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x1c0(%rsp), %rdi
callq 0x4100
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x52e2
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x52ea
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x70(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1fd08(%rip), %rsi     # 0x2501a
leaq 0x1fd06(%rip), %rdx     # 0x2501f
leaq 0x60(%rsp), %rdi
callq 0x579e
leaq 0x2d1be(%rip), %rdi     # 0x324e8
movq %rsp, %rdx
leaq 0x60(%rsp), %rcx
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x20f32
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x5356
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4470
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x536c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1c0(%rsp), %rdi
cmpq %r15, %rdi
je 0x5389
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x53c8
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x53c8
leaq 0x1c0(%rsp), %rdi
xorl %esi, %esi
callq 0x1a248
leaq 0x1c0(%rsp), %rdi
callq 0x18598
leaq 0xe0(%rsp), %rdi
callq 0x5bd2
leaq 0x158(%rsp), %rdi
callq 0x8648
xorl %eax, %eax
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x541b
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x541b
movq %rdx, %r14
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x5487
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x5487
movq %rdx, %r14
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x5458
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x5458
movq %rdx, %r14
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x553e
movq 0xb0(%rsp), %rsi
jmp 0x54c1
movq %rdx, %r14
movq %rax, %rbx
jmp 0x54a4
jmp 0x54db
movq %rdx, %r14
movq %rax, %rbx
movq 0x1c0(%rsp), %rdi
cmpq %r15, %rdi
je 0x54a4
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x553e
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x553e
jmp 0x54db
jmp 0x550c
jmp 0x552b
jmp 0x550c
movq %rdx, %r14
movq %rax, %rbx
jmp 0x5558
movq %rdx, %r14
movq %rax, %rbx
jmp 0x553e
movq %rdx, %r14
movq %rax, %rbx
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x554b
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x554b
movq %rdx, %r14
movq %rax, %rbx
jmp 0x554b
movq %rdx, %r14
movq %rax, %rbx
movl $0x238, %esi            # imm = 0x238
movq %r12, %rdi
callq 0x4470
jmp 0x5531
jmp 0x552b
movq %rdx, %r14
movq %rax, %rbx
leaq 0x1c0(%rsp), %rdi
callq 0x18598
leaq 0xe0(%rsp), %rdi
callq 0x5bd2
leaq 0x158(%rsp), %rdi
callq 0x8648
cmpl $0x1, %r14d
jne 0x5661
movq %rbx, %rdi
callq 0x4180
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x80(%rsp), %rdi
leaq 0x1c0(%rsp), %rdx
movq %rax, %rsi
callq 0x5712
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1fa85(%rip), %rsi     # 0x25020
leaq 0x1fa83(%rip), %rdx     # 0x25025
leaq 0x20(%rsp), %rdi
callq 0x579e
leaq 0x2cf35(%rip), %rdi     # 0x324e8
leaq 0x80(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movl $0x1, %esi
movl $0x1, %r8d
callq 0x20f32
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x55e7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5608
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
callq 0x4720
movl $0x1, %eax
jmp 0x53e4
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x5636
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x5636
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x565c
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x565c
movq %rax, %rbx
callq 0x4720
movq %rbx, %rdi
callq 0x4790
movq %rax, %rdi
callq 0x5793
nop