// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rsi, 0x8(%rsp)
movl %edi, %ebx
movslq %edi, %rdi
movl $0x8, %esi
callq 0x10f0
movq %rax, 0x3e0b(%rip)      # 0x5100
testq %rax, %rax
je 0x1652
xorl %edi, %edi
callq 0x1150
movq %rax, 0x3dfc(%rip)      # 0x5108
cmpq $-0x1, %rax
je 0x1695
addq $-0x15180, %rax         # imm = 0xFFFEAE80
movq %rax, 0x3de5(%rip)      # 0x5108
leaq 0x1d07(%rip), %rdi      # 0x3031
leaq 0x1cf6(%rip), %rsi      # 0x3027
callq 0x1180
testq %rax, %rax
je 0x169e
movq %rax, %r14
leaq 0x1cfa(%rip), %rdi      # 0x3043
leaq 0x1cd7(%rip), %rsi      # 0x3027
callq 0x1180
testq %rax, %rax
je 0x16a7
movq %rax, %rbp
cmpl $0x2, %ebx
jl 0x1558
movq %r14, 0x18(%rsp)
leaq 0x1cdf(%rip), %rdi      # 0x3055
leaq 0x1caa(%rip), %rsi      # 0x3027
callq 0x1180
testq %rax, %rax
je 0x16b0
movq %rax, %r15
leaq 0x1cca(%rip), %rdi      # 0x305f
movq %rbp, %rsi
callq 0x10b0
movl %ebx, 0x14(%rsp)
movl %ebx, %eax
movq %rax, 0x20(%rsp)
leaq -0x1(%rax), %rbx
xorl %r14d, %r14d
movq %rbp, %r12
movl $0x1, %edi
movl $0x60, %esi
callq 0x10f0
movq %rax, %r13
movq 0x3d35(%rip), %rax      # 0x5100
movq %r13, (%rax,%r14,8)
testq %r13, %r13
je 0x1652
movq 0x8(%rsp), %rax
movq 0x8(%rax,%r14,8), %rbp
movq %rbp, %rdi
movl $0x2f, %esi
callq 0x10a0
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %rbp, %rcx
movq %rcx, (%r13)
movq %rbp, %rdi
leaq 0x1d5c(%rip), %rsi      # 0x3164
callq 0x1180
testq %rax, %rax
je 0x1665
movq %rax, %r13
movq 0x3ce0(%rip), %rax      # 0x5100
movq (%rax,%r14,8), %rdx
movq %r12, %rbp
movq %r12, %rdi
movq %r13, %rsi
callq 0x16b9
movq %r13, %rdi
callq 0x1050
testl %eax, %eax
jne 0x1678
movq %r13, %rdi
callq 0x1060
incq %r14
cmpq %r14, %rbx
jne 0x13af
leaq 0x1d1e(%rip), %rdi      # 0x317b
movq %rbp, %rsi
callq 0x10b0
cmpl $0x2, 0x14(%rsp)
jl 0x15c8
leaq 0x1d22(%rip), %rdi      # 0x3199
movq %r15, %rsi
callq 0x10b0
decq 0x20(%rsp)
leaq 0x1e2d(%rip), %r13      # 0x32b8
leaq 0x1e36(%rip), %rbp      # 0x32c8
xorl %r14d, %r14d
movq 0x3c64(%rip), %rax      # 0x5100
movq (%rax,%r14,8), %rbx
cmpq $0x0, 0x8(%rbx)
leaq 0x1dde(%rip), %rdi      # 0x328a
je 0x14b5
leaq 0x1db6(%rip), %rdi      # 0x326b
movq %r15, %rsi
callq 0x10b0
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x1f72
leaq 0x1dd0(%rip), %rdi      # 0x329f
movq %r15, %rsi
callq 0x10b0
cmpq $0x0, 0x8(%rbx)
je 0x14ed
leaq 0x1dcc(%rip), %rdi      # 0x32b1
movq %r15, %rsi
callq 0x10b0
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x1f72
movq 0x8(%rbx), %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x1120
cmpq $0x0, 0x8(%rbx)
je 0x151f
leaq 0x1da8(%rip), %rdi      # 0x32bf
movq %r15, %rsi
callq 0x10b0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x10b0
incq %r14
cmpq %r14, 0x20(%rsp)
jne 0x1495
leaq 0x1d94(%rip), %rdi      # 0x32d3
movq %r15, %rsi
callq 0x10b0
leaq 0x1e96(%rip), %rbx      # 0x33e4
movq 0x18(%rsp), %r14
movq %r12, %rbp
jmp 0x15d4
leaq 0x1b00(%rip), %rdi      # 0x305f
movq %rbp, %rsi
callq 0x10b0
cmpl $0x1, %ebx
jne 0x15ad
movl $0x1, %edi
movl $0x60, %esi
callq 0x10f0
movq 0x3b7e(%rip), %rcx      # 0x5100
movq %rax, (%rcx)
testq %rax, %rax
je 0x1652
leaq 0x1ef1(%rip), %rcx      # 0x3486
movq %rcx, (%rax)
movq 0x3a41(%rip), %rcx      # 0x4fe0
movq (%rcx), %rsi
movq %rbp, %rdi
movq %rax, %rdx
callq 0x16b9
leaq 0x1bc7(%rip), %rdi      # 0x317b
movq %rbp, %rsi
callq 0x10b0
leaq 0x1e8e(%rip), %rbx      # 0x3451
xorl %r15d, %r15d
jmp 0x15d4
leaq 0x1e82(%rip), %rbx      # 0x3451
movq 0x18(%rsp), %r14
leaq 0x1d0e(%rip), %rdi      # 0x32e9
movq %r14, %rsi
callq 0x10b0
movq 0x3b26(%rip), %rdx      # 0x5110
leaq 0x1da0(%rip), %rsi      # 0x3391
movq %r14, %rdi
xorl %eax, %eax
callq 0x1120
leaq 0x1d93(%rip), %rdi      # 0x3395
movq %r14, %rsi
callq 0x10b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10b0
leaq 0x1e6b(%rip), %rdi      # 0x3487
movq %r14, %rsi
callq 0x10b0
movq %r14, %rdi
callq 0x1060
movq %rbp, %rdi
callq 0x1060
testq %r15, %r15
je 0x1641
movq %r15, %rdi
callq 0x1060
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19c7(%rip), %rsi      # 0x3020
movl $0x1, %edi
xorl %eax, %eax
callq 0x1170
movq 0x8(%rsp), %rax
movq 0x8(%rax,%r14,8), %rdx
leaq 0x1af0(%rip), %rsi      # 0x3166
jmp 0x1689
movq 0x8(%rsp), %rax
movq 0x8(%rax,%r14,8), %rdx
leaq 0x1ae7(%rip), %rsi      # 0x3170
movl $0x1, %edi
xorl %eax, %eax
callq 0x1170
leaq 0x1e5c(%rip), %rsi      # 0x34f8
jmp 0x1659
leaq 0x1985(%rip), %rsi      # 0x302a
jmp 0x1659
leaq 0x198e(%rip), %rsi      # 0x303c
jmp 0x1659
leaq 0x1997(%rip), %rsi      # 0x304e
jmp 0x1659