// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/main.c
// Function: run_as_daemonize
static void run_as_daemonize()
{
#ifdef WINDOWS
	SERVICE_TABLE_ENTRY ServiceTable[2];

	ServiceTable[0].lpServiceName = DOHCLIENT_NAME;
	ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;

	ServiceTable[1].lpServiceName = NULL;
	ServiceTable[1].lpServiceProc = NULL;

	if (!StartServiceCtrlDispatcher(ServiceTable)) {
		loge("Cannot start service ctrl dispatcher\n");
	}
#else
	pid_t pid, sid;
	int dev_null;

	if (!conf.pid_file) {
		conf.pid_file = strdup(DEFAULT_PID_FILE);
	}

	pid = fork();
	if (pid < 0) {
		exit(1);
	}

	if (pid > 0) {
		if (conf.pid_file) {
			FILE* file = fopen(conf.pid_file, "w");
			if (file == NULL) {
				logc("Invalid pid file: %s\n", conf.pid_file);
				exit(1);
			}
			fprintf(file, "%d", (int)pid);
			fclose(file);
		}
		
		exit(0);
	}

	if (init_dohclient() != 0)
		exit(1);

	umask(0);

	if (!conf.log_file || !(*conf.log_file)) {
		open_syslog(DOHCLIENT_NAME);
	}

	sid = setsid();
	if (sid < 0) {
		exit(1);
	}

	if ((chdir("/")) < 0) {
		exit(1);
	}

	dev_null = open("/dev/null", O_WRONLY);
	if (dev_null) {
		dup2(dev_null, STDOUT_FILENO);
		dup2(dev_null, STDERR_FILENO);
	}
	else {
		close(STDOUT_FILENO);
		close(STDERR_FILENO);
	}

	close(STDIN_FILENO);

	if (do_loop() != 0) {
		loge("Service exit with error\n");
		exit(1);
	}

	uninit_dohclient();

	conf_free(&conf);

#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
cmpq $0x0, 0x11dd8(%rip)     # 0x41b38
jne 0x2fd75
leaq 0x9a0d(%rip), %rdi      # 0x39776
callq 0x3620
movq %rax, 0x11dc3(%rip)     # 0x41b38
callq 0x30f0
movl %eax, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
jge 0x2fd8d
movl $0x1, %edi
callq 0x3470
cmpl $0x0, -0x4(%rbp)
jle 0x2fe2d
cmpq $0x0, 0x11d99(%rip)     # 0x41b38
je 0x2fe26
movq 0x11d8c(%rip), %rdi     # 0x41b38
leaq 0x9c7a(%rip), %rsi      # 0x39a2d
callq 0x3440
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2fe08
jmp 0x2fdc5
movb $0x0, %al
callq 0x242d0
cmpl $0x2, (%rax)
jl 0x2fdfe
movq 0x11d60(%rip), %r9      # 0x41b38
movl $0x2, %edi
leaq 0x8dde(%rip), %rsi      # 0x38bc2
leaq 0x99a2(%rip), %rdx      # 0x3978d
movl $0x57c, %ecx            # imm = 0x57C
leaq 0x99a7(%rip), %r8       # 0x3979e
movb $0x0, %al
callq 0x243b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3470
movq -0x18(%rbp), %rdi
movl -0x4(%rbp), %edx
leaq 0x7fef(%rip), %rsi      # 0x37e05
movb $0x0, %al
callq 0x3530
movq -0x18(%rbp), %rdi
callq 0x33a0
xorl %edi, %edi
callq 0x3470
callq 0x2ff60
cmpl $0x0, %eax
je 0x2fe41
movl $0x1, %edi
callq 0x3470
xorl %edi, %edi
callq 0x35f0
cmpq $0x0, 0x11cf0(%rip)     # 0x41b40
je 0x2fe5e
movq 0x11ce7(%rip), %rax     # 0x41b40
cmpb $0x0, (%rax)
jne 0x2fe6a
leaq 0x9977(%rip), %rdi      # 0x397dc
callq 0x248b0
callq 0x33f0
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jge 0x2fe82
movl $0x1, %edi
callq 0x3470
leaq 0x81d0(%rip), %rdi      # 0x38059
callq 0x3540
cmpl $0x0, %eax
jge 0x2fe9d
movl $0x1, %edi
callq 0x3470
leaq 0x9910(%rip), %rdi      # 0x397b4
movl $0x1, %esi
movb $0x0, %al
callq 0x3280
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x2fed5
movl -0xc(%rbp), %edi
movl $0x1, %esi
callq 0x3340
movl -0xc(%rbp), %edi
movl $0x2, %esi
callq 0x3340
jmp 0x2fee9
movl $0x1, %edi
callq 0x3680
movl $0x2, %edi
callq 0x3680
xorl %edi, %edi
callq 0x3680
callq 0x308f0
cmpl $0x0, %eax
je 0x2ff3a
jmp 0x2fefc
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x2ff2e
movl $0x3, %edi
leaq 0x8cae(%rip), %rsi      # 0x38bc2
leaq 0x9872(%rip), %rdx      # 0x3978d
movl $0x5a5, %ecx            # imm = 0x5A5
leaq 0x9897(%rip), %r8       # 0x397be
movb $0x0, %al
callq 0x243b0
jmp 0x2ff30
movl $0x1, %edi
callq 0x3470
callq 0x33440
leaq 0x11be2(%rip), %rdi     # 0x41b28
callq 0x1de50
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)