// File: /workspace/github_c_makefile_star2_O1/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 $0xf8, %rsp
movq %rsi, %r14
cmpl $0x1, %edi
jle 0x401b6b
callq 0x44ed00
testl %eax, %eax
js 0x401b77
je 0x401b83
movl %eax, %ebx
xorl %r13d, %r13d
movl %eax, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x44ec40
movl $0x4200, %edi           # imm = 0x4200
movl %ebx, %esi
xorl %edx, %edx
movl $0x13, %ecx
xorl %eax, %eax
callq 0x450d50
movl $0x18, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
leaq 0x1c(%rsp), %r14
leaq 0x97999(%rip), %r15     # 0x499094
xorl %ebp, %ebp
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %r14, %rsi
xorl %edx, %edx
callq 0x44ec40
testl %eax, %eax
js 0x40176d
movl %eax, %r12d
movl 0x1c(%rsp), %eax
testb $0x7f, %al
je 0x401789
andl $0xff00, %eax           # imm = 0xFF00
cmpl $0x8500, %eax           # imm = 0x8500
jne 0x40179f
movl $0x3, %edi
movl %r12d, %esi
movl $0x78, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
leal -0x5c(%rax), %ecx
cmpl $0x1c, %ecx
ja 0x4017ed
leaq 0x978d0(%rip), %rdx     # 0x499020
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0x6, %edi
movl %r12d, %esi
movl $0x50, %edx
xorl %ecx, %ecx
jmp 0x401b2f
movl %ebx, %edi
movl $0x9, %esi
callq 0x40a440
movl $0x1, %ebp
movl %ebp, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
xorl %eax, %eax
cmpl %ebx, %r12d
sete %al
orl $0x2, %eax
movl %eax, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x4201, %edi           # imm = 0x4201
movl %r12d, %esi
xorl %edx, %edx
leaq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x450d50
movslq 0x20(%rsp), %rsi
leaq (%rsi,%rsi,2), %rax
leaq 0xc9b2b(%rip), %rcx     # 0x4cb2f0
xorps %xmm0, %xmm0
movups %xmm0, (%rcx,%rax,8)
movq $0x0, 0x10(%rcx,%rax,8)
movl $0x4200, %edi           # imm = 0x4200
xorl %edx, %edx
movl $0x13, %ecx
xorl %eax, %eax
callq 0x450d50
jmp 0x401b36
cmpl $0x104, %eax            # imm = 0x104
jne 0x401b36
jmp 0x401759
movl $0xc, %edi
movl %r12d, %esi
xorl %edx, %edx
leaq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x450d50
movl 0x90(%rsp), %eax
movl %r12d, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq 0xc9ac8(%rip), %rdx     # 0x4cb2f0
movl %eax, 0xc(%rdx,%rcx,8)
movl 0x88(%rsp), %eax
movl %eax, 0x10(%rdx,%rcx,8)
movl 0x80(%rsp), %eax
movl %eax, 0x14(%rdx,%rcx,8)
jmp 0x401759
movl $0xc, %edi
movl %r12d, %esi
xorl %edx, %edx
leaq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x450d50
movq 0x90(%rsp), %r13
movl %r12d, %eax
testq %r13, %r13
movq %rax, 0x8(%rsp)
je 0x4018c5
movq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq 0xc9a6e(%rip), %rcx     # 0x4cb2f0
movzwl 0xc(%rcx,%rax,8), %eax
movq %rax, 0x10(%rsp)
movl $0x2, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
andq $-0x10000, %rax         # imm = 0xFFFF0000
movq 0x10(%rsp), %rcx
orq %rax, %rcx
movl $0x5, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x450d50
movq 0x8(%rsp), %rax
movq 0x88(%rsp), %r13
testq %r13, %r13
je 0x401925
movq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq 0xc9a0e(%rip), %rcx     # 0x4cb2f0
movzwl 0x10(%rcx,%rax,8), %eax
movq %rax, 0x10(%rsp)
movl $0x2, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
andq $-0x10000, %rax         # imm = 0xFFFF0000
movq 0x10(%rsp), %rcx
orq %rax, %rcx
movl $0x5, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x450d50
movq 0x8(%rsp), %rax
movq 0x80(%rsp), %r13
testq %r13, %r13
je 0x401ae1
leaq (%rax,%rax,2), %rax
leaq 0xc99af(%rip), %rcx     # 0x4cb2f0
movzwl 0x14(%rcx,%rax,8), %eax
jmp 0x401aa8
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc9997(%rip), %rcx     # 0x4cb2f0
movl 0x4(%rcx,%rax,8), %ecx
jmp 0x401b22
movl $0xc, %edi
movl %r12d, %esi
xorl %edx, %edx
leaq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x450d50
movl 0x90(%rsp), %eax
movl %r12d, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq 0xc9963(%rip), %rdx     # 0x4cb2f0
movl %eax, (%rdx,%rcx,8)
movl 0x88(%rsp), %eax
movl %eax, 0x4(%rdx,%rcx,8)
movl 0x80(%rsp), %eax
movl %eax, 0x8(%rdx,%rcx,8)
jmp 0x401759
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc9937(%rip), %rcx     # 0x4cb2f0
movl (%rcx,%rax,8), %ecx
jmp 0x401b22
movl $0xc, %edi
movl %r12d, %esi
xorl %edx, %edx
leaq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x450d50
movq 0x90(%rsp), %r13
testq %r13, %r13
je 0x401a2f
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc98fe(%rip), %rcx     # 0x4cb2f0
movzwl (%rcx,%rax,8), %eax
movq %rax, 0x8(%rsp)
movl $0x2, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
andq $-0x10000, %rax         # imm = 0xFFFF0000
movq 0x8(%rsp), %rcx
orq %rax, %rcx
movl $0x5, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x450d50
movq 0x88(%rsp), %r13
testq %r13, %r13
je 0x401a88
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc98a6(%rip), %rcx     # 0x4cb2f0
movzwl 0x4(%rcx,%rax,8), %eax
movq %rax, 0x8(%rsp)
movl $0x2, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
andq $-0x10000, %rax         # imm = 0xFFFF0000
movq 0x8(%rsp), %rcx
orq %rax, %rcx
movl $0x5, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x450d50
movq 0x80(%rsp), %r13
testq %r13, %r13
je 0x401ae1
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc984d(%rip), %rcx     # 0x4cb2f0
movzwl 0x8(%rcx,%rax,8), %eax
movq %rax, 0x8(%rsp)
movl $0x2, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
andq $-0x10000, %rax         # imm = 0xFFFF0000
movq 0x8(%rsp), %rcx
orq %rax, %rcx
movl $0x5, %edi
movl %r12d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x450d50
movl $0x6, %edi
movl %r12d, %esi
movl $0x50, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
xorl %r13d, %r13d
jmp 0x401b36
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc97e6(%rip), %rcx     # 0x4cb2f0
movl 0x10(%rcx,%rax,8), %ecx
jmp 0x401b22
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0xc97d2(%rip), %rcx     # 0x4cb2f0
movl 0xc(%rcx,%rax,8), %ecx
movl $0x6, %edi
movl %r12d, %esi
movl $0x50, %edx
xorl %eax, %eax
callq 0x450d50
movl $0x18, %edi
movl %r12d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
movl %r13d, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rsi
leaq 0x9752f(%rip), %rdi     # 0x4990a4
jmp 0x401ba9
movq (%r14), %rsi
leaq 0x9753f(%rip), %rdi     # 0x4990c0
jmp 0x401ba9
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x450d50
leaq 0x8(%r14), %rsi
movq 0x8(%r14), %rdi
callq 0x44f700
movq (%r14), %rsi
leaq 0x9752d(%rip), %rdi     # 0x4990d6
xorl %eax, %eax
callq 0x401bb0