// File: /workspace/github_c_makefile_star2_O2/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), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x6fe7c
movq %rsi, %r14
movl %edi, %ebp
movq 0x85235(%rip), %rax     # 0xf4f20
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x26500
leaq (%rbx,%rax), %rcx
movq %rcx, 0x10(%rsp)
addq %rax, %rbx
incq %rbx
movslq %ebp, %r13
xorl %r12d, %r12d
cmpq %r13, %r12
setge %al
movq (%r14,%r12,8), %r15
testq %r15, %r15
sete %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x6fd49
testq %r15, %r15
je 0x6fd44
cmpq %rbx, %r15
jb 0x6fd44
movq %r15, %rdi
callq 0x26500
leaq (%r15,%rax), %rbx
incq %rbx
incq %r12
jmp 0x6fd14
movq (%rsp), %r12
movq (%r12), %r15
testq %r15, %r15
je 0x6fd70
cmpq %rbx, %r15
jb 0x6fd6a
movq %r15, %rdi
callq 0x26500
leaq (%r15,%rax), %rbx
incq %rbx
addq $0x8, %r12
jmp 0x6fd4d
movq 0x8(%rsp), %rdi
callq 0x268b0
movq %rax, 0x9e9cf(%rip)     # 0x10e750
testq %rax, %rax
je 0x6fe7c
movq 0x8522f(%rip), %r15     # 0xf4fc0
movq (%r15), %rdi
callq 0x268b0
testq %rax, %rax
je 0x6fe7c
movq %rax, (%r15)
movq 0x85194(%rip), %r15     # 0xf4f40
movq (%r15), %rdi
callq 0x268b0
testq %rax, %rax
je 0x6fe7c
movq %rax, (%r15)
callq 0x263a0
pushq $0x3d
popq %rbp
movq (%rsp), %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x6fe17
movl %ebp, %esi
callq 0x267f0
testq %rax, %rax
je 0x6fe11
movq %rax, %r12
movb $0x0, (%rax)
movq (%r15), %rdi
movq %rax, %rsi
incq %rsi
pushq $0x1
popq %rdx
callq 0x26830
testl %eax, %eax
je 0x6fe0c
callq 0x26880
cmpl $0x0, (%rax)
movb $0x3d, (%r12)
je 0x6fe11
jmp 0x6fe6e
movb $0x3d, (%r12)
addq $0x8, %r15
jmp 0x6fdcc
pushq $0x1
popq %r15
movq (%r14,%r15,8), %rdi
cmpq %r13, %r15
jge 0x6fe2b
testq %rdi, %rdi
jne 0x6fe30
jmp 0x6fe3e
testq %rdi, %rdi
je 0x6fe4d
callq 0x268b0
testq %rax, %rax
je 0x6fe43
movq %rax, (%r14,%r15,8)
incq %r15
jmp 0x6fe1b
callq 0x26880
cmpl $0x0, (%rax)
jne 0x6fe7c
movq 0x10(%rsp), %rax
movq %rax, 0x9e90f(%rip)     # 0x10e768
movq 0x8(%rsp), %rax
movq %rax, 0x9e8f3(%rip)     # 0x10e758
movq %rbx, 0x9e8f4(%rip)     # 0x10e760
jmp 0x6fe7c
movq 0x850ab(%rip), %rax     # 0xf4f20
movq (%rsp), %rcx
movq %rcx, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq