// File: tylerkaraszewski[P]Argyle/main.cpp
// Function: main
int main(int argc, char *argv[])
{
  signal(SIGPIPE, SIG_IGN);
  signal(SIGINT, sigHandler);
  signal(SIGTERM, sigHandler);

  if (daemon(0, 0) == -1)
  {
    return 5; // No logfiles yet.
  }

  Config config(configPath);
  Logger logger(config);
  logger.open();
  
  server = new Server(80, logger, config);
  if (!server->bindPort())
  {
    return 1;
  }
  if (!logger.open())
  {
    return 2;
  }
  else if (!setUser(config.getString(Config::S_KEY_RUN_AS_USERNAME).c_str(), logger))
  {
    return 3;
  }
  else if (!server->start())
  {
    return 4;
  }
  //@TODO: Set user back to root so Server destructor can clean up effectively (may not be nessecary?).
  delete server;
  server = NULL;
  logger.close();
  return 0;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movl $0x0, 0x104(%rsp)
movl %edi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movl $0xd, %edi
movl $0x1, %esi
callq 0x4490
movl $0x2, %edi
leaq -0x88c(%rip), %rsi      # 0x9c50
callq 0x4490
movl $0xf, %edi
leaq -0x89d(%rip), %rsi      # 0x9c50
callq 0x4490
xorl %esi, %esi
movl %esi, %edi
callq 0x44b0
cmpl $-0x1, %eax
jne 0xa510
movl $0x5, 0x104(%rsp)
jmp 0xa7e2
movq 0xeec1(%rip), %rax      # 0x193d8
movq %rax, 0x20(%rsp)
leaq 0x87(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x46c0
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x88(%rsp), %rdi
callq 0x6450
jmp 0xa547
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x11380
jmp 0xa55e
leaq 0x88(%rsp), %rdi
callq 0x4788
leaq 0x87(%rsp), %rdi
callq 0x4400
leaq 0x58(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x10af0
jmp 0xa58c
leaq 0x58(%rsp), %rdi
callq 0x10b20
jmp 0xa598
movl $0x68, %edi
callq 0x43b0
movq %rax, 0x18(%rsp)
jmp 0xa5a9
movq 0x18(%rsp), %rdi
movl $0x50, %esi
leaq 0x58(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
callq 0x4e60
jmp 0xa5c7
movq 0x18(%rsp), %rax
movq %rax, 0xee1d(%rip)      # 0x193f0
movq 0xee16(%rip), %rdi      # 0x193f0
callq 0x4f00
movb %al, 0x17(%rsp)
jmp 0xa5e5
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0xa67d
jmp 0xa5f3
movl $0x1, 0x104(%rsp)
movl $0x1, 0x54(%rsp)
jmp 0xa7c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
jmp 0xa636
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x4788
leaq 0x87(%rsp), %rdi
callq 0x4400
jmp 0xa7f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
jmp 0xa7d3
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
movl $0x68, %esi
callq 0x43c0
jmp 0xa7d3
leaq 0x58(%rsp), %rdi
callq 0x10b20
movb %al, 0x16(%rsp)
jmp 0xa68d
movb 0x16(%rsp), %al
testb $0x1, %al
jne 0xa6af
jmp 0xa697
movl $0x2, 0x104(%rsp)
movl $0x1, 0x54(%rsp)
jmp 0xa7c4
leaq 0xee22(%rip), %rdx      # 0x194d8
leaq 0x30(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x11c60
jmp 0xa6ca
leaq 0x30(%rsp), %rdi
callq 0x4190
movq %rax, %rdi
leaq 0x58(%rsp), %rsi
callq 0x9c70
movb %al, 0x15(%rsp)
jmp 0xa6e7
movb 0x15(%rsp), %al
xorb $-0x1, %al
movb %al, 0x14(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x4788
movb 0x14(%rsp), %al
testb $0x1, %al
jne 0xa705
jmp 0xa73a
movl $0x3, 0x104(%rsp)
movl $0x1, 0x54(%rsp)
jmp 0xa7c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x4788
jmp 0xa7d3
movq 0xecaf(%rip), %rdi      # 0x193f0
callq 0x5400
movb %al, 0x13(%rsp)
jmp 0xa74c
movb 0x13(%rsp), %al
testb $0x1, %al
jne 0xa76b
jmp 0xa756
movl $0x4, 0x104(%rsp)
movl $0x1, 0x54(%rsp)
jmp 0xa7c4
jmp 0xa76d
jmp 0xa76f
movq 0xec7a(%rip), %rax      # 0x193f0
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0xa79a
movq 0x8(%rsp), %rdi
callq 0x6120
movq 0x8(%rsp), %rdi
movl $0x68, %esi
callq 0x43c0
movq $0x0, 0xec4b(%rip) # 0x193f0
leaq 0x58(%rsp), %rdi
callq 0x10ca0
jmp 0xa7b1
movl $0x0, 0x104(%rsp)
movl $0x1, 0x54(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xa800
jmp 0xa7e2
leaq 0xa8(%rsp), %rdi
callq 0xa800
jmp 0xa7f1
movl 0x104(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
movq 0x78(%rsp), %rdi
callq 0x46b0
nopl (%rax,%rax)