// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1080, %rsp           # imm = 0x1080
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x1c20(%rip), %rdi      # 0x3010
callq 0x1030
movq %rax, 0x3d1c(%rip)      # 0x5118
cmpq $0x0, %rax
jne 0x1410
leaq 0x1d3d(%rip), %rax      # 0x3146
movq %rax, 0x3d08(%rip)      # 0x5118
movslq -0x8(%rbp), %rdi
movl $0x8, %esi
callq 0x1110
movq %rax, 0x3cfb(%rip)      # 0x5120
cmpq $0x0, %rax
jne 0x143e
movl $0x1, %edi
leaq 0x1be8(%rip), %rsi      # 0x301f
movb $0x0, %al
callq 0x1190
xorl %eax, %eax
movl %eax, %edi
callq 0x1170
movq %rax, 0x3cda(%rip)      # 0x5128
cmpq $-0x1, %rax
jne 0x1467
movl $0x1, %edi
leaq 0x1c2a(%rip), %rsi      # 0x308a
movb $0x0, %al
callq 0x1190
movq 0x3cba(%rip), %rax      # 0x5128
subq $0x15180, %rax          # imm = 0x15180
movq %rax, 0x3cad(%rip)      # 0x5128
cmpl $0x1, -0x8(%rbp)
jne 0x14ef
movl $0x1, %edi
movl $0x60, %esi
callq 0x1110
movq 0x3c89(%rip), %rcx      # 0x5120
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x14b3
movl $0x1, %edi
leaq 0x1b73(%rip), %rsi      # 0x301f
movb $0x0, %al
callq 0x1190
movq 0x3c66(%rip), %rax      # 0x5120
movq (%rax), %rax
leaq 0x1bc0(%rip), %rcx      # 0x3084
movq %rcx, (%rax)
movq 0x3b0a(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq 0x3b08(%rip), %rax      # 0x4fe0
movq (%rax), %rsi
movq 0x3c3e(%rip), %rax      # 0x5120
movq (%rax), %rdx
callq 0x1810
jmp 0x17f7
leaq 0x1b3a(%rip), %rdi      # 0x3030
leaq 0x1b29(%rip), %rsi      # 0x3026
callq 0x11a0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x151f
movl $0x1, %edi
leaq 0x1b11(%rip), %rsi      # 0x3029
movb $0x0, %al
callq 0x1190
movl $0x1, -0x1044(%rbp)
movl -0x1044(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x17ee
movl $0x1, %edi
movl $0x60, %esi
callq 0x1110
movq 0x3bd2(%rip), %rcx      # 0x5120
movl -0x1044(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x1577
movl $0x1, %edi
leaq 0x1aaf(%rip), %rsi      # 0x301f
movb $0x0, %al
callq 0x1190
movq 0x3ba2(%rip), %rax      # 0x5120
movl -0x1044(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x1050(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1044(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl $0x2f, %esi
callq 0x10c0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x15c9
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1058(%rbp)
jmp 0x15df
movq -0x10(%rbp), %rax
movslq -0x1044(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x1058(%rbp)
movq -0x1058(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x1050(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movslq -0x1044(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1a2c(%rip), %rsi      # 0x303a
callq 0x11a0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x163f
movq -0x10(%rbp), %rax
movslq -0x1044(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl $0x1, %edi
leaq 0x1a04(%rip), %rsi      # 0x303c
movb $0x0, %al
callq 0x1190
leaq -0x1040(%rbp), %rdi
movq -0x1050(%rbp), %rax
movq (%rax), %rcx
movl $0x1001, %esi           # imm = 0x1001
leaq 0x19ea(%rip), %rdx      # 0x3046
movb $0x0, %al
callq 0x10b0
leaq -0x1040(%rbp), %rdi
leaq 0x19b5(%rip), %rsi      # 0x3026
callq 0x11a0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x1693
movl $0x1, %edi
leaq 0x19c1(%rip), %rsi      # 0x304d
movb $0x0, %al
callq 0x1190
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x1050(%rbp), %rdx
callq 0x1810
movq -0x28(%rbp), %rdi
callq 0x1070
cmpl $0x0, %eax
je 0x16d7
movq -0x10(%rbp), %rax
movslq -0x1044(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl $0x1, %edi
leaq 0x1983(%rip), %rsi      # 0x3053
movb $0x0, %al
callq 0x1190
movq -0x28(%rbp), %rdi
callq 0x1080
movq -0x18(%rbp), %rdi
callq 0x1080
movq -0x20(%rbp), %rdi
leaq 0x196a(%rip), %rsi      # 0x305e
movb $0x0, %al
callq 0x1140
movq -0x20(%rbp), %rax
movq %rax, -0x1078(%rbp)
movq -0x1050(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1070(%rbp)
movq -0x1050(%rbp), %rax
movq (%rax), %rdi
callq 0x1090
movq -0x1078(%rbp), %rdi
movq -0x1070(%rbp), %rsi
movq %rax, %rdx
callq 0x12f0
movq -0x20(%rbp), %rdi
movq -0x1050(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x1050(%rbp), %rax
movq 0x10(%rax), %rcx
movq 0x39bb(%rip), %r8       # 0x5118
leaq 0x18fe(%rip), %rsi      # 0x3062
movb $0x0, %al
callq 0x1140
leaq -0x1040(%rbp), %rdi
movq -0x1050(%rbp), %rax
movq (%rax), %rcx
movl $0x1001, %esi           # imm = 0x1001
leaq 0x18be(%rip), %rdx      # 0x3046
movb $0x0, %al
callq 0x10b0
movq -0x20(%rbp), %rax
movq %rax, -0x1068(%rbp)
leaq -0x1040(%rbp), %rax
movq %rax, -0x1060(%rbp)
leaq -0x1040(%rbp), %rdi
callq 0x1090
movq -0x1068(%rbp), %rdi
movq -0x1060(%rbp), %rsi
movq %rax, %rdx
callq 0x12f0
movq -0x20(%rbp), %rsi
leaq 0x189b(%rip), %rdi      # 0x3070
callq 0x10d0
movl -0x1044(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1044(%rbp)
jmp 0x1529
movq -0x20(%rbp), %rdi
callq 0x1080
xorl %eax, %eax
addq $0x1080, %rsp           # imm = 0x1080
popq %rbp
retq
nopw %cs:(%rax,%rax)