// File: /workspace/github_c_makefile_star2_O1/dxwc[P]sfeed/sfeed_frames.c
// Function: main
int
main(int argc, char *argv[])
{
	FILE *fpindex, *fpitems, *fpmenu = NULL, *fp;
	char *name;
	int i, showsidebar = (argc > 1);
	struct feed *f;

	if (pledge("stdio rpath wpath cpath", NULL) == -1)
		err(1, "pledge");

	if (!(feeds = calloc(argc, sizeof(struct feed *))))
		err(1, "calloc");

	if ((comparetime = time(NULL)) == -1)
		err(1, "time");
	/* 1 day is old news */
	comparetime -= 86400;

	/* write main index page */
	if (!(fpindex = fopen("index.html", "wb")))
		err(1, "fopen: index.html");
	if (!(fpitems = fopen("items.html", "wb")))
		err(1, "fopen: items.html");
	if (showsidebar && !(fpmenu = fopen("menu.html", "wb")))
		err(1, "fopen: menu.html");

	if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1)
		err(1, "pledge");

	fputs("<!DOCTYPE HTML>\n"
	      "<html>\n"
	      "\t<head>\n"
	      "\t<meta name=\"referrer\" content=\"no-referrer\" />\n"
	      "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
	      "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n"
	      "</head>\n"
	      "<body class=\"frame\"><div id=\"items\"><pre>\n", fpitems);

	if (argc == 1) {
		if (!(feeds[0] = calloc(1, sizeof(struct feed))))
			err(1, "calloc");
		feeds[0]->name = "";
		printfeed(fpitems, stdin, feeds[0]);
	} else {
		for (i = 1; i < argc; i++) {
			if (!(feeds[i - 1] = calloc(1, sizeof(struct feed))))
				err(1, "calloc");
			name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i];
			feeds[i - 1]->name = name;

			if (!(fp = fopen(argv[i], "r")))
				err(1, "fopen: %s", argv[i]);
			printfeed(fpitems, fp, feeds[i - 1]);
			if (ferror(fp))
				err(1, "ferror: %s", argv[i]);
			fclose(fp);
		}
	}
	fputs("</pre>\n</div></body>\n</html>\n", fpitems); /* div items */

	if (showsidebar) {
		fputs("<!DOCTYPE HTML>\n"
		      "<html>\n"
		      "<head>\n"
		      "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
		      "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n"
		      "</head>\n"
		      "<body class=\"frame\">\n<div id=\"sidebar\">\n", fpmenu);

		for (i = 1; i < argc; i++) {
			f = feeds[i - 1];
			if (f->totalnew)
				fputs("<a class=\"n\" href=\"items.html#", fpmenu);
			else
				fputs("<a href=\"items.html#", fpmenu);
			xmlencode(f->name, fpmenu);
			fputs("\" target=\"items\">", fpmenu);
			if (f->totalnew > 0)
				fputs("<b><u>", fpmenu);
			xmlencode(f->name, fpmenu);
			fprintf(fpmenu, " (%lu)", f->totalnew);
			if (f->totalnew > 0)
				fputs("</u></b>", fpmenu);
			fputs("</a><br/>\n", fpmenu);
		}
		fputs("</div></body></html>\n", fpmenu);
	}
	fputs("<!DOCTYPE html>\n<html>\n<head>\n"
	      "\t<meta name=\"referrer\" content=\"no-referrer\" />\n"
	      "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
	      "\t<title>Newsfeed (", fpindex);
	fprintf(fpindex, "%lu", totalnew);
	fputs(")</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n"
	      "</head>\n", fpindex);
	if (showsidebar) {
		fputs("<frameset framespacing=\"0\" cols=\"250,*\" frameborder=\"1\">\n"
		      "\t<frame name=\"menu\" src=\"menu.html\" target=\"menu\">\n", fpindex);
	} else {
		fputs("<frameset framespacing=\"0\" cols=\"*\" frameborder=\"1\">\n", fpindex);
	}
	fputs(
	      "\t<frame name=\"items\" src=\"items.html\" target=\"items\">\n"
	      "</frameset>\n"
	      "</html>\n", fpindex);

	fclose(fpindex);
	fclose(fpitems);
	if (fpmenu)
		fclose(fpmenu);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movl %edi, %ebp
