// File: /workspace/github_c_makefile_star2_O2/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, %ebx
leaq 0xcb9(%rip), %rdi       # 0x202c
callq 0x1030
testq %rax, %rax
leaq 0xd6b(%rip), %rcx       # 0x20ed
cmovneq %rax, %rcx
movq %rcx, 0x2d7b(%rip)      # 0x4108
movslq %ebx, %rdi
pushq $0x8
popq %rsi
movq %rdi, 0x8(%rsp)
callq 0x1100
movq %rax, 0x2d6c(%rip)      # 0x4110
testq %rax, %rax
je 0x15cc
xorl %edi, %edi
callq 0x1160
movq %rax, 0x2d5d(%rip)      # 0x4118
cmpq $-0x1, %rax
je 0x1610
addq $-0x15180, %rax         # imm = 0xFFFEAE80
movq %rax, 0x2d46(%rip)      # 0x4118
cmpl $0x1, %ebx
jne 0x1420
pushq $0x1
popq %rdi
pushq $0x60
popq %rsi
callq 0x1100
movq 0x2d27(%rip), %rcx      # 0x4110
movq %rax, (%rcx)
testq %rax, %rax
je 0x15cc
leaq 0xca4(%rip), %rcx       # 0x20a0
movq %rcx, (%rax)
movq 0x2bd2(%rip), %rcx      # 0x3fd8
movq (%rcx), %rdi
movq 0x2bd0(%rip), %rcx      # 0x3fe0
movq (%rcx), %rsi
movq %rax, %rdx
callq 0x1622
jmp 0x15b8
leaq 0xc25(%rip), %rdi       # 0x204c
leaq 0xc14(%rip), %rsi       # 0x2042
callq 0x1190
testq %rax, %rax
je 0x1619
movq %rax, %r15
pushq $0x1
popq %r13
movq %r13, %rbp
cmpq 0x8(%rsp), %rbp
jge 0x15b0
movq %r13, %rdi
pushq $0x60
popq %rsi
callq 0x1100
movq %rax, %rbx
movq 0x2caa(%rip), %rax      # 0x4110
movq %rbx, -0x8(%rax,%rbp,8)
testq %rbx, %rbx
je 0x15cc
movq (%rsp), %rax
movq (%rax,%rbp,8), %r14
movq %r14, %rdi
pushq $0x2f
popq %rsi
callq 0x10b0
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %r14, %rcx
movq %rcx, (%rbx)
movq %r14, %rdi
leaq 0xbb7(%rip), %rsi       # 0x2056
callq 0x1190
testq %rax, %rax
je 0x15f7
movq %rax, %r14
movq (%rbx), %rcx
movl $0x1001, %esi           # imm = 0x1001
leaq 0x10(%rsp), %r12
movq %r12, %rdi
leaq 0xb9b(%rip), %rdx       # 0x2062
xorl %eax, %eax
callq 0x10a0
movq %r12, %rdi
leaq 0xb6a(%rip), %rsi       # 0x2042
callq 0x1190
testq %rax, %rax
je 0x15d5
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1622
movq %r14, %rdi
callq 0x1060
testl %eax, %eax
jne 0x15e6
movq %r14, %rdi
callq 0x1070
movq %r12, %rdi
callq 0x1070
leaq 0xb5c(%rip), %rdi       # 0x207a
pushq $0x3
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
movq (%rbx), %r14
movq %r14, %rdi
callq 0x1080
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x12dc
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
movq 0x2bb4(%rip), %r8       # 0x4108
movq %r15, %rdi
leaq 0xb20(%rip), %rsi       # 0x207e
xorl %eax, %eax
callq 0x1130
movq (%rbx), %rcx
movl $0x1001, %esi           # imm = 0x1001
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
leaq 0xae6(%rip), %rdx       # 0x2062
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rdi
callq 0x1080
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x12dc
leaq 0xaec(%rip), %rdi       # 0x208c
movq %r15, %rsi
callq 0x10c0
incq %rbp
jmp 0x1446
movq %r15, %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 0xa68(%rip), %rsi       # 0x203b
jmp 0x15dc
leaq 0xa8d(%rip), %rsi       # 0x2069
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1180
movq (%rsp), %rax
movq (%rax,%rbp,8), %rdx
leaq 0xa7a(%rip), %rsi       # 0x206f
jmp 0x1606
movq (%rsp), %rax
movq (%rax,%rbp,8), %rdx
leaq 0xa52(%rip), %rsi       # 0x2058
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1180
leaq 0xa8f(%rip), %rsi       # 0x20a6
jmp 0x15dc
leaq 0xa25(%rip), %rsi       # 0x2045
jmp 0x15dc