// File: 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
subq $0x2f0, %rsp            # imm = 0x2F0
movl $0x0, -0x4(%rbp)
leaq 0x28bb(%rip), %rdi      # 0x5004
callq 0x4ad0
movq 0x588b(%rip), %rdi      # 0x7fe0
leaq -0x8(%rbp), %rsi
callq 0x20c0
movl $0x0, -0xc(%rbp)
leaq 0x28c3(%rip), %rdi      # 0x502f
callq 0x4ad0
movl -0xc(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x280a
leaq -0x30(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x2280
movq -0x2c8(%rbp), %rsi
movq 0x5845(%rip), %rdi      # 0x7fe0
callq 0x2260
jmp 0x27a2
leaq -0x60(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2090
jmp 0x27b1
leaq -0x60(%rbp), %rdi
callq 0x2aa0
jmp 0x27bc
leaq -0x60(%rbp), %rdi
callq 0x2368
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2368
jmp 0x2771
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x27fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x2368
leaq -0x30(%rbp), %rdi
callq 0x2368
jmp 0x2a91
leaq 0x288c(%rip), %rsi      # 0x509d
leaq -0x260(%rbp), %rdi
movl $0x10, %edx
callq 0x2210
leaq -0x280(%rbp), %rdi
callq 0x30e0
jmp 0x2830
leaq -0x260(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x2180
jmp 0x2845
leaq -0x280(%rbp), %rdi
callq 0x2368
leaq -0x260(%rbp), %rdi
callq 0x22a0
jmp 0x285f
leaq 0x27ee(%rip), %rdi      # 0x5054
callq 0x4ad0
jmp 0x286d
leaq 0x2807(%rip), %rdi      # 0x507b
callq 0x2160
jmp 0x287b
leaq 0x2828(%rip), %rdi      # 0x50aa
movl $0x1, %esi
callq 0x2290
movq %rax, -0x288(%rbp)
cmpq $0x0, -0x288(%rbp)
jne 0x290f
movq 0x572c(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x2d0(%rbp)
callq 0x21a0
movq -0x2d0(%rbp), %rdi
movq %rax, %rdx
leaq 0x27f3(%rip), %rsi      # 0x50b7
movb $0x0, %al
callq 0x22b0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x294(%rbp)
jmp 0x2a6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2a85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x2368
jmp 0x2a85
movq -0x288(%rbp), %rdi
leaq 0x27a7(%rip), %rsi      # 0x50c4
callq 0x2190
movq %rax, -0x290(%rbp)
cmpq $0x0, -0x290(%rbp)
jne 0x2983
movq 0x5696(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x2d8(%rbp)
callq 0x21a0
movq -0x2d8(%rbp), %rdi
movq %rax, %rdx
leaq 0x2770(%rip), %rsi      # 0x50ca
movb $0x0, %al
callq 0x22b0
movq -0x288(%rbp), %rdi
callq 0x2140
movl $0x1, -0x4(%rbp)
movl $0x1, -0x294(%rbp)
jmp 0x2a6d
movb $0x79, -0x295(%rbp)
movsbl -0x295(%rbp), %eax
cmpl $0x79, %eax
jne 0x2a57
leaq 0x2736(%rip), %rdi      # 0x50d7
callq 0x4ad0
jmp 0x29a8
leaq -0x2b8(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x2280
movq -0x2e0(%rbp), %rsi
movq 0x5617(%rip), %rdi      # 0x7fe0
callq 0x2260
jmp 0x29d0
xorl %eax, %eax
movl %eax, %esi
leaq -0x2b8(%rbp), %rdi
callq 0x2350
movq %rax, -0x2e8(%rbp)
jmp 0x29e9
movq -0x2e8(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movq -0x290(%rbp), %rax
movq -0x2c0(%rbp), %rdi
callq *%rax
jmp 0x2a09
leaq 0x26e9(%rip), %rdi      # 0x50f9
callq 0x4ad0
jmp 0x2a17
movq 0x55c2(%rip), %rdi      # 0x7fe0
leaq -0x295(%rbp), %rsi
callq 0x2270
jmp 0x2a2c
leaq -0x2b8(%rbp), %rdi
callq 0x2368
jmp 0x298a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x2368
jmp 0x2a85
movq -0x288(%rbp), %rdi
callq 0x2140
movl $0x0, -0x294(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x22d0
movl -0x4(%rbp), %eax
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x22d0
movq -0x38(%rbp), %rdi
callq 0x2300
nopw (%rax,%rax)