movslq %edi, %rdi
movl $0x8, %esi
callq 0x1100
movq %rax, 0x3e05(%rip)      # 0x5108
testq %rax, %rax
je 0x163b
xorl %edi, %edi
callq 0x1160
movq %rax, 0x3df6(%rip)      # 0x5110
cmpq $-0x1, %rax
je 0x1674
addq $-0x15180, %rax         # imm = 0xFFFEAE80
movq %rax, 0x3ddf(%rip)      # 0x5110
leaq 0x1cdd(%rip), %rdi      # 0x3015
leaq 0x1ccc(%rip), %rsi      # 0x300b
callq 0x1190
testq %rax, %rax
je 0x167d
movq %rax, %rbx
leaq 0x1cd0(%rip), %rdi      # 0x3027
leaq 0x1cad(%rip), %rsi      # 0x300b
callq 0x1190
movq %rax, (%rsp)
testq %rax, %rax
je 0x1686
cmpl $0x2, %ebp
jl 0x139c
leaq 0x1cbd(%rip), %rdi      # 0x3039
leaq 0x1c88(%rip), %rsi      # 0x300b
callq 0x1190
movq %rax, %r15
testq %rax, %rax
jne 0x139f
leaq 0x1c9b(%rip), %rsi      # 0x3032
jmp 0x1642
xorl %r15d, %r15d
leaq 0x1c9d(%rip), %rdi      # 0x3043
movq (%rsp), %rsi
callq 0x10c0
cmpl $0x1, %ebp
movq %rbx, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
jne 0x1404
movl $0x1, %edi
movl $0x60, %esi
callq 0x1100
movq 0x3d35(%rip), %rcx      # 0x5108
movq %rax, (%rcx)
testq %rax, %rax
je 0x163b
leaq 0x2084(%rip), %rdx      # 0x346a
movq %rdx, (%rax)
movq 0x3bf0(%rip), %rax      # 0x4fe0
movq (%rax), %rsi
movq (%rcx), %rdx
movq (%rsp), %rdi
callq 0x168f
jmp 0x14af
jle 0x14af
movl 0xc(%rsp), %ebp
decq %rbp
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x60, %esi
callq 0x1100
movq %rax, %r14
movq 0x3cdc(%rip), %rax      # 0x5108
movq %r14, (%rax,%rbx,8)
testq %r14, %r14
je 0x163b
movq 0x8(%r12,%rbx,8), %r13
movq %r13, %rdi
movl $0x2f, %esi
callq 0x10b0
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %r13, %rcx
movq %rcx, (%r14)
movq %r13, %rdi
leaq 0x1ce5(%rip), %rsi      # 0x3148
callq 0x1190
testq %rax, %rax
je 0x164e
movq %rax, %r14
movq 0x3c8d(%rip), %rax      # 0x5108
movq (%rax,%rbx,8), %rdx
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x168f
movq %r14, %rdi
callq 0x1060
testl %eax, %eax
jne 0x165c
movq %r14, %rdi
callq 0x1070
incq %rbx
cmpq %rbx, %rbp
jne 0x1413
leaq 0x1ca9(%rip), %rdi      # 0x315f
movq (%rsp), %rsi
callq 0x10c0
movl 0xc(%rsp), %ebx
cmpl $0x2, %ebx
jl 0x15b0
leaq 0x1caa(%rip), %rdi      # 0x317d
movq %r15, %rsi
callq 0x10c0
movl %ebx, %ebx
decq %rbx
leaq 0x1db5(%rip), %r13      # 0x329c
leaq 0x1dbe(%rip), %rbp      # 0x32ac
xorl %r14d, %r14d
movq 0x3c10(%rip), %rax      # 0x5108
movq (%rax,%r14,8), %r12
cmpq $0x0, 0x8(%r12)
leaq 0x1d65(%rip), %rdi      # 0x326e
je 0x1512
leaq 0x1d3d(%rip), %rdi      # 0x324f
movq %r15, %rsi
callq 0x10c0
movq (%r12), %rdi
movq %r15, %rsi
callq 0x1eef
leaq 0x1d56(%rip), %rdi      # 0x3283
movq %r15, %rsi
callq 0x10c0
cmpq $0x0, 0x8(%r12)
je 0x154c
leaq 0x1d51(%rip), %rdi      # 0x3295
movq %r15, %rsi
callq 0x10c0
movq (%r12), %rdi
movq %r15, %rsi
callq 0x1eef
movq 0x8(%r12), %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x1130
cmpq $0x0, 0x8(%r12)
je 0x1581
leaq 0x1d2a(%rip), %rdi      # 0x32a3
movq %r15, %rsi
callq 0x10c0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x10c0
incq %r14
cmpq %r14, %rbx
jne 0x14f1
leaq 0x1d18(%rip), %rdi      # 0x32b7
movq %r15, %rsi
callq 0x10c0
leaq 0x1e1a(%rip), %rbx      # 0x33c8
jmp 0x15b7
leaq 0x1e7e(%rip), %rbx      # 0x3435
leaq 0x1d0f(%rip), %rdi      # 0x32cd
movq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x10c0
movq 0x3b46(%rip), %rdx      # 0x5118
leaq 0x1d9c(%rip), %rsi      # 0x3375
movq %r14, %rdi
xorl %eax, %eax
callq 0x1130
leaq 0x1d8f(%rip), %rdi      # 0x3379
movq %r14, %rsi
callq 0x10c0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10c0
leaq 0x1e67(%rip), %rdi      # 0x346b
movq %r14, %rsi
callq 0x10c0
movq %r14, %rdi
callq 0x1070
movq (%rsp), %rdi
callq 0x1070
testq %r15, %r15
je 0x162a
movq %r15, %rdi
callq 0x1070
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19c2(%rip), %rsi      # 0x3004
movl $0x1, %edi
xorl %eax, %eax
callq 0x1180
movq 0x8(%r12,%rbx,8), %rdx
leaq 0x1af0(%rip), %rsi      # 0x314a
jmp 0x1668
movq 0x8(%r12,%rbx,8), %rdx
leaq 0x1aec(%rip), %rsi      # 0x3154
movl $0x1, %edi
xorl %eax, %eax
callq 0x1180
leaq 0x1e61(%rip), %rsi      # 0x34dc
jmp 0x1642
leaq 0x198a(%rip), %rsi      # 0x300e
jmp 0x1642
leaq 0x1993(%rip), %rsi      # 0x3020
jmp 0x1642