// File: demon386[P]git-store/main.cpp
// Function: process_write_cmd(boost::program_options::variables_map const&)
void process_write_cmd(const po::variables_map& options) {
    if (!options.count("subargs")) {
        return;
    }
    auto subargs = options["subargs"].as<std::vector<std::string>>();
    if (subargs.size() == 0) {
        return;
    }
    auto subargs_str = boost::algorithm::join(subargs, " ");
    int ret = 0;
    ret = subprocess::run_cmd("git reset --mixed");
    if (ret != 0) {
        return;
    }

    if (subargs.size() == 1 && !fs::is_directory(subargs_str)
            && !options.count("tree")) {
        std::cout << "hashing blob object" << std::endl;
        ret = subprocess::run_cmd("git hash-object -w " + subargs_str);
    } else {
        std::cout << "hashing tree" << std::endl;
        ret = subprocess::run_cmd("git add " + subargs_str);
        if (ret != 0) {
            return;
        }
        ret = subprocess::run_cmd("git write-tree && git reset --mixed");
    }
    if (ret == 0) {
        if (options.count("delete")) {
            // @todo: check file is inside git repo.
            // to avoid accidently delete files under / or things like that.
            subprocess::run_cmd("rm -rf " + subargs_str);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x1e0(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0xdb50
movq -0x1d8(%rbp), %rdx
leaq 0xe84c(%rip), %rsi      # 0x64108
leaq -0x28(%rbp), %rdi
callq 0xd8b0
jmp 0x558c7
movq -0x1e0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x44d90
movq %rax, -0x1e8(%rbp)
jmp 0x558e0
movq -0x1e8(%rbp), %rax
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
movb %al, -0x1e9(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xdca8
leaq -0x29(%rbp), %rdi
callq 0xd6b0
movb -0x1e9(%rbp), %al
testb $0x1, %al
jne 0x55914
jmp 0x5594a
jmp 0x56017
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5593c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xdca8
leaq -0x29(%rbp), %rdi
callq 0xd6b0
jmp 0x56035
movq -0x8(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0xdb50
movq -0x1f8(%rbp), %rdx
leaq 0xe795(%rip), %rsi      # 0x64108
leaq -0x78(%rbp), %rdi
callq 0xd8b0
jmp 0x5597e
movq -0x200(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x57490
movq %rax, -0x208(%rbp)
jmp 0x55997
movq -0x208(%rbp), %rdi
callq 0x57830
movq %rax, -0x210(%rbp)
jmp 0x559ac
movq -0x210(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x19a40
jmp 0x559be
leaq -0x78(%rbp), %rdi
callq 0xdca8
leaq -0x79(%rbp), %rdi
callq 0xd6b0
leaq -0x58(%rbp), %rdi
callq 0x124d0
cmpq $0x0, %rax
jne 0x55a1c
movl $0x1, -0x80(%rbp)
jmp 0x5600e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x55a0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xdca8
leaq -0x79(%rbp), %rdi
callq 0xd6b0
jmp 0x56035
leaq 0xaa58(%rip), %rdx      # 0x6047b
leaq -0xa0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x57850
jmp 0x55a35
movl $0x0, -0xa4(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0xdb50
movq -0x218(%rbp), %rdx
leaq 0xe7e9(%rip), %rsi      # 0x64249
leaq -0xc8(%rbp), %rdi
callq 0xd8b0
jmp 0x55a6e
leaq -0xc8(%rbp), %rdi
movl $0x1, %esi
callq 0x55650
movl %eax, -0x21c(%rbp)
jmp 0x55a87
movl -0x21c(%rbp), %eax
movl %eax, -0xa4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xdca8
leaq -0xc9(%rbp), %rdi
callq 0xd6b0
cmpl $0x0, -0xa4(%rbp)
je 0x55b08
movl $0x1, -0x80(%rbp)
jmp 0x56002
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5602c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x55af7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xdca8
leaq -0xc9(%rbp), %rdi
callq 0xd6b0
jmp 0x56020
leaq -0x58(%rbp), %rdi
callq 0x124d0
movq %rax, %rcx
movb $0x0, -0xf1(%rbp)
movb $0x0, -0x11a(%rbp)
movb $0x0, -0x11b(%rbp)
xorl %eax, %eax
cmpq $0x1, %rcx
movb %al, -0x21d(%rbp)
jne 0x55c02
leaq -0xf0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x4e1a0
jmp 0x55b50
movb $0x1, -0xf1(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x4e000
movb %al, -0x21e(%rbp)
jmp 0x55b6b
movb -0x21e(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x21d(%rbp)
jne 0x55c02
jmp 0x55b84
movq -0x8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x230(%rbp)
leaq -0x119(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0xdb50
movq -0x228(%rbp), %rdx
movb $0x1, -0x11a(%rbp)
leaq 0xe66e(%rip), %rsi      # 0x64229
leaq -0x118(%rbp), %rdi
callq 0xd8b0
jmp 0x55bc9
movq -0x230(%rbp), %rdi
movb $0x1, -0x11b(%rbp)
leaq -0x118(%rbp), %rsi
callq 0x44d90
movq %rax, -0x238(%rbp)
jmp 0x55bec
movq -0x238(%rbp), %rax
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
movb %al, -0x21d(%rbp)
movb -0x21d(%rbp), %al
movb %al, -0x239(%rbp)
testb $0x1, -0x11b(%rbp)
jne 0x55c19
jmp 0x55c25
leaq -0x118(%rbp), %rdi
callq 0xdca8
testb $0x1, -0x11a(%rbp)
jne 0x55c30
jmp 0x55c3c
leaq -0x119(%rbp), %rdi
callq 0xd6b0
testb $0x1, -0xf1(%rbp)
jne 0x55c47
jmp 0x55c53
leaq -0xf0(%rbp), %rdi
callq 0x4d550
movb -0x239(%rbp), %al
testb $0x1, %al
jne 0x55c62
jmp 0x55d89
movq 0x38347(%rip), %rdi     # 0x8dfb0
leaq 0xe589(%rip), %rsi      # 0x641f9
callq 0xd610
movq %rax, -0x248(%rbp)
jmp 0x55c7e
movq -0x248(%rbp), %rdi
movq 0x382e4(%rip), %rsi     # 0x8df70
callq 0xd670
jmp 0x55c93
leaq 0xe573(%rip), %rsi      # 0x6420d
leaq -0x140(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x267b0
jmp 0x55caf
leaq -0x140(%rbp), %rdi
movl $0x1, %esi
callq 0x55650
movl %eax, -0x24c(%rbp)
jmp 0x55cc8
movl -0x24c(%rbp), %eax
movl %eax, -0xa4(%rbp)
leaq -0x140(%rbp), %rdi
callq 0xdca8
jmp 0x55ede
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x56020
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x55d50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x55d37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
testb $0x1, -0x11b(%rbp)
jne 0x55d29
jmp 0x55d35
leaq -0x118(%rbp), %rdi
callq 0xdca8
jmp 0x55d37
testb $0x1, -0x11a(%rbp)
jne 0x55d42
jmp 0x55d4e
leaq -0x119(%rbp), %rdi
callq 0xd6b0
jmp 0x55d50
testb $0x1, -0xf1(%rbp)
jne 0x55d5b
jmp 0x55d67
leaq -0xf0(%rbp), %rdi
callq 0x4d550
jmp 0x56020
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0xdca8
jmp 0x56020
movq 0x38220(%rip), %rdi     # 0x8dfb0
leaq 0xe48a(%rip), %rsi      # 0x64221
callq 0xd610
movq %rax, -0x258(%rbp)
jmp 0x55da5
movq -0x258(%rbp), %rdi
movq 0x381bd(%rip), %rsi     # 0x8df70
callq 0xd670
jmp 0x55dba
leaq 0xe46d(%rip), %rsi      # 0x6422e
leaq -0x160(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x267b0
jmp 0x55dd6
leaq -0x160(%rbp), %rdi
movl $0x1, %esi
callq 0x55650
movl %eax, -0x25c(%rbp)
jmp 0x55def
movl -0x25c(%rbp), %eax
movl %eax, -0xa4(%rbp)
leaq -0x160(%rbp), %rdi
callq 0xdca8
cmpl $0x0, -0xa4(%rbp)
je 0x55e39
movl $0x1, -0x80(%rbp)
jmp 0x56002
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0xdca8
jmp 0x56020
leaq -0x181(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0xdb50
movq -0x268(%rbp), %rdx
leaq 0xe3dd(%rip), %rsi      # 0x64237
leaq -0x180(%rbp), %rdi
callq 0xd8b0
jmp 0x55e68
leaq -0x180(%rbp), %rdi
movl $0x1, %esi
callq 0x55650
movl %eax, -0x26c(%rbp)
jmp 0x55e81
movl -0x26c(%rbp), %eax
movl %eax, -0xa4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0xdca8
leaq -0x181(%rbp), %rdi
callq 0xd6b0
jmp 0x55ede
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x55ecd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0xdca8
leaq -0x181(%rbp), %rdi
callq 0xd6b0
jmp 0x56020
cmpl $0x0, -0xa4(%rbp)
jne 0x55ffb
movq -0x8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x280(%rbp)
leaq -0x1a9(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0xdb50
movq -0x278(%rbp), %rdx
leaq 0xe340(%rip), %rsi      # 0x6425b
leaq -0x1a8(%rbp), %rdi
callq 0xd8b0
jmp 0x55f29
movq -0x280(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x44d90
movq %rax, -0x288(%rbp)
jmp 0x55f45
leaq -0x1a8(%rbp), %rdi
callq 0xdca8
leaq -0x1a9(%rbp), %rdi
callq 0xd6b0
movq -0x288(%rbp), %rax
cmpq $0x0, %rax
je 0x55ff9
leaq 0xe2ed(%rip), %rsi      # 0x64262
leaq -0x1d0(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x267b0
jmp 0x55f8a
leaq -0x1d0(%rbp), %rdi
movl $0x1, %esi
callq 0x55650
jmp 0x55f9d
leaq -0x1d0(%rbp), %rdi
callq 0xdca8
jmp 0x55ff9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x55fd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0xdca8
leaq -0x1a9(%rbp), %rdi
callq 0xd6b0
jmp 0x56020
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0xdca8
jmp 0x56020
jmp 0x55ffb
movl $0x0, -0x80(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xdca8
leaq -0x58(%rbp), %rdi
callq 0x11db0
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0xdca8
leaq -0x58(%rbp), %rdi
callq 0x11db0
movq -0x38(%rbp), %rdi
callq 0xdb30
nop