// File: /workspace/github_cpp_makefile_star2_O3/ammarfaizi2[P]TeaCurlCpp/main.cpp
// Function: main
int main(int argc, char *argv[]) {

	// Prevent defunct
	signal(SIGCHLD, SIG_IGN);

	for(int i = 0; i < 3; i++) {
		int pid = fork();
		if (pid == 0) {

			char process_name[32];
			sprintf(process_name, "child_%d --daemon --no-tty", i);
			memcpy(argv[0], process_name, sizeof(process_name));

			std::string url = "https://www.google.com";
			
			TeaCurl tch(url);
			tch.setOpt(CURLOPT_COOKIEJAR, "/tmp/cookie");
			tch.setOpt(CURLOPT_COOKIEFILE, "/tmp/cookie");
			tch.exec();
			
			char *effectiveURL = (char*)malloc(1024);
			tch.getInfo(CURLINFO_EFFECTIVE_URL, &effectiveURL);

			printf("Got effective URL: %s\n", effectiveURL);

			std::string responseHeader = tch.getResponseHeader();
			long httpCode = tch.getHttpCode();

			printf("Got response header:\n%s\n", responseHeader.c_str());
			printf("Got http code: %ld\n", httpCode);

			if (tch.getRes() == CURLE_OK) {
				std::string body = tch.getBody();
				char filename[10];
				sprintf(filename, "out_%d.tmp", i);
				FILE *h = fopen(filename, "w");
				const char *cstrBody = body.c_str();

				size_t length = strlen(cstrBody);
				fwrite(cstrBody, length, 1, h);
				printf("Wrote %ld bytes to %s\n", length, filename);
				fclose(h);
				printf("Child %d has finished its execution\n", i);
			} else {
				printf("An error occued: %s\n", tch.getError().c_str());
			}
			sleep(10);
			return 0;
		}
	}

	wait(NULL);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %r14
movl $0x1, %esi
movl $0x11, %edi
callq 0x20b0
xorl %ebx, %ebx
callq 0x2180
testl %eax, %eax
je 0x23b0
incl %ebx
cmpl $0x3, %ebx
jne 0x2394
xorl %edi, %edi
callq 0x2030
jmp 0x264a
leaq 0xc4d(%rip), %rsi       # 0x3004
leaq -0x180(%rbp), %r15
movq %r15, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x21a0
movq (%r14), %rax
movaps (%r15), %xmm0
movaps 0x10(%r15), %xmm1
movups %xmm0, (%rax)
movups %xmm1, 0x10(%rax)
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xc32(%rip), %rsi       # 0x301f
leaq 0xc41(%rip), %rdx       # 0x3035
leaq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0x277a
leaq -0x80(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x26dc
leaq -0x160(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x2840
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x2449
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2080
leaq 0xbe6(%rip), %rdx       # 0x3036
leaq -0x160(%rbp), %rdi
movl $0x2762, %esi           # imm = 0x2762
callq 0x2b18
leaq 0xbce(%rip), %rdx       # 0x3036
leaq -0x160(%rbp), %rdi
movl $0x272f, %esi           # imm = 0x272F
callq 0x2b18
leaq -0x160(%rbp), %rdi
callq 0x29f0
movl $0x400, %edi            # imm = 0x400
callq 0x2150
leaq -0x30(%rbp), %rdx
movq %rax, (%rdx)
leaq -0x160(%rbp), %rdi
movl $0x100001, %esi         # imm = 0x100001
callq 0x2a64
movq -0x30(%rbp), %rsi
leaq 0xb90(%rip), %rdi       # 0x3042
xorl %eax, %eax
callq 0x2060
leaq -0xb0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x2aac
leaq -0x160(%rbp), %rdi
callq 0x2b0e
movq %rax, %r14
movq -0xb0(%rbp), %rsi
leaq 0xb70(%rip), %rdi       # 0x3059
xorl %eax, %eax
callq 0x2060
leaq 0xb7b(%rip), %rdi       # 0x3072
movq %r14, %rsi
xorl %eax, %eax
callq 0x2060
leaq -0x160(%rbp), %rdi
callq 0x2a74
testl %eax, %eax
je 0x2555
leaq -0x70(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x2a7e
leaq -0x60(%rbp), %rbx
movq -0x10(%rbx), %rsi
leaq 0xb9f(%rip), %rdi       # 0x30cf
xorl %eax, %eax
callq 0x2060
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x2600
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2080
jmp 0x2600
leaq -0x70(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x2ae0
leaq 0xb1a(%rip), %rsi       # 0x3086
leaq -0xba(%rbp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x21a0
leaq 0xb0b(%rip), %rsi       # 0x3091
movq %r14, %rdi
callq 0x21f0
movq %rax, %r15
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %r12
movq %r12, %rdi
callq 0x20c0
movq %rax, %r13
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rcx
callq 0x21b0
leaq 0xad5(%rip), %rdi       # 0x3093
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2060
movq %r15, %rdi
callq 0x20d0
leaq 0xad0(%rip), %rdi       # 0x30aa
movl %ebx, %esi
xorl %eax, %eax
callq 0x2060
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x25fc
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2080
leaq -0x40(%rbp), %r12
movl $0xa, %edi
callq 0x21c0
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2629
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2080
leaq -0x160(%rbp), %rdi
callq 0x2b56
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x264a
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2080
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2688
jmp 0x2688
jmp 0x26ac
jmp 0x26ac
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x26bb
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2080
jmp 0x26bb
movq %rax, %rbx
jmp 0x26bb
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x26af
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2080
jmp 0x26af
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x2b56
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x26d4
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2080
movq %rbx, %rdi
callq 0x2100