// File: /workspace/github_cpp_makefile_star2_O2/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 0x1b0d(%rip), %rdi      # 0x4004
callq 0x300b
movq 0x3add(%rip), %rbx      # 0x5fe0
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x2090
leaq 0x1b19(%rip), %rdi      # 0x402f
callq 0x300b
xorl %r12d, %r12d
leaq -0x268(%rbp), %r13
leaq -0x278(%rbp), %r14
leaq -0x78(%rbp), %r15
cmpl -0x30(%rbp), %r12d
jge 0x257f
movq %r13, -0x278(%rbp)
andq $0x0, -0x270(%rbp)
movb $0x0, -0x268(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21a0
movq %r15, %rdi
movq %r14, %rsi
callq 0x21d0
movq %r15, %rdi
callq 0x2754
movq %r15, %rdi
callq 0x2298
incl %r12d
movq %r14, %rdi
callq 0x2298
jmp 0x2530
leaq 0x1b17(%rip), %rsi      # 0x409d
leaq -0x278(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x2180
leaq -0x58(%rbp), %rdi
callq 0x2abc
leaq -0x278(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2120
leaq -0x58(%rbp), %rdi
callq 0x2298
leaq -0x278(%rbp), %rdi
callq 0x21f0
leaq 0x1a8a(%rip), %rdi      # 0x4054
callq 0x300b
leaq 0x1aa5(%rip), %rdi      # 0x407b
callq 0x20f0
leaq 0x1ac8(%rip), %rdi      # 0x40aa
pushq $0x1
popq %r15
movl %r15d, %esi
callq 0x21e0
testq %rax, %rax
je 0x26b5
leaq 0x1ac6(%rip), %rsi      # 0x40c4
movq %rax, -0x38(%rbp)
movq %rax, %rdi
callq 0x2130
testq %rax, %rax
je 0x26da
movq %rax, %r14
leaq -0x29(%rbp), %rax
movb $0x79, (%rax)
movb $0x79, %al
leaq 0x1ab1(%rip), %r12      # 0x40d7
movq 0x39b3(%rip), %r13      # 0x5fe0
leaq -0x58(%rbp), %rbx
leaq 0x1ac1(%rip), %r15      # 0x40f9
cmpb $0x79, %al
jne 0x2688
movq %r12, %rdi
callq 0x300b
leaq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
andq $0x0, -0x50(%rbp)
movb $0x0, -0x48(%rbp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x21a0
movq -0x58(%rbp), %rdi
callq *%r14
movq %r15, %rdi
callq 0x300b
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2298
movb -0x29(%rbp), %al
jmp 0x2638
movq -0x38(%rbp), %rdi
callq 0x20d0
xorl %r15d, %r15d
leaq -0x278(%rbp), %rdi
callq 0x2220
movl %r15d, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3914(%rip), %rax      # 0x5fd0
movq (%rax), %rbx
callq 0x2140
leaq 0x19ec(%rip), %rsi      # 0x40b7
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2200
jmp 0x2694
movq 0x38ef(%rip), %rax      # 0x5fd0
movq (%rax), %rbx
callq 0x2140
leaq 0x19da(%rip), %rsi      # 0x40ca
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2200
movq -0x38(%rbp), %rdi
callq 0x20d0
jmp 0x2694
jmp 0x2734
jmp 0x2710
jmp 0x2710
jmp 0x2734
movq %rax, %rbx
jmp 0x2740
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x2298
jmp 0x2726
movq %rax, %rbx
leaq -0x278(%rbp), %rdi
callq 0x2298
jmp 0x274c
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2298
leaq -0x278(%rbp), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2250