// File: /workspace/github_c_makefile_star2_O3/dxwc[P]sfeed/sfeed_gph.c
// Function: main
int
main(int argc, char *argv[])
{
	FILE *fpitems, *fpindex, *fp;
	char *name, path[PATH_MAX + 1];
	int i;
	struct feed *f;

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

	if (!(prefixpath = getenv("SFEED_GPH_PATH")))
		prefixpath = "/";

	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;

	if (argc == 1) {
		if (pledge("stdio", NULL) == -1)
			err(1, "pledge");
		if (!(feeds[0] = calloc(1, sizeof(struct feed))))
			err(1, "calloc");
		feeds[0]->name = "";
		printfeed(stdout, stdin, feeds[0]);
	} else {
		/* write main index page */
		if (!(fpindex = fopen("index.gph", "wb")))
			err(1, "fopen: index.gph");

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

			if (!(fp = fopen(argv[i], "r")))
				err(1, "fopen: %s", argv[i]);

			snprintf(path, sizeof(path), "%s.gph", f->name);
			if (!(fpitems = fopen(path, "wb")))
				err(1, "fopen");
			printfeed(fpitems, fp, f);
			if (ferror(fp))
				err(1, "ferror: %s", argv[i]);
			fclose(fp);
			fclose(fpitems);

			/* append directory item to index */
			fprintf(fpindex, "[1|");
			gphlink(fpindex, f->name, strlen(f->name));
			fprintf(fpindex, " (%lu/%lu)|%s",
			        f->totalnew, f->total, prefixpath);
			snprintf(path, sizeof(path), "%s.gph", f->name);
			gphlink(fpindex, path, strlen(path));
			fputs("|server|port]\n", fpindex);
		}
		fclose(fpindex);
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movq %rsi, (%rsp)
movl %edi, %ebp
leaq 0x1c9c(%rip), %rdi      # 0x302c
callq 0x1030
testq %rax, %rax
leaq 0x1d62(%rip), %rcx      # 0x3101
cmovneq %rax, %rcx
movq %rcx, 0x3d5e(%rip)      # 0x5108
movslq %ebp, %rdi
movl $0x8, %esi
callq 0x1100
movq %rax, 0x3d52(%rip)      # 0x5110
testq %rax, %rax
je 0x15fd
xorl %edi, %edi
callq 0x1160
movq %rax, 0x3d43(%rip)      # 0x5118
cmpq $-0x1, %rax
je 0x1647
addq $-0x15180, %rax         # imm = 0xFFFEAE80
movq %rax, 0x3d2c(%rip)      # 0x5118
cmpl $0x1, %ebp
jne 0x143e
movl $0x1, %edi
movl $0x60, %esi
callq 0x1100
movq 0x3d09(%rip), %rcx      # 0x5110
movq %rax, (%rcx)
testq %rax, %rax
je 0x15fd
leaq 0x1c86(%rip), %rcx      # 0x30a0
movq %rcx, (%rax)
movq 0x3bb4(%rip), %rcx      # 0x4fd8
movq (%rcx), %rdi
movq 0x3bb2(%rip), %rcx      # 0x4fe0
movq (%rcx), %rsi
movq %rax, %rdx
callq 0x1659
jmp 0x15e9
leaq 0x1c07(%rip), %rdi      # 0x304c
leaq 0x1bf6(%rip), %rsi      # 0x3042
callq 0x1190
testq %rax, %rax
je 0x1650
movq %rax, %r14
cmpl $0x2, %ebp
jl 0x15e1
movl %ebp, %eax
decq %rax
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %r13
xorl %r12d, %r12d
movl $0x1, %edi
movl $0x60, %esi
callq 0x1100
movq %rax, %rbp
movq 0x3c7f(%rip), %rax      # 0x5110
movq %rbp, (%rax,%r12,8)
testq %rbp, %rbp
je 0x15fd
movq (%rsp), %rax
movq 0x8(%rax,%r12,8), %rbx
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x10b0
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %rbx, %rcx
movq %rcx, (%rbp)
movq %rbx, %rdi
leaq 0x1b89(%rip), %rsi      # 0x3056
callq 0x1190
testq %rax, %rax
je 0x1619
movq %rax, %r15
movq (%rbp), %rcx
movl $0x1001, %esi           # imm = 0x1001
movq %r13, %rdi
leaq 0x1b71(%rip), %rdx      # 0x3062
xorl %eax, %eax
callq 0x10a0
movq %r13, %rdi
leaq 0x1b40(%rip), %rsi      # 0x3042
callq 0x1190
testq %rax, %rax
je 0x1606
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x1659
movq %r15, %rdi
callq 0x1060
testl %eax, %eax
jne 0x162b
movq %r15, %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x1070
movl $0x3, %esi
movl $0x1, %edx
leaq 0x1b28(%rip), %rdi      # 0x307a
movq %r14, %rcx
callq 0x11c0
movq (%rbp), %rbx
movq %rbx, %rdi
callq 0x1080
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x12dc
movq 0x8(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq 0x3b85(%rip), %r8       # 0x5108
movq %r14, %rdi
leaq 0x1af1(%rip), %rsi      # 0x307e
xorl %eax, %eax
callq 0x1130
movq (%rbp), %rcx
movl $0x1001, %esi           # imm = 0x1001
movq %r13, %rdi
leaq 0x1abb(%rip), %rdx      # 0x3062
xorl %eax, %eax
callq 0x10a0
movq %r13, %rdi
callq 0x1080
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x12dc
leaq 0x1ac1(%rip), %rdi      # 0x308c
movq %r14, %rsi
callq 0x10c0
incq %r12
cmpq %r12, 0x8(%rsp)
jne 0x1478
movq %r14, %rdi
callq 0x1070
xorl %eax, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a37(%rip), %rsi      # 0x303b
jmp 0x160d
leaq 0x1a5c(%rip), %rsi      # 0x3069
movl $0x1, %edi
xorl %eax, %eax
callq 0x1180
movq (%rsp), %rax
movq 0x8(%rax,%r12,8), %rdx
leaq 0x1a2f(%rip), %rsi      # 0x3058
jmp 0x163b
movq (%rsp), %rax
movq 0x8(%rax,%r12,8), %rdx
leaq 0x1a34(%rip), %rsi      # 0x306f
movl $0x1, %edi
xorl %eax, %eax
callq 0x1180
leaq 0x1a58(%rip), %rsi      # 0x30a6
jmp 0x160d
leaq 0x19ee(%rip), %rsi      # 0x3045
jmp 0x160d