// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0x7c9ac
movq %rsi, %r14
movl %edi, %ebp
movq 0x80732(%rip), %rax     # 0xfcf20
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
callq 0x26500
movq %rax, 0x10(%rsp)
leaq (%rbx,%rax), %r15
incq %r15
movslq %ebp, %r13
testl %r13d, %r13d
setle %al
movq (%r14), %r12
testq %r12, %r12
sete %cl
testb %cl, %al
jne 0x7c855
movl $0x1, %ebp
testq %r12, %r12
je 0x7c83e
cmpq %r15, %r12
jb 0x7c83e
movq %r12, %rdi
callq 0x26500
leaq (%r12,%rax), %r15
incq %r15
cmpq %r13, %rbp
setge %al
movq (%r14,%rbp,8), %r12
testq %r12, %r12
sete %cl
incq %rbp
testb %cl, %al
je 0x7c825
movq 0x8(%rsp), %rax
movq (%rax), %r12
testq %r12, %r12
je 0x7c887
leaq 0x8(%rax), %rbp
cmpq %r15, %r12
jb 0x7c87a
movq %r12, %rdi
callq 0x26500
leaq (%r12,%rax), %r15
incq %r15
movq (%rbp), %r12
addq $0x8, %rbp
testq %r12, %r12
jne 0x7c866
movq %rbx, %rdi
callq 0x268b0
movq %rax, 0x99eba(%rip)     # 0x116750
testq %rax, %rax
je 0x7c9ac
movq 0x8071a(%rip), %r12     # 0xfcfc0
movq (%r12), %rdi
callq 0x268b0
testq %rax, %rax
je 0x7c9ac
movq %rax, (%r12)
movq 0x8067d(%rip), %r12     # 0xfcf40
movq (%r12), %rdi
callq 0x268b0
testq %rax, %rax
je 0x7c9ac
movq %rax, (%r12)
callq 0x263a0
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x7c944
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rbp
movl $0x3d, %esi
callq 0x267f0
testq %rax, %rax
je 0x7c937
movq %rax, %r12
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq %rax, %rsi
incq %rsi
movl $0x1, %edx
callq 0x26830
testl %eax, %eax
je 0x7c932
callq 0x26880
cmpl $0x0, (%rax)
movb $0x3d, (%r12)
je 0x7c937
jmp 0x7c99d
movb $0x3d, (%r12)
movq (%rbp), %rdi
addq $0x8, %rbp
testq %rdi, %rdi
jne 0x7c8f4
addq %rbx, 0x10(%rsp)
movl $0x1, %r12d
movq (%r14,%r12,8), %rdi
cmpq %r13, %r12
jge 0x7c95f
testq %rdi, %rdi
jne 0x7c964
jmp 0x7c972
testq %rdi, %rdi
je 0x7c981
callq 0x268b0
testq %rax, %rax
je 0x7c977
movq %rax, (%r14,%r12,8)
incq %r12
jmp 0x7c94f
callq 0x26880
cmpl $0x0, (%rax)
jne 0x7c9ac
movq 0x10(%rsp), %rax
movq %rax, 0x99ddb(%rip)     # 0x116768
movq %rbx, 0x99dc4(%rip)     # 0x116758
movq %r15, 0x99dc5(%rip)     # 0x116760
jmp 0x7c9ac
movq 0x8057c(%rip), %rax     # 0xfcf20
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq