// File: /workspace/github_c_makefile_star2_O1/jacereda[P]fsatrace/src/fsatrace.c
// Function: main
int
main(int argc, char *const argv[])
{
	int		     err;
	int		     rc = EXIT_FAILURE;
	const char *	     out;
	struct shm	     shm;
	size_t		     sz = 0;
	char		     envout[PATH_MAX + 8];
	const unsigned char *opts;
	char *		     bopts;
	int		     verr;
	char *const *	     args = argv + 4;
	unsigned	     nargs = argc - 4;

	static char s_buf[LOGSZ];

	if (argc < 5 || (strcmp(argv[3], "--") && strcmp(argv[3], "---")))
		fatal(
		    " usage: %s <options> <output> -- <cmdline>\n"
		    "  where <options> is a combination of the following characters:\n"
		    "   v: print args vector\n"
		    "   e: print verbose errors\n"
		    "   r: dump read operations\n"
		    "   w: dump write operations\n"
		    "   m: dump file move operations\n"
		    "   d: dump file delete operations\n"
		    "   q: dump file stat operations\n",
		    argv[0]);
	out = argv[2];
	if ((err = shmInit(&shm, out, LOGSZ, 1)))
		fatal("allocating shared memory (%d)", err);
	snprintf(envout, sizeof(envout), ENVOUT "=%s", out);
	putenv(envout);
	workaround(out);
	fflush(stdout);
	opts = (const unsigned char *)argv[1];
	bopts = shm.buf + 4;
	while (*opts)
		bopts[*opts++] = 1;

	if (bopts['v'])
		procDumpArgs(nargs, args);
	verr = bopts['e'];
	switch (procRun(nargs, args, &rc)) {
	case ERR_PROC_FORK:
		if (verr)
			aerror(nargs, args, "forking process");
		break;
	case ERR_PROC_EXEC:
		if (verr)
			aerror(nargs, args, "executing command: %d", rc);
		break;
	case ERR_PROC_SIGNALED:
		if (verr)
			aerror(nargs, args, "process signaled: %d", rc);
		break;
	case ERR_PROC_STOPPED:
		if (verr)
			aerror(nargs, args, "process stopped: %d", rc);
		break;
	case ERR_PROC_UNKNOWN:
		if (verr)
			aerror(nargs, args, "unknow process error");
		break;
	case ERR_PROC_WAIT:
		if (verr)
			aerror(nargs, args, "waiting for command completion");
		break;
	default:
		if (rc) {
			if (verr)
				aerror(nargs, args,
				    "command failed with code %d", rc);
		}
		if (strcmp(argv[3], "---")) {
			uniq(s_buf, &sz, shm.buf + 4 + 256, "", 0);
			dump(out, s_buf, sz);
		} else
			dump(out, shm.buf + 4 + 256, *(uint32_t *)shm.buf);
	}
	if ((err = shmTerm(&shm, 1)))
		error("freeing shared memory (%d)", err);
	return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2048, %rsp           # imm = 0x2048
movq %rsi, %r15
movl $0x1, 0xc(%rsp)
movq $0x0, 0x10(%rsp)
cmpl $0x5, %edi
jl 0x1683
movl %edi, %ebx
movq 0x18(%r15), %r14
leaq 0xbd6(%rip), %rsi       # 0x201d
movq %r14, %rdi
callq 0x1130
testl %eax, %eax
je 0x146a
leaq 0xbc2(%rip), %rsi       # 0x201c
movq %r14, %rdi
callq 0x1130
testl %eax, %eax
jne 0x1683
movq 0x10(%r15), %r14
leaq 0x18(%rsp), %rdi
movl $0x1000000, %edx        # imm = 0x1000000
movq %r14, %rsi
movl $0x1, %ecx
callq 0x1b10
testl %eax, %eax
jne 0x1694
leaq 0xce2(%rip), %rdx       # 0x2176
leaq 0x1040(%rsp), %r12
movl $0x1008, %esi           # imm = 0x1008
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x10e0
movq %r12, %rdi
callq 0x1120
movq 0x2b1b(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1170
movq 0x8(%r15), %rax
movq 0x18(%rsp), %r13
movb (%rax), %cl
testb %cl, %cl
je 0x14e9
incq %rax
movzbl %cl, %ecx
movb $0x1, 0x4(%r13,%rcx)
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x14d7
leaq 0x20(%r15), %r12
addl $-0x4, %ebx
cmpb $0x0, 0x7a(%r13)
je 0x1501
movl %ebx, %edi
movq %r12, %rsi
callq 0x1a1b
movb 0x69(%r13), %bpl
leaq 0xc(%rsp), %rdx
movl %ebx, %edi
movq %r12, %rsi
callq 0x1a2b
decl %eax
cmpl $0x5, %eax
ja 0x15c5
leaq 0xade(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb %bpl, %bpl
je 0x164a
leaq 0xc43(%rip), %rdx       # 0x2182
jmp 0x15b4
testb %bpl, %bpl
je 0x164a
leaq 0xc95(%rip), %rdx       # 0x21e6
jmp 0x15b4
testb %bpl, %bpl
je 0x164a
movl 0xc(%rsp), %ecx
leaq 0xc41(%rip), %rdx       # 0x21a8
jmp 0x1593
testb %bpl, %bpl
je 0x164a
movl 0xc(%rsp), %ecx
leaq 0xc40(%rip), %rdx       # 0x21bd
jmp 0x1593
testb %bpl, %bpl
je 0x164a
movl 0xc(%rsp), %ecx
leaq 0xbff(%rip), %rdx       # 0x2192
movl %ebx, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1735
jmp 0x164a
testb %bpl, %bpl
je 0x164a
leaq 0xc1d(%rip), %rdx       # 0x21d1
movl %ebx, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1735
jmp 0x164a
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
setne %al
testb %bpl, %bpl
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x15ee
leaq 0xc23(%rip), %rdx       # 0x2205
movl %ebx, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1735
movq 0x18(%r15), %rdi
leaq 0xa23(%rip), %rsi       # 0x201c
callq 0x1130
movq 0x18(%rsp), %rcx
leaq 0x104(%rcx), %rdx
testl %eax, %eax
je 0x163a
leaq 0x2b1b(%rip), %rbx      # 0x4130
leaq 0xc3e(%rip), %rcx       # 0x225a
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
xorl %r8d, %r8d
callq 0x17d5
movq (%r15), %rdx
movq %r14, %rdi
movq %rbx, %rsi
jmp 0x1645
movl (%rcx), %eax
movq %r14, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0x187d
leaq 0x18(%rsp), %rdi
movl $0x1, %esi
callq 0x1c47
testl %eax, %eax
je 0x166d
leaq 0xbbd(%rip), %rdi       # 0x2221
movl %eax, %esi
xorl %eax, %eax
callq 0x191e
movl 0xc(%rsp), %eax
addq $0x2048, %rsp           # imm = 0x2048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rsi
leaq 0x993(%rip), %rdi       # 0x2020
xorl %eax, %eax
callq 0x16a4
leaq 0xabd(%rip), %rdi       # 0x2158
movl %eax, %esi
xorl %eax, %eax
callq 0x16a4