// File: /workspace/github_c_makefile_star2_O3/hifi[P]whatever/whatever.c
// Function: main
int main(int argc, char **argv)
{
    pid_t pid;

    if (argc < 2)
        die("usage: %s <program> [args]\n", argv[0]);

    pid = fork();

    if (pid < 0)
        die("%s: failed to fork()\n", argv[0]);

    if (pid == 0) {
        /* child */
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        execv(argv[1], argv+1);
        die("%s: failed to execv()", argv[0]);
    } else {
        /* parent */
        waitpid(pid, NULL, 0);
        ptrace(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACESYSGOOD|PTRACE_O_TRACEFORK|PTRACE_O_TRACEEXEC);
        ptrace(PTRACE_SYSCALL, pid, NULL, NULL);

        while (1) {
            int status;
            pid_t trace_pid = waitpid(-1, &status, 0);

            if (trace_pid < 0) {
                kill(pid, SIGKILL);
                return 1;
            }

            if (WIFEXITED(status)) {
                if (trace_pid == pid)
                    break;

                continue;
            }

            if (WSTOPSIG(status) == (SIGTRAP|0x80)) {
                int syscall = ptrace(PTRACE_PEEKUSER, trace_pid, 8*ORIG_RAX, NULL);

                switch (syscall) {
                    case SYS_setresuid:
                    {
                        struct user_regs_struct regs;
                        ptrace(PTRACE_GETREGS, trace_pid, 0, &regs);

                        if (regs.rdi >= 0)
                            processes[trace_pid].ruid = regs.rdi;
                        if (regs.rsi >= 0)
                            processes[trace_pid].euid = regs.rsi;
                        if (regs.rdx >= 0)
                            processes[trace_pid].suid = regs.rdx;

                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, 0);
                        break;
                    }

                    case SYS_setresgid:
                    {
                        struct user_regs_struct regs;
                        ptrace(PTRACE_GETREGS, trace_pid, 0, &regs);

                        if (regs.rdi >= 0)
                            processes[trace_pid].rgid = regs.rdi;
                        if (regs.rsi >= 0)
                            processes[trace_pid].egid = regs.rsi;
                        if (regs.rdx >= 0)
                            processes[trace_pid].sgid = regs.rdx;

                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, 0);
                        break;
                    }

                    case SYS_getresuid:
                    {
                        struct user_regs_struct regs;
                        ptrace(PTRACE_GETREGS, trace_pid, 0, &regs);

                        if (regs.rdi > 0)
                            poke_short(trace_pid, regs.rdi, processes[trace_pid].ruid);

                        if (regs.rsi > 0)
                            poke_short(trace_pid, regs.rsi, processes[trace_pid].euid);

                        if (regs.rdx > 0)
                            poke_short(trace_pid, regs.rdx, processes[trace_pid].suid);

                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, 0);
                        break;
                    }

                    case SYS_getresgid:
                    {
                        struct user_regs_struct regs;
                        ptrace(PTRACE_GETREGS, trace_pid, 0, &regs);

                        if (regs.rdi > 0)
                            poke_short(trace_pid, regs.rdi, processes[trace_pid].rgid);

                        if (regs.rsi > 0)
                            poke_short(trace_pid, regs.rsi, processes[trace_pid].egid);

                        if (regs.rdx > 0)
                            poke_short(trace_pid, regs.rdx, processes[trace_pid].sgid);

                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, 0);
                        break;
                    }

                    case SYS_getuid:
                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, processes[trace_pid].ruid);
                        break;
                    case SYS_getgid:
                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, processes[trace_pid].rgid);
                        break;
                    case SYS_geteuid:
                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, processes[trace_pid].euid);
                        break;
                    case SYS_getegid:
                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, processes[trace_pid].egid);
                        break;

                    case SYS_getgroups:
                    case SYS_setgroups:
                    case SYS_chown:
                    case SYS_fchown:
                    case SYS_lchown:
                    case SYS_fchownat:
                    case SYS_setreuid:
                    case SYS_setregid:
                    case SYS_setuid:
                    case SYS_setgid:
                        ptrace(PTRACE_POKEUSER, trace_pid, 8*RAX, 0);
                    default:
                        break;
                }
            } else {
                /* fork */
                pid_t child_pid;
                ptrace(PTRACE_GETEVENTMSG, trace_pid, 0, &child_pid);
                /* blindly forcing all children to think they are root initially */
                memset(&processes[child_pid], 0, sizeof(struct who));
                ptrace(PTRACE_SETOPTIONS, child_pid, NULL, PTRACE_O_TRACESYSGOOD|PTRACE_O_TRACEFORK|PTRACE_O_TRACEEXEC);
            }

            ptrace(PTRACE_SYSCALL, trace_pid, NULL, NULL);
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
cmpl $0x1, %edi
jle 0x401ad2
callq 0x44ec80
testl %eax, %eax
js 0x401ade
je 0x401aea
movl %eax, %ebx
movl %eax, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x44ebc0
movl $0x4200, %edi           # imm = 0x4200
movl %ebx, %esi
xorl %edx, %edx
movl $0x13, %ecx
xorl %eax, %eax
callq 0x450cd0
movl $0x18, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
leaq 0x4(%rsp), %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x44ebc0
testl %eax, %eax
js 0x401aab
movl %eax, %ebp
leaq 0x4(%rsp), %r14
leaq 0x9790d(%rip), %r12     # 0x499020
leaq 0xc9bd6(%rip), %r15     # 0x4cb2f0
leaq 0x10(%rsp), %r13
movl 0x4(%rsp), %eax
testb $0x7f, %al
je 0x40176c
andl $0xff00, %eax           # imm = 0xFF00
cmpl $0x8500, %eax           # imm = 0x8500
jne 0x401779
movl $0x3, %edi
movl %ebp, %esi
movl $0x78, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
leal -0x5c(%rax), %ecx
cmpl $0x1c, %ecx
ja 0x4017be
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x6, %edi
movl %ebp, %esi
movl $0x50, %edx
xorl %ecx, %ecx
jmp 0x401a79
cmpl %ebx, %ebp
jne 0x401a92
jmp 0x401ace
movl $0x4201, %edi           # imm = 0x4201
movl %ebp, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x450cd0
movslq 0x10(%rsp), %rsi
leaq (%rsi,%rsi,2), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%r15,%rax,8)
movq $0x0, 0x10(%r15,%rax,8)
movl $0x4200, %edi           # imm = 0x4200
xorl %edx, %edx
movl $0x13, %ecx
xorl %eax, %eax
callq 0x450cd0
jmp 0x401a80
cmpl $0x104, %eax            # imm = 0x104
jne 0x401a80
jmp 0x401759
movl $0xc, %edi
movl %ebp, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x450cd0
movl 0x80(%rsp), %eax
movl %ebp, %ecx
leaq (%rcx,%rcx,2), %rcx
movl %eax, 0xc(%r15,%rcx,8)
movl 0x78(%rsp), %eax
movl %eax, 0x10(%r15,%rcx,8)
movl 0x70(%rsp), %eax
movl %eax, 0x14(%r15,%rcx,8)
jmp 0x401759
movl $0xc, %edi
movl %ebp, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x450cd0
movq 0x80(%rsp), %r12
movl %ebp, %eax
testq %r12, %r12
movq %rax, 0x8(%rsp)
je 0x401877
movq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
movzwl 0xc(%r15,%rax,8), %r13d
movl $0x2, %edi
movl %ebp, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
andq $-0x10000, %rax         # imm = 0xFFFF0000
orq %rax, %r13
movl $0x5, %edi
movl %ebp, %esi
movq %r12, %rdx
movq %r13, %rcx
leaq 0x10(%rsp), %r13
xorl %eax, %eax
callq 0x450cd0
movq 0x8(%rsp), %rax
movq 0x78(%rsp), %r12
testq %r12, %r12
je 0x4018ca
movq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
movzwl 0x10(%r15,%rax,8), %r13d
movl $0x2, %edi
movl %ebp, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
andq $-0x10000, %rax         # imm = 0xFFFF0000
orq %rax, %r13
movl $0x5, %edi
movl %ebp, %esi
movq %r12, %rdx
movq %r13, %rcx
leaq 0x10(%rsp), %r13
xorl %eax, %eax
callq 0x450cd0
movq 0x8(%rsp), %rax
movq 0x70(%rsp), %r12
testq %r12, %r12
je 0x401a37
leaq (%rax,%rax,2), %rax
movzwl 0x14(%r15,%rax,8), %r13d
jmp 0x401a02
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
movl 0x4(%r15,%rax,8), %ecx
jmp 0x401a6d
movl $0xc, %edi
movl %ebp, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x450cd0
movl 0x80(%rsp), %eax
movl %ebp, %ecx
leaq (%rcx,%rcx,2), %rcx
movl %eax, (%r15,%rcx,8)
movl 0x78(%rsp), %eax
movl %eax, 0x4(%r15,%rcx,8)
movl 0x70(%rsp), %eax
movl %eax, 0x8(%r15,%rcx,8)
jmp 0x401759
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
movl (%r15,%rax,8), %ecx
jmp 0x401a6d
movl $0xc, %edi
movl %ebp, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x450cd0
movq 0x80(%rsp), %r12
testq %r12, %r12
je 0x4019a1
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
movzwl (%r15,%rax,8), %r13d
movl $0x2, %edi
movl %ebp, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
andq $-0x10000, %rax         # imm = 0xFFFF0000
orq %rax, %r13
movl $0x5, %edi
movl %ebp, %esi
movq %r12, %rdx
movq %r13, %rcx
leaq 0x10(%rsp), %r13
xorl %eax, %eax
callq 0x450cd0
movq 0x78(%rsp), %r12
testq %r12, %r12
je 0x4019ec
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
movzwl 0x4(%r15,%rax,8), %r13d
movl $0x2, %edi
movl %ebp, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
andq $-0x10000, %rax         # imm = 0xFFFF0000
orq %rax, %r13
movl $0x5, %edi
movl %ebp, %esi
movq %r12, %rdx
movq %r13, %rcx
leaq 0x10(%rsp), %r13
xorl %eax, %eax
callq 0x450cd0
movq 0x70(%rsp), %r12
testq %r12, %r12
je 0x401a37
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
movzwl 0x8(%r15,%rax,8), %r13d
movl $0x2, %edi
movl %ebp, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
andq $-0x10000, %rax         # imm = 0xFFFF0000
orq %rax, %r13
movl $0x5, %edi
movl %ebp, %esi
movq %r12, %rdx
movq %r13, %rcx
leaq 0x10(%rsp), %r13
xorl %eax, %eax
callq 0x450cd0
movl $0x6, %edi
movl %ebp, %esi
movl $0x50, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
leaq 0x975cd(%rip), %r12     # 0x499020
jmp 0x401a80
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
movl 0x10(%r15,%rax,8), %ecx
jmp 0x401a6d
movl %ebp, %eax
leaq (%rax,%rax,2), %rax
movl 0xc(%r15,%rax,8), %ecx
movl $0x6, %edi
movl %ebp, %esi
movl $0x50, %edx
xorl %eax, %eax
callq 0x450cd0
movl $0x18, %edi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %r14, %rsi
xorl %edx, %edx
callq 0x44ebc0
movl %eax, %ebp
testl %eax, %eax
jns 0x40171f
movl %ebx, %edi
movl $0x9, %esi
callq 0x40a3b0
movl $0x1, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x401abc
movq (%r14), %rsi
leaq 0x975b8(%rip), %rdi     # 0x499094
jmp 0x401b10
movq (%r14), %rsi
leaq 0x975c8(%rip), %rdi     # 0x4990b0
jmp 0x401b10
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450cd0
leaq 0x8(%r14), %rsi
movq 0x8(%r14), %rdi
callq 0x44f680
movq (%r14), %rsi
leaq 0x975b6(%rip), %rdi     # 0x4990c6
xorl %eax, %eax
callq 0x401b17