// File: /workspace/github_cpp_makefile_star2_O1/kiranbhanushali[P]recursive-descent-parser-generator/main.cpp
// Function: main
int main (){

    int lines ;
    print_message("Enter No. Of Productions you want to add: ");
    cin>>lines;
    int cur_line = 0 ;
    print_message("Enter Productions (lines separated)\n");
    while( cur_line< lines){
        // input line 
        string line;
        cin>>line;
        // generate production template for  current lines
        generate_template(line); // defined in template.h
        cur_line++;
    }

    
    // save program 
    ofstream f ( "lib_temp.cpp" );
    f<<get_template(); // get dynamically generated program
    f.close();

    print_message("Successfully Generated Parser Program\n");

    // create library
    system ( "g++ -fPIC  -o  libtemp.so -shared lib_temp.cpp" );

    // load library
    void * handle;
    void (*func) (const char *);

    handle = dlopen("./libtemp.so",RTLD_LAZY);
     if (!handle) {
        /* fail to load the library */
        fprintf(stderr, "Error:ii %s\n", dlerror());
        return EXIT_FAILURE;
    }

    *(void **) (&func) = dlsym(handle,"start");
    if( !func ) {
         fprintf(stderr, "Error: u %s\n", dlerror());
        dlclose(handle);
        return EXIT_FAILURE;
    }
    

    char loop ='y';
    while(loop == 'y'){
        print_message("Enter String You Want To Parse: \n");
        string input ;
        cin>>input;
        // convering string to char *
        char *input_c;
        input_c = &input[0];


        // calling library function 
        func(input_c);

        // loop termination 
        print_message(" Do You want to Continue:(y/n):");
        cin>>loop;
    }



    // closeing the library
    dlclose(handle);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
leaq 0x1a1d(%rip), %rdi      # 0x4004
callq 0x3387
movq 0x39ed(%rip), %rdi      # 0x5fe0
leaq -0x54(%rbp), %rbx
movq %rbx, %rsi
callq 0x2090
leaq 0x1a29(%rip), %rdi      # 0x402f
callq 0x3387
cmpl $0x0, (%rbx)
jle 0x26b4
leaq -0x270(%rbp), %r12
xorl %ebx, %ebx
leaq -0x70(%rbp), %r13
leaq -0x280(%rbp), %r14
leaq -0x80(%rbp), %r15
movq %r12, -0x280(%rbp)
movq $0x0, -0x278(%rbp)
movb $0x0, -0x270(%rbp)
movq 0x3994(%rip), %rdi      # 0x5fe0
movq %r14, %rsi
callq 0x21a0
movq %r13, -0x80(%rbp)
movq -0x280(%rbp), %rsi
movq -0x278(%rbp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x28c4
movq %r15, %rdi
callq 0x2960
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
je 0x268e
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2150
movq -0x280(%rbp), %rdi
cmpq %r12, %rdi
je 0x26a9
movq -0x270(%rbp), %rsi
incq %rsi
callq 0x2150
incl %ebx
cmpl -0x54(%rbp), %ebx
jl 0x262c
leaq 0x19e2(%rip), %rsi      # 0x409d
leaq -0x280(%rbp), %rdi
movl $0x10, %edx
callq 0x2170
leaq -0x50(%rbp), %rdi
callq 0x2e34
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x280(%rbp), %rdi
callq 0x2180
leaq -0x40(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x2702
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
leaq -0x280(%rbp), %rdi
callq 0x21d0
leaq 0x193f(%rip), %rdi      # 0x4054
callq 0x3387
leaq 0x195a(%rip), %rdi      # 0x407b
callq 0x20f0
leaq 0x197d(%rip), %rdi      # 0x40aa
movl $0x1, %ebx
movl $0x1, %esi
callq 0x21c0
testq %rax, %rax
je 0x282f
leaq 0x1978(%rip), %rsi      # 0x40c4
movq %rax, -0x60(%rbp)
movq %rax, %rdi
callq 0x2120
testq %rax, %rax
je 0x2836
movq %rax, %r14
leaq -0x29(%rbp), %rax
movb $0x79, (%rax)
movq 0x386e(%rip), %r13      # 0x5fe0
leaq -0x50(%rbp), %rbx
leaq 0x197c(%rip), %r12      # 0x40f9
leaq 0x1953(%rip), %rdi      # 0x40d7
callq 0x3387
movq %r15, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movb $0x0, -0x40(%rbp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x21a0
movq -0x50(%rbp), %rdi
callq *%r14
movq %r12, %rdi
callq 0x3387
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
callq 0x21b0
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0x27d4
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
cmpb $0x79, -0x29(%rbp)
je 0x277d
movq -0x60(%rbp), %rdi
callq 0x20c0
xorl %ebx, %ebx
movq 0x37dc(%rip), %rax      # 0x5fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x278(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x280(%rbp,%rcx)
callq 0x20e0
leaq -0x188(%rbp), %rdi
callq 0x2070
movl %ebx, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x22aa
jmp 0x27e5
movq -0x60(%rbp), %rdi
callq 0x2270
jmp 0x27e5
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x28a4
jmp 0x28b0
jmp 0x2871
jmp 0x2871
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
je 0x287b
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x287b
movq %rax, %rbx
jmp 0x28b0
jmp 0x2898
movq %rax, %rbx
movq -0x280(%rbp), %rdi
cmpq %r12, %rdi
je 0x28bc
movq -0x270(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x28bc
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0x28b0
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
leaq -0x280(%rbp), %rdi
callq 0x2200
movq %rbx, %rdi
callq 0x2230