// File: /workspace/github_c_makefile_star2_O0/sos22[P]unexec/unexec.c
// Function: extract_new_environment
static void extract_new_environment(const void * bounce_area,
                                    struct new_environment * env) {
    unsigned long rsp = ((unsigned long *)bounce_area)[0];
    unsigned long argc = ((unsigned long *)bounce_area)[1];
    const char ** new_argv =
        (const char **)(bounce_area + 2 * sizeof(unsigned long));
    const char ** new_environ = new_argv + argc + 1;
    unsigned nr_environ;
    for (nr_environ = 0; new_environ[nr_environ]; nr_environ++) ;
    if (env) {
        unsigned needed = 0;
        /* argv pointers */
        needed += sizeof(env->argv[0]) * (argc + 1);
        /* environment pointers */
        needed += sizeof(env->environ[0]) * (nr_environ + 1);
        /* argv values */
        for (unsigned x = 0; x < argc; x++) {
            needed += strlen(translate_new_environment(bounce_area,
                                                       new_argv[x],
                                                       rsp)) + 1; }
        /* environ values */
        for (unsigned x = 0; x < nr_environ; x++) {
            needed += strlen(translate_new_environment(bounce_area,
                                                       new_environ[x],
                                                       rsp)) + 1; }
        void * buffer = alloc_with_mmap(needed);
        env->argc = argc;
        env->argv = buffer;
        buffer += sizeof(env->argv[0]) * (argc + 1);
        env->environ = buffer;
        buffer += sizeof(env->environ[0]) * (nr_environ + 1);
        for (unsigned x = 0; x < argc; x++) {
            const char * old = translate_new_environment(bounce_area,
                                                         new_argv[x],
                                                         rsp);
            size_t sz = strlen(old);
            env->argv[x] = buffer;
            memcpy(buffer, old, sz + 1);
            buffer += sz + 1; }
        for (unsigned x = 0; x < nr_environ; x++) {
            const char * old = translate_new_environment(bounce_area,
                                                         new_environ[x],
                                                         rsp);
            size_t sz = strlen(old);
            env->environ[x] = buffer;
            memcpy(buffer, old, sz + 1);
            buffer += sz + 1; } }
    const char * last_env = translate_new_environment(bounce_area,
                                                      new_environ[nr_environ-1],
                                                      rsp);
    const void * bounce_end = last_env + strlen(last_env);
    bounce_end = (void *)(((unsigned long)bounce_end + PAGE_SIZE - 1) &
                          ~(PAGE_SIZE - 1));
    munmap((void *)bounce_area, bounce_end - bounce_area); }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x22ef
jmp 0x22e4
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x22d4
cmpq $0x0, -0x10(%rbp)
je 0x2515
movl $0x0, -0x38(%rbp)
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
shlq $0x3, %rcx
movl -0x38(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
shlq $0x3, %rcx
movl -0x38(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpq -0x20(%rbp), %rax
jae 0x2378
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rdx
callq 0x2da0
movq %rax, %rdi
callq 0x1070
movq %rax, %rcx
addq $0x1, %rcx
movl -0x38(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2334
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x23c2
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rdx
callq 0x2da0
movq %rax, %rdi
callq 0x1070
movq %rax, %rcx
addq $0x1, %rcx
movl -0x38(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x237f
movl -0x38(%rbp), %eax
movl %eax, %edi
callq 0x25a0
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
shlq $0x3, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
shlq $0x3, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpq -0x20(%rbp), %rax
jae 0x2498
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rdx
callq 0x2da0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1070
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq $0x1, %rdx
callq 0x1130
movq -0x60(%rbp), %rax
addq $0x1, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2423
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x2513
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rdx
callq 0x2da0
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x1070
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq $0x1, %rdx
callq 0x1130
movq -0x78(%rbp), %rax
addq $0x1, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x249f
jmp 0x2515
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rdx
callq 0x2da0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x80(%rbp), %rdi
callq 0x1070
movq %rax, %rcx
movq -0x90(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
addq $0x1000, %rax           # imm = 0x1000
subq $0x1, %rax
andq $-0x1000, %rax          # imm = 0xF000
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x8(%rbp), %rax
subq %rax, %rsi
callq 0x1140
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)