// File: /workspace/github_c_makefile_star2_O0/Carben-dev[P]ext2fs-simple-utilities/ext2_utils.c
// Function: get_inode_number_by_path_helper
int get_inode_number_by_path_helper(char *path,
                                    int curr_inode_num)
{
    // Inode index = inode number - 1
    // Get inode by inode index.
    struct ext2_inode *curr_inode = inode_table + curr_inode_num - 1;
    
    // Prepare path
    // For example.
    // "d1/d2/d3" -> path_next_call: "d2/d3", dir_name: "d1"
    // "d3"       -> path_next_call: NULL   , dir_name: "d3"
    char *path_next_call = strchr(path, '/');
    char dir_name[EXT2_NAME_LEN];
    
    
    /*
     *  Base case:
     *      inode ref an reg file and not reach end return -1
     *          or
     *      reach end of path
     */
    
    if ((curr_inode->i_mode & EXT2_S_IFREG) &&
        path_next_call != NULL) {
        return -1;
    }
    
    // reach end of path, then search the inode number current dir.
    if (path_next_call == NULL) {
        memcpy(dir_name, path, strlen(path));
        return get_inode_number_by_name(curr_inode_num, dir_name);
    }
    
    
    /*
     *  Recursive part
     */
    
    // Prepare dir_name
    int i;
    int first_slash_index = 0;
    for (i = 0; i < strlen(path); i++) {
        if (path[i] == '/') {
            first_slash_index = i;
            break;
        }
    }
    memcpy(dir_name, path, first_slash_index);
    dir_name[first_slash_index] = '\0';
    
    // Enter next level dir
    // Before enter next level, check if entry exist.
    int next_level_inode = get_inode_number_by_name(curr_inode_num, dir_name);
    if (next_level_inode == -1) {
        return -1;
    }
    
    return get_inode_number_by_path_helper(path_next_call + 1, next_level_inode);
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
leaq 0x499f(%rip), %rax      # 0x60b8
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
addq $-0x80, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2f, %esi
callq 0x1090
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x1765
cmpq $0x0, -0x28(%rbp)
je 0x1765
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188d
cmpq $0x0, -0x28(%rbp)
jne 0x17bb
leaq -0x130(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1070
movq -0x150(%rbp), %rdi
movq -0x148(%rbp), %rsi
movq %rax, %rdx
callq 0x10d0
movl -0x14(%rbp), %edi
leaq -0x130(%rbp), %rsi
callq 0x14c0
movl %eax, -0x4(%rbp)
jmp 0x188d
movl $0x0, -0x138(%rbp)
movl $0x0, -0x134(%rbp)
movslq -0x134(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1070
movq %rax, %rcx
movq -0x158(%rbp), %rax
cmpq %rcx, %rax
jae 0x182a
movq -0x10(%rbp), %rax
movslq -0x134(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x1817
movl -0x134(%rbp), %eax
movl %eax, -0x138(%rbp)
jmp 0x182a
jmp 0x1819
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x17cf
leaq -0x130(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x138(%rbp), %rdx
callq 0x10d0
movslq -0x138(%rbp), %rax
movb $0x0, -0x130(%rbp,%rax)
movl -0x14(%rbp), %edi
leaq -0x130(%rbp), %rsi
callq 0x14c0
movl %eax, -0x13c(%rbp)
cmpl $-0x1, -0x13c(%rbp)
jne 0x1877
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188d
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
movl -0x13c(%rbp), %esi
callq 0x1700
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)