// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/setproctitle.c
// Function: spt_init
void spt_init(int argc, char *argv[]) {
        char **envp = environ;
	char *base, *end, *nul, *tmp;
	int i, error;

	if (!(base = argv[0]))
		return;

	nul = &base[strlen(base)];
	end = nul + 1;

	for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
		if (!argv[i] || argv[i] < end)
			continue;

		end = argv[i] + strlen(argv[i]) + 1;
	}

	for (i = 0; envp[i]; i++) {
		if (envp[i] < end)
			continue;

		end = envp[i] + strlen(envp[i]) + 1;
	}

	if (!(SPT.arg0 = strdup(argv[0])))
		goto syerr;

#if __GLIBC__
	if (!(tmp = strdup(program_invocation_name)))
		goto syerr;

	program_invocation_name = tmp;

	if (!(tmp = strdup(program_invocation_short_name)))
		goto syerr;

	program_invocation_short_name = tmp;
#elif __APPLE__
	if (!(tmp = strdup(getprogname())))
		goto syerr;

	setprogname(tmp);
#endif


	if ((error = spt_copyenv(envp)))
		goto error;

	if ((error = spt_copyargs(argc, argv)))
		goto error;

	SPT.nul  = nul;
	SPT.base = base;
	SPT.end  = end;

	return;
syerr:
	error = errno;
error:
	SPT.error = error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq (%rsi), %rbx
testq %rbx, %rbx
je 0x2ffa5
movq %rsi, %r14
movl %edi, %ebp
movq 0x3e1a2(%rip), %rax     # 0x6dfa8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
callq 0x12250
leaq (%rbx,%rax), %rcx
movq %rcx, 0x10(%rsp)
leaq (%rbx,%rax), %r12
incq %r12
movslq %ebp, %r13
xorl %ebp, %ebp
cmpq %r13, %rbp
jl 0x2fe37
cmpq $0x0, (%r14,%rbp,8)
je 0x2fe59
movq (%r14,%rbp,8), %r15
testq %r15, %r15
je 0x2fe54
cmpq %r12, %r15
jb 0x2fe54
movq %r15, %rdi
callq 0x12250
leaq (%r15,%rax), %r12
incq %r12
incq %rbp
jmp 0x2fe2b
movq 0x8(%rsp), %rax
movq (%rax), %r15
testq %r15, %r15
je 0x2fe8b
leaq 0x8(%rax), %rbp
cmpq %r12, %r15
jb 0x2fe7e
movq %r15, %rdi
callq 0x12250
leaq (%r15,%rax), %r12
incq %r12
movq (%rbp), %r15
addq $0x8, %rbp
testq %r15, %r15
jne 0x2fe6a
movq %rbx, %rdi
callq 0x128e0
movq %rax, 0x5386e(%rip)     # 0x83708
testq %rax, %rax
je 0x2ffa5
movq 0x3e106(%rip), %r15     # 0x6dfb0
movq (%r15), %rdi
callq 0x128e0
testq %rax, %rax
je 0x2ffa5
movq %rax, (%r15)
movq 0x3e113(%rip), %r15     # 0x6dfd8
movq (%r15), %rdi
callq 0x128e0
testq %rax, %rax
je 0x2ffa5
movq %rax, (%r15)
callq 0x12240
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2ff42
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rbp
movl $0x3d, %esi
callq 0x122b0
testq %rax, %rax
je 0x2ff35
movq %rax, %r15
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq %rax, %rsi
incq %rsi
movl $0x1, %edx
callq 0x121d0
testl %eax, %eax
je 0x2ff31
callq 0x120d0
cmpl $0x0, (%rax)
movb $0x3d, (%r15)
je 0x2ff35
jmp 0x2ff96
movb $0x3d, (%r15)
movq (%rbp), %rdi
addq $0x8, %rbp
testq %rdi, %rdi
jne 0x2fef4
movl $0x1, %r15d
cmpq %r13, %r15
jl 0x2ff54
cmpq $0x0, (%r14,%r15,8)
je 0x2ff7a
movq (%r14,%r15,8), %rdi
testq %rdi, %rdi
je 0x2ff6b
callq 0x128e0
testq %rax, %rax
je 0x2ff70
movq %rax, (%r14,%r15,8)
incq %r15
jmp 0x2ff48
callq 0x120d0
cmpl $0x0, (%rax)
jne 0x2ffa5
movq 0x10(%rsp), %rax
movq %rax, 0x5379a(%rip)     # 0x83720
movq %rbx, 0x53783(%rip)     # 0x83710
movq %r12, 0x53784(%rip)     # 0x83718
jmp 0x2ffa5
movq 0x3e00b(%rip), %rax     # 0x6dfa8
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq