// File: /workspace/github_c_makefile_star2_O2/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, %r13
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x10f0
movq %rax, 0x3e0c(%rip)      # 0x5100
testq %rax, %rax
je 0x1620
xorl %edi, %edi
callq 0x1150
movq %rax, 0x3dfd(%rip)      # 0x5108
cmpq $-0x1, %rax
je 0x1653
addq $-0x15180, %rax         # imm = 0xFFFEAE80
movq %rax, 0x3de6(%rip)      # 0x5108
leaq 0x1d08(%rip), %rdi      # 0x3031
leaq 0x1cf7(%rip), %rsi      # 0x3027
callq 0x1180
testq %rax, %rax
je 0x165c
movq %rax, %rbx
leaq 0x1cfb(%rip), %rdi      # 0x3043
leaq 0x1cd8(%rip), %rsi      # 0x3027
callq 0x1180
movq %rax, (%rsp)
testq %rax, %rax
je 0x1665
cmpl $0x2, %ebp
jl 0x138d
leaq 0x1ce8(%rip), %rdi      # 0x3055
leaq 0x1cb3(%rip), %rsi      # 0x3027
callq 0x1180
movq %rax, %r15
testq %rax, %rax
jne 0x1390
leaq 0x1cc6(%rip), %rsi      # 0x304e
jmp 0x1627
xorl %r15d, %r15d
leaq 0x1cc8(%rip), %rdi      # 0x305f
movq (%rsp), %rsi
callq 0x10b0
cmpl $0x1, %ebp
movq %rbx, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
jne 0x14de
pushq $0x1
popq %rdi
pushq $0x60
popq %rsi
callq 0x10f0
movq 0x3d3c(%rip), %rcx      # 0x5100
movq %rax, (%rcx)
testq %rax, %rax
je 0x1620
leaq 0x20af(%rip), %rcx      # 0x3486
movq %rcx, (%rax)
movq 0x3bff(%rip), %rcx      # 0x4fe0
movq (%rcx), %rsi
movq (%rsp), %rdi
movq %rax, %rdx
callq 0x166e
leaq 0x1d84(%rip), %rdi      # 0x317b
movq (%rsp), %rsi
callq 0x10b0
movl 0xc(%rsp), %ebx
cmpl $0x2, %ebx
jl 0x157d
leaq 0x1d85(%rip), %rdi      # 0x3199
movq %r15, %rsi
callq 0x10b0
movl %ebx, %r14d
decq %r14
leaq 0x1e8f(%rip), %r13      # 0x32b8
leaq 0x1e98(%rip), %rbp      # 0x32c8
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x1586
movq 0x3cbe(%rip), %rax      # 0x5100
movq (%rax,%rbx,8), %r12
cmpq $0x0, 0x8(%r12)
leaq 0x1e37(%rip), %rdi      # 0x328a
je 0x145c
leaq 0x1e0f(%rip), %rdi      # 0x326b
movq %r15, %rsi
callq 0x10b0
movq (%r12), %rdi
movq %r15, %rsi
callq 0x1e09
leaq 0x1e28(%rip), %rdi      # 0x329f
movq %r15, %rsi
callq 0x10b0
cmpq $0x0, 0x8(%r12)
je 0x1496
leaq 0x1e23(%rip), %rdi      # 0x32b1
movq %r15, %rsi
callq 0x10b0
movq (%r12), %rdi
movq %r15, %rsi
callq 0x1e09
movq 0x8(%r12), %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x1120
cmpq $0x0, 0x8(%r12)
je 0x14cb
leaq 0x1dfc(%rip), %rdi      # 0x32bf
movq %r15, %rsi
callq 0x10b0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x10b0
incq %rbx
jmp 0x1432
pushq $0x1
popq %rbp
cmpq %r13, %rbp
jge 0x13f0
pushq $0x1
popq %rdi
pushq $0x60
popq %rsi
callq 0x10f0
movq %rax, %r14
movq 0x3c01(%rip), %rax      # 0x5100
movq %r14, -0x8(%rax,%rbp,8)
testq %r14, %r14
je 0x1620
movq (%r12,%rbp,8), %rbx
movq %rbx, %rdi
pushq $0x2f
popq %rsi
callq 0x10a0
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %rbx, %rcx
movq %rcx, (%r14)
movq %rbx, %rdi
leaq 0x1c30(%rip), %rsi      # 0x3164
callq 0x1180
testq %rax, %rax
je 0x1631
movq %rax, %r14
movq 0x3bb4(%rip), %rax      # 0x5100
movq -0x8(%rax,%rbp,8), %rdx
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x166e
movq %r14, %rdi
callq 0x1050
testl %eax, %eax
jne 0x163e
movq %r14, %rdi
callq 0x1060
incq %rbp
jmp 0x14e1
leaq 0x1ecd(%rip), %rbx      # 0x3451
jmp 0x159c
leaq 0x1d46(%rip), %rdi      # 0x32d3
movq %r15, %rsi
callq 0x10b0
leaq 0x1e48(%rip), %rbx      # 0x33e4
leaq 0x1d46(%rip), %rdi      # 0x32e9
movq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x10b0
movq 0x3b59(%rip), %rdx      # 0x5110
leaq 0x1dd3(%rip), %rsi      # 0x3391
movq %r14, %rdi
xorl %eax, %eax
callq 0x1120
leaq 0x1dc6(%rip), %rdi      # 0x3395
movq %r14, %rsi
callq 0x10b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10b0
leaq 0x1e9e(%rip), %rdi      # 0x3487
movq %r14, %rsi
callq 0x10b0
movq %r14, %rdi
callq 0x1060
movq (%rsp), %rdi
callq 0x1060
testq %r15, %r15
je 0x160f
movq %r15, %rdi
callq 0x1060
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19f9(%rip), %rsi      # 0x3020
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1170
movq (%r12,%rbp,8), %rdx
leaq 0x1b2a(%rip), %rsi      # 0x3166
jmp 0x1649
movq (%r12,%rbp,8), %rdx
leaq 0x1b27(%rip), %rsi      # 0x3170
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1170
leaq 0x1e9e(%rip), %rsi      # 0x34f8
jmp 0x1627
leaq 0x19c7(%rip), %rsi      # 0x302a
jmp 0x1627
leaq 0x19d0(%rip), %rsi      # 0x303c
jmp 0x1627