// File: /workspace/github_cpp_makefile_star2_O1/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 0x83b8
leaq 0x158(%rsp), %rdi
callq 0x8608
leaq 0x158(%rsp), %rdi
callq 0x8d20
testb %al, %al
je 0x4f79
leaq 0x1c0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x8c7a
movq 0x1c0(%rsp), %rsi
movq 0x1c8(%rsp), %rdx
movq 0x2d098(%rip), %rdi     # 0x31fb8
callq 0x44d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x42b0
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x53c5
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x53c5
leaq 0x158(%rsp), %rdi
callq 0x8e20
leaq 0x2d54b(%rip), %rdi     # 0x324d8
movl %eax, %esi
callq 0x20fa6
leaq 0x158(%rsp), %rdi
callq 0x8d1a
leaq 0xe0(%rsp), %rdi
movq %rax, %rsi
callq 0x5a0c
leaq 0xe0(%rsp), %rdi
callq 0x6206
leaq 0x158(%rsp), %rdi
callq 0x8e24
testb %al, %al
je 0x503e
leaq 0xe0(%rsp), %rdi
callq 0x652e
leaq 0x20021(%rip), %rsi     # 0x25004
leaq 0xc0(%rsp), %rdi
movq %rax, %rdx
callq 0x567a
leaq 0x20212(%rip), %rsi     # 0x2520c
leaq 0xc0(%rsp), %rdi
callq 0x4830
leaq 0x1d0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5268
movq %rdx, 0x1c0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x1d0(%rsp)
jmp 0x526f
leaq 0xe0(%rsp), %rdi
callq 0x652e
leaq 0x1ffb2(%rip), %rsi     # 0x25004
leaq 0xa0(%rsp), %rdi
movq %rax, %rdx
callq 0x567a
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1ffa8(%rip), %rsi     # 0x2501a
leaq 0x1ffa6(%rip), %rdx     # 0x2501f
leaq 0x40(%rsp), %rdi
callq 0x578e
leaq 0x2d44e(%rip), %rdi     # 0x324d8
leaq 0xa0(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x20fae
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x50bb
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50dc
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0xe0(%rsp), %rdi
callq 0x5bf6
leaq 0xe0(%rsp), %rdi
callq 0x6532
leaq 0x1c0(%rsp), %rdi
leaq 0x158(%rsp), %rdx
movq %rax, %rsi
callq 0x18486
leaq 0x1c0(%rsp), %rdi
callq 0x1860e
leaq 0xe0(%rsp), %rdi
callq 0x6538
testl %eax, %eax
jle 0x539c
leaq 0xe0(%rsp), %rdi
callq 0x6538
movslq %eax, %rsi
leaq 0x2d379(%rip), %rdi     # 0x324c0
callq 0x5740
leaq 0x2d31d(%rip), %rdi     # 0x32470
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x4620
leaq 0x2d334(%rip), %rdi     # 0x32498
xorl %esi, %esi
callq 0x4620
leaq 0xe0(%rsp), %rbx
leaq 0x1c0(%rsp), %r14
leaq -0x2e6(%rip), %r15      # 0x4e9c
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x6538
cltq
cmpq %rax, %rbp
jge 0x51ed
movq 0x2d326(%rip), %rax     # 0x324c0
leal 0x1(%rbp), %ecx
movl %ecx, 0x8(%rax,%r13)
movl $0x238, %edi            # imm = 0x238
callq 0x4430
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x182f8
movq 0x2d2ff(%rip), %rcx     # 0x324c0
leaq (%rcx,%r13), %rdi
addq $0x10, %rdi
addq %r13, %rcx
movq %r12, -0x10(%rdi)
xorl %esi, %esi
movq %r15, %rdx
callq 0x47e0
addq $0x18, %r13
incq %rbp
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x45c0
jmp 0x5184
xorl %r15d, %r15d
leaq 0xe0(%rsp), %rbx
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x6538
cltq
cmpq %rax, %r12
jge 0x524b
movq 0x2d2af(%rip), %rax     # 0x324c0
movq 0x10(%rax,%r15), %rdi
xorl %esi, %esi
callq 0x43b0
movq 0x2d29c(%rip), %rax     # 0x324c0
movq (%rax,%r15), %r14
testq %r14, %r14
je 0x5242
movq %r14, %rdi
callq 0x185a6
movl $0x238, %esi            # imm = 0x238
movq %r14, %rdi
callq 0x4460
incq %r12
addq $0x18, %r15
jmp 0x51fb
leaq 0x2d246(%rip), %rdi     # 0x32498
callq 0x4510
leaq 0x2d212(%rip), %rdi     # 0x32470
callq 0x4510
jmp 0x53ab
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 0x653c
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 0x52d2
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x52da
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 0x1fd18(%rip), %rsi     # 0x2501a
leaq 0x1fd16(%rip), %rdx     # 0x2501f
leaq 0x60(%rsp), %rdi
callq 0x578e
leaq 0x2d1be(%rip), %rdi     # 0x324d8
movq %rsp, %rdx
leaq 0x60(%rsp), %rcx
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x20fae
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x5346
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x535c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x1c0(%rsp), %rdi
cmpq %r15, %rdi
je 0x5379
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x53b8
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x53b8
leaq 0x1c0(%rsp), %rdi
xorl %esi, %esi
callq 0x1a1cc
leaq 0x1c0(%rsp), %rdi
callq 0x185a6
leaq 0xe0(%rsp), %rdi
callq 0x5ba0
leaq 0x158(%rsp), %rdi
callq 0x85e0
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 0x540b
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x540b
movq %rdx, %r14
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x5477
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x5477
movq %rdx, %r14
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x5448
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x5448
movq %rdx, %r14
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x552e
movq 0xb0(%rsp), %rsi
jmp 0x54b1
movq %rdx, %r14
movq %rax, %rbx
jmp 0x5494
jmp 0x54cb
movq %rdx, %r14
movq %rax, %rbx
movq 0x1c0(%rsp), %rdi
cmpq %r15, %rdi
je 0x5494
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x552e
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x552e
jmp 0x54cb
jmp 0x54fc
jmp 0x551b
jmp 0x54fc
movq %rdx, %r14
movq %rax, %rbx
jmp 0x5548
movq %rdx, %r14
movq %rax, %rbx
jmp 0x552e
movq %rdx, %r14
movq %rax, %rbx
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x553b
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x553b
movq %rdx, %r14
movq %rax, %rbx
jmp 0x553b
movq %rdx, %r14
movq %rax, %rbx
movl $0x238, %esi            # imm = 0x238
movq %r12, %rdi
callq 0x4460
jmp 0x5521
jmp 0x551b
movq %rdx, %r14
movq %rax, %rbx
leaq 0x1c0(%rsp), %rdi
callq 0x185a6
leaq 0xe0(%rsp), %rdi
callq 0x5ba0
leaq 0x158(%rsp), %rdi
callq 0x85e0
cmpl $0x1, %r14d
jne 0x5651
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 0x5702
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1fa95(%rip), %rsi     # 0x25020
leaq 0x1fa93(%rip), %rdx     # 0x25025
leaq 0x20(%rsp), %rdi
callq 0x578e
leaq 0x2cf35(%rip), %rdi     # 0x324d8
leaq 0x80(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movl $0x1, %esi
movl $0x1, %r8d
callq 0x20fae
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x55d7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x55f8
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4460
callq 0x4710
movl $0x1, %eax
jmp 0x53d4
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x5626
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x5626
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x564c
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x564c
movq %rax, %rbx
callq 0x4710
movq %rbx, %rdi
callq 0x4780
movq %rax, %rdi
callq 0x5783
nop