// File: shengzh-oOoO[P]CodeSim/src/test.cpp
// Function: main
int main(int argc, char **argv){
    memset(input,0,sizeof(input));
    sprintf(input,"./bin/text_moss %s %s", argv[1], argv[2]);
    Shell(input);
    result[len++] = atof(buffer);

    memset(input,0,sizeof(input));
    Shell((char *)"mktemp 1.s.XXXX");
    char sfile1[128] = {0};
    strcpy(sfile1, buffer);
    for (int i = 0 ;i < 128 ;i++){
        if (sfile1[i] == '\n'){
            sfile1[i] = 0;
            break;
        }
    }
    memset(input,0,sizeof(input));
    Shell((char *)"mktemp 2.s.XXXX");
    char sfile2[128] = {0};
    strcpy(sfile2, buffer);
    for (int i = 0 ;i < 128 ;i++){
        if (sfile2[i] == '\n'){
            sfile2[i] = 0;
            break;
        }
    }

    memset(input,0,sizeof(input));
    sprintf(input,"g++ -S %s -o %s", argv[1], sfile1);
    Shell(input);

    memset(input,0,sizeof(input));
    sprintf(input,"g++ -S %s -o %s", argv[2], sfile2);
    Shell(input);
    
    memset(input,0,sizeof(input));
    sprintf(input,"./bin/assembly_moss %s %s", sfile1, sfile2);
    Shell(input);
    result[len++] = atof(buffer);

    memset(input,0,sizeof(input));
    sprintf(input,"rm %s", sfile1);
    Shell(input);
    memset(input,0,sizeof(input));
    sprintf(input,"rm %s", sfile2);
    Shell(input);


    PrintFinalResult();
    return 0;    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x3190(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x316d(%rip), %rdi      # 0x44a0
leaq 0xcd3(%rip), %rsi       # 0x200d
movb $0x0, %al
callq 0x1040
leaq 0x3158(%rip), %rdi      # 0x44a0
callq 0x1290
leaq 0x2d4c(%rip), %rdi      # 0x40a0
callq 0x1090
cvtsd2ss %xmm0, %xmm0
movl 0x3565(%rip), %eax      # 0x48c8
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x355a(%rip)      # 0x48c8
movslq %eax, %rcx
leaq 0x3528(%rip), %rax      # 0x48a0
movss %xmm0, (%rax,%rcx,4)
leaq 0x311c(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
leaq 0xc8c(%rip), %rdi       # 0x2023
callq 0x1290
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x1060
leaq -0x90(%rbp), %rdi
leaq 0x2ce3(%rip), %rsi      # 0x40a0
callq 0x1080
movl $0x0, -0x94(%rbp)
cmpl $0x80, -0x94(%rbp)
jge 0x1410
movslq -0x94(%rbp), %rax
movsbl -0x90(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x13fd
movslq -0x94(%rbp), %rax
movb $0x0, -0x90(%rbp,%rax)
jmp 0x1410
jmp 0x13ff
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x13cc
leaq 0x3089(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
leaq 0xc09(%rip), %rdi       # 0x2033
callq 0x1290
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x1060
leaq -0x120(%rbp), %rdi
leaq 0x2c50(%rip), %rsi      # 0x40a0
callq 0x1080
movl $0x0, -0x124(%rbp)
cmpl $0x80, -0x124(%rbp)
jge 0x14a3
movslq -0x124(%rbp), %rax
movsbl -0x120(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x1490
movslq -0x124(%rbp), %rax
movb $0x0, -0x120(%rbp,%rax)
jmp 0x14a3
jmp 0x1492
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x145f
leaq 0x2ff6(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x90(%rbp), %rcx
leaq 0x2fd4(%rip), %rdi      # 0x44a0
leaq 0xb70(%rip), %rsi       # 0x2043
movb $0x0, %al
callq 0x1040
leaq 0x2fbf(%rip), %rdi      # 0x44a0
callq 0x1290
leaq 0x2fb3(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq -0x120(%rbp), %rcx
leaq 0x2f91(%rip), %rdi      # 0x44a0
leaq 0xb2d(%rip), %rsi       # 0x2043
movb $0x0, %al
callq 0x1040
leaq 0x2f7c(%rip), %rdi      # 0x44a0
callq 0x1290
leaq 0x2f70(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
leaq -0x90(%rbp), %rdx
leaq -0x120(%rbp), %rcx
leaq 0x2f4f(%rip), %rdi      # 0x44a0
leaq 0xafb(%rip), %rsi       # 0x2053
movb $0x0, %al
callq 0x1040
leaq 0x2f3a(%rip), %rdi      # 0x44a0
callq 0x1290
leaq 0x2b2e(%rip), %rdi      # 0x40a0
callq 0x1090
cvtsd2ss %xmm0, %xmm0
movl 0x3347(%rip), %eax      # 0x48c8
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x333c(%rip)      # 0x48c8
movslq %eax, %rcx
leaq 0x330a(%rip), %rax      # 0x48a0
movss %xmm0, (%rax,%rcx,4)
leaq 0x2efe(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
leaq -0x90(%rbp), %rdx
leaq 0x2ee4(%rip), %rdi      # 0x44a0
leaq 0xaaa(%rip), %rsi       # 0x206d
movb $0x0, %al
callq 0x1040
leaq 0x2ecf(%rip), %rdi      # 0x44a0
callq 0x1290
leaq 0x2ec3(%rip), %rdi      # 0x44a0
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1060
leaq -0x120(%rbp), %rdx
leaq 0x2ea9(%rip), %rdi      # 0x44a0
leaq 0xa6f(%rip), %rsi       # 0x206d
movb $0x0, %al
callq 0x1040
leaq 0x2e94(%rip), %rdi      # 0x44a0
callq 0x1290
callq 0x1210
xorl %eax, %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq