// File: /workspace/github_c_makefile_star2_O0/adsr[P]phpspy/./phpspy_trace.c
// Function: trace_stack_70
static int trace_stack(trace_context_t *context, zend_execute_data *remote_execute_data, int *depth) {
    int rv;
    zend_execute_data execute_data;
    zend_function zfunc;
    zend_string zstring;
    zend_class_entry zce;
    zend_op zop;
    trace_target_t *target;
    trace_frame_t *frame;

    target = &context->target;
    frame = &context->event.frame;
    *depth = 0;

    while (remote_execute_data && *depth != opt_max_stack_depth) { /* TODO make options struct */
        memset(&execute_data, 0, sizeof(execute_data));
        memset(&zfunc, 0, sizeof(zfunc));
        memset(&zstring, 0, sizeof(zstring));
        memset(&zce, 0, sizeof(zce));
        memset(&zop, 0, sizeof(zop));

        /* TODO reduce number of copy calls */
        try_copy_proc_mem("execute_data", remote_execute_data, &execute_data, sizeof(execute_data));
        try_copy_proc_mem("zfunc", execute_data.func, &zfunc, sizeof(zfunc));
        if (zfunc.common.function_name) {
            try(rv, sprint_zstring(context, "function_name", zfunc.common.function_name, frame->loc.func, sizeof(frame->loc.func), &frame->loc.func_len));
        } else {
            frame->loc.func_len = snprintf(frame->loc.func, sizeof(frame->loc.func), "<main>");
        }
        if (zfunc.common.scope) {
            try_copy_proc_mem("zce", zfunc.common.scope, &zce, sizeof(zce));
            try(rv, sprint_zstring(context, "class_name", zce.name, frame->loc.class, sizeof(frame->loc.class), &frame->loc.class_len));
        } else {
            frame->loc.class[0] = '\0';
            frame->loc.class_len = 0;
        }
        if (zfunc.type == 2) {
            try(rv, sprint_zstring(context, "filename", zfunc.op_array.filename, frame->loc.file, sizeof(frame->loc.file), &frame->loc.file_len));
            frame->loc.lineno = zfunc.op_array.line_start;
            /* TODO add comments */
            if (HASH_CNT(hh, varpeek_map) > 0) {
                if (copy_proc_mem(target->pid, "opline", (void*)execute_data.opline, &zop, sizeof(zop)) == PHPSPY_OK) {
                    trace_locals(context, &zop, remote_execute_data, &zfunc.op_array, frame->loc.file, frame->loc.file_len);
                }
            }
        } else {
            frame->loc.file_len = snprintf(frame->loc.file, sizeof(frame->loc.file), "<internal>");
            frame->loc.lineno = -1;
        }
        frame->depth = *depth;
        try(rv, context->event_handler(context, PHPSPY_TRACE_EVENT_FRAME));
        remote_execute_data = execute_data.prev_execute_data;
        *depth += 1;
    }

    return PHPSPY_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x10(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x148(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x149(%rbp)
je 0x1283f
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl 0x27afa(%rip), %eax     # 0x3a330
setne %al
movb %al, -0x149(%rbp)
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x1284e
jmp 0x12bfa
leaq -0x6c(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x6230
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
movl $0x84, %edx
callq 0x6230
leaq -0x109(%rbp), %rdi
xorl %esi, %esi
movl $0x19, %edx
callq 0x6230
leaq -0x119(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x6230
leaq -0x135(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x6230
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rdx
leaq 0x226d0(%rip), %rsi     # 0x34f8b
leaq -0x6c(%rbp), %rcx
movl $0x48, %r8d
callq 0x12680
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x128dd
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12c01
jmp 0x128df
jmp 0x128e1
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x54(%rbp), %rdx
leaq 0x226a6(%rip), %rsi     # 0x34f98
leaq -0xf0(%rbp), %rcx
movl $0x84, %r8d
callq 0x12680
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x12917
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12c01
jmp 0x12919
cmpq $0x0, -0xe8(%rbp)
je 0x1296e
jmp 0x12925
movq -0x10(%rbp), %rdi
movq -0xe8(%rbp), %rdx
movq -0x148(%rbp), %rcx
movq -0x148(%rbp), %r9
addq $0x300, %r9             # imm = 0x300
leaq 0x22652(%rip), %rsi     # 0x34f9e
movl $0x100, %r8d            # imm = 0x100
callq 0x13140
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x1296a
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12c01
jmp 0x1296c
jmp 0x12999
movq -0x148(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
leaq 0x2262b(%rip), %rdx     # 0x34fac
movb $0x0, %al
callq 0x61d0
movslq %eax, %rcx
movq -0x148(%rbp), %rax
movq %rcx, 0x300(%rax)
cmpq $0x0, -0xe0(%rbp)
je 0x12a36
jmp 0x129a9
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0xe0(%rbp), %rdx
leaq 0x225f6(%rip), %rsi     # 0x34fb3
leaq -0x119(%rbp), %rcx
movl $0x10, %r8d
callq 0x12680
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x129e2
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12c01
jmp 0x129e4
jmp 0x129e6
movq -0x10(%rbp), %rdi
movq -0x111(%rbp), %rdx
movq -0x148(%rbp), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x148(%rbp), %r9
addq $0x308, %r9             # imm = 0x308
leaq 0x225a3(%rip), %rsi     # 0x34fb7
movl $0x100, %r8d            # imm = 0x100
callq 0x13140
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x12a32
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12c01
jmp 0x12a34
jmp 0x12a56
movq -0x148(%rbp), %rax
movb $0x0, 0x100(%rax)
movq -0x148(%rbp), %rax
movq $0x0, 0x308(%rax)
movzbl -0xf0(%rbp), %eax
cmpl $0x2, %eax
jne 0x12b64
jmp 0x12a68
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rdx
movq -0x148(%rbp), %rcx
addq $0x200, %rcx            # imm = 0x200
movq -0x148(%rbp), %r9
addq $0x310, %r9             # imm = 0x310
leaq 0x2252f(%rip), %rsi     # 0x34fc2
movl $0x100, %r8d            # imm = 0x100
callq 0x13140
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x12ab1
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12c01
jmp 0x12ab3
movl -0x70(%rbp), %ecx
movq -0x148(%rbp), %rax
movl %ecx, 0x318(%rax)
cmpq $0x0, 0x29a85(%rip)     # 0x3c550
je 0x12ae6
movq 0x29a7c(%rip), %rax     # 0x3c550
movq 0x108(%rax), %rax
movl 0x10(%rax), %eax
movl %eax, -0x150(%rbp)
jmp 0x12af0
xorl %eax, %eax
movl %eax, -0x150(%rbp)
jmp 0x12af0
movl -0x150(%rbp), %eax
cmpl $0x0, %eax
jbe 0x12b62
movq -0x140(%rbp), %rax
movl (%rax), %edi
movq -0x6c(%rbp), %rdx
leaq 0x224bc(%rip), %rsi     # 0x34fcb
leaq -0x135(%rbp), %rcx
movl $0x1c, %r8d
callq 0x12680
cmpl $0x0, %eax
jne 0x12b60
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x148(%rbp), %r8
addq $0x200, %r8             # imm = 0x200
movq -0x148(%rbp), %rax
movq 0x310(%rax), %rax
movl %eax, %r9d
leaq -0x135(%rbp), %rsi
leaq -0xf0(%rbp), %rcx
callq 0x13280
jmp 0x12b62
jmp 0x12ba7
movq -0x148(%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
movl $0x100, %esi            # imm = 0x100
leaq 0x22454(%rip), %rdx     # 0x34fd2
movb $0x0, %al
callq 0x61d0
movslq %eax, %rcx
movq -0x148(%rbp), %rax
movq %rcx, 0x310(%rax)
movq -0x148(%rbp), %rax
movl $0xffffffff, 0x318(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movq -0x148(%rbp), %rax
movl %ecx, 0x320(%rax)
movq -0x10(%rbp), %rax
movq 0x798(%rax), %rax
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq *%rax
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x12be0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12c01
jmp 0x12be2
movq -0x34(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x1281b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopl (%rax)