// File: /workspace/github_cpp_makefile_star2_O1/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 $0x168, %rsp            # imm = 0x168
movq %rsi, %r14
movl $0x1, %esi
movl $0x11, %edi
callq 0x20b0
callq 0x2180
testl %eax, %eax
je 0x23bc
xorl %ebx, %ebx
cmpl $-0x2, %ebx
je 0x266e
callq 0x2180
decl %ebx
testl %eax, %eax
jne 0x239d
cmpl $-0x2, %ebx
setb %r13b
negl %ebx
jmp 0x23c1
xorl %r13d, %r13d
xorl %ebx, %ebx
leaq 0xc3c(%rip), %rsi       # 0x3004
leaq -0x190(%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 -0x48(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xc21(%rip), %rsi       # 0x301f
leaq 0xc30(%rip), %rdx       # 0x3035
leaq -0x58(%rbp), %r14
movq %r14, %rdi
callq 0x27a4
leaq -0x88(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x270a
leaq -0x168(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2868
movq -0x98(%rbp), %rdi
cmpq %r15, %rdi
je 0x2460
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2080
leaq 0xbcf(%rip), %rdx       # 0x3036
leaq -0x168(%rbp), %rdi
movl $0x2762, %esi           # imm = 0x2762
callq 0x2b40
leaq 0xbb7(%rip), %rdx       # 0x3036
leaq -0x168(%rbp), %rdi
movl $0x272f, %esi           # imm = 0x272F
callq 0x2b40
leaq -0x168(%rbp), %rdi
callq 0x2a18
movl $0x400, %edi            # imm = 0x400
callq 0x2150
leaq -0x38(%rbp), %rdx
movq %rax, (%rdx)
leaq -0x168(%rbp), %rdi
movl $0x100001, %esi         # imm = 0x100001
callq 0x2a8c
movq -0x38(%rbp), %rsi
leaq 0xb79(%rip), %rdi       # 0x3042
xorl %eax, %eax
callq 0x2060
leaq -0xb8(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x2ad4
leaq -0x168(%rbp), %rdi
callq 0x2b36
movq %rax, %r14
movq -0xb8(%rbp), %rsi
leaq 0xb59(%rip), %rdi       # 0x3059
xorl %eax, %eax
callq 0x2060
leaq 0xb64(%rip), %rdi       # 0x3072
movq %r14, %rsi
xorl %eax, %eax
callq 0x2060
leaq -0x168(%rbp), %rdi
callq 0x2a9c
testl %eax, %eax
je 0x256c
leaq -0x78(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x2aa6
leaq -0x68(%rbp), %rbx
movq -0x10(%rbx), %rsi
leaq 0xb88(%rip), %rdi       # 0x30cf
xorl %eax, %eax
callq 0x2060
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x261f
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2080
jmp 0x261f
movl %r13d, -0x2c(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x2b08
leaq 0xaff(%rip), %rsi       # 0x3086
leaq -0xc2(%rbp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x21a0
leaq 0xaf0(%rip), %rsi       # 0x3091
movq %r14, %rdi
callq 0x21f0
movq %rax, %r15
leaq -0x68(%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 0xaba(%rip), %rdi       # 0x3093
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2060
movq %r15, %rdi
callq 0x20d0
leaq 0xab5(%rip), %rdi       # 0x30aa
movl %ebx, %esi
xorl %eax, %eax
callq 0x2060
leaq -0x68(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2617
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2080
leaq -0x48(%rbp), %r12
movl -0x2c(%rbp), %r13d
movl $0xa, %edi
callq 0x21c0
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2648
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2080
leaq -0x168(%rbp), %rdi
callq 0x2b7e
movq -0x58(%rbp), %rdi
cmpq %r12, %rdi
je 0x2669
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2080
testb %r13b, %r13b
je 0x2675
xorl %edi, %edi
callq 0x2030
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x26b6
jmp 0x26b6
jmp 0x26da
jmp 0x26da
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r15, %rdi
je 0x26e9
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2080
jmp 0x26e9
movq %rax, %rbx
jmp 0x26e9
movq %rax, %rbx
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x26dd
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2080
jmp 0x26dd
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x2b7e
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x2702
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2080
movq %rbx, %rdi
callq 0x2100