// File: /workspace/github_cpp_makefile_star2_O2/nikhilYadala[P]Python_to_cpp/Source/src/functionize.cpp
// Function: self_sanitize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)
void self_sanitize(std::string* code) {
	int itr = code->find("self.", 0);
    while(itr != std::string::npos) {
        code->replace(itr, 5, ""); 
        itr = code->find("self.", itr);
    }

    itr = code->find("self", 0);
    while(itr != std::string::npos) {
        code->replace(itr, 4, ""); 
        itr = code->find("self", itr);
    }

    itr = code->find("import re", 0);
    while(itr != std::string::npos) {
        code->replace(itr, 9, ""); 
        itr = code->find("self", itr);
    }

    int rem = code->find("re.search(");
    if(rem!=std::string::npos){
    itr =  code->find("re.search(")+10;
    	// std::cout<<">>>>>>>>>>>"<<itr<<"  "<<"\n";
    while(*(code->begin()+itr)==' ')
    	itr++;


    std::string s ="",r="";
    while(*(code->begin()+itr)!=','){
    	r.push_back(*(code->begin()+itr));
    	itr++;
    }
    itr++;

    while(*(code->begin()+itr)!=')'){
    	s.push_back(*(code->begin()+itr));
    	itr++;
    }
    rem=itr-rem+1;
       itr = code->find("re.search(", 0);
    while(itr != std::string::npos) {
        code->replace(itr, rem, "std::regex_match("+s+",std::regex("+r+"))"); 
        itr = code->find("re.search(", itr);
    	}
	}
	// if(std::find(tokens.begin(), tokens.end(),"re.search")!=tokens.end())
	// {
	// 	converted_code.append((size_t)lines[i].second*tab_size,' ');	
	// 	converted_code.append("bool "+v+" = std::regex_match("+*(itr+8)+", std::regex_match("+*(itr+6)+"))"+"\n");		

	// }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
xorl %r15d, %r15d
leaq 0x41d8(%rip), %r14      # 0x91b9
leaq 0x4216(%rip), %r12      # 0x91fe
pushq $0x5
popq %r13
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2370
movq %rax, %r15
shlq $0x20, %r15
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
cmpq %rax, %r15
je 0x5027
sarq $0x20, %r15
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x2120
jmp 0x4fec
xorl %r12d, %r12d
leaq 0x418e(%rip), %r14      # 0x91bf
leaq 0x41c6(%rip), %r15      # 0x91fe
pushq $0x4
popq %r13
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2370
movq %rax, %r12
shlq $0x20, %r12
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
cmpq %rax, %r12
je 0x5077
sarq $0x20, %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2120
jmp 0x503c
leaq 0x4146(%rip), %rsi      # 0x91c4
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2370
movq %rax, %r12
leaq 0x416c(%rip), %r14      # 0x91fe
pushq $0x9
popq %r15
leaq 0x4122(%rip), %r13      # 0x91bf
shlq $0x20, %r12
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
cmpq %rax, %r12
je 0x50d8
sarq $0x20, %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2120
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2370
movq %rax, %r12
jmp 0x509d
leaq 0x40ef(%rip), %rsi      # 0x91ce
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2370
movq %rax, %r15
cmpl $-0x1, %r15d
je 0x52b3
movabsq $0x100000000, %r12      # imm = 0x100000000
leaq 0x40c7(%rip), %rsi      # 0x91ce
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2370
movq (%rbx), %rcx
shlq $0x20, %rax
movabsq $0xa00000000, %r14      # imm = 0xA00000000
addq %rax, %r14
movq %r14, %r13
sarq $0x20, %r13
shlq $0x20, %r15
addq %r12, %r14
subq %r15, %r14
addq %r12, %r14
cmpb $0x20, (%rcx,%r13)
leaq 0x1(%r13), %r13
je 0x5136
leaq 0x40b3(%rip), %r15      # 0x91fe
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %r15, %rsi
callq 0x20b0
leaq -0x48(%rbp), %rdi
leaq -0xe8(%rbp), %rdx
movq %r15, %rsi
callq 0x20b0
leaq -0x48(%rbp), %r15
movq (%rbx), %rax
movb -0x1(%rax,%r13), %al
cmpb $0x2c, %al
je 0x5191
movsbl %al, %esi
movq %r15, %rdi
callq 0x2160
addq %r12, %r14
incq %r13
jmp 0x5172
leaq -0x68(%rbp), %r15
movq (%rbx), %rax
movb (%rax,%r13), %al
cmpb $0x29, %al
je 0x51b3
addq %r12, %r14
incq %r13
movsbl %al, %esi
movq %r15, %rdi
callq 0x2160
jmp 0x5195
leaq 0x4014(%rip), %rsi      # 0x91ce
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2370
movq %rax, %r15
sarq $0x20, %r14
movq %r15, %rax
shlq $0x20, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
cmpq %rcx, %rax
je 0x52a1
leaq -0x88(%rbp), %r12
movq %r12, %rdi
leaq 0x3fe3(%rip), %rsi      # 0x91d9
leaq -0x68(%rbp), %rdx
callq 0x4232
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
leaq 0x3fd8(%rip), %rdx      # 0x91eb
callq 0x4209
leaq -0xc8(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
leaq -0x48(%rbp), %rdx
callq 0x56ec
leaq -0xe8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
leaq 0x3fb6(%rip), %rdx      # 0x91f8
callq 0x4209
movslq %r15d, %r15
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x20a0
movq %r13, %rdi
callq 0x20e0
leaq -0xc8(%rbp), %rdi
callq 0x20e0
leaq -0xa8(%rbp), %rdi
callq 0x20e0
leaq -0x88(%rbp), %rdi
callq 0x20e0
movq %rbx, %rdi
leaq 0x3f3d(%rip), %rsi      # 0x91ce
movq %r15, %rdx
callq 0x2370
movq %rax, %r15
jmp 0x51cb
leaq -0x48(%rbp), %rdi
callq 0x20e0
leaq -0x68(%rbp), %rdi
callq 0x20e0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x531e
movq %rax, %rbx
jmp 0x5300
movq %rax, %rbx
jmp 0x52f4
movq %rax, %rbx
jmp 0x52e8
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x20e0
leaq -0xc8(%rbp), %rdi
callq 0x20e0
leaq -0xa8(%rbp), %rdi
callq 0x20e0
leaq -0x88(%rbp), %rdi
callq 0x20e0
jmp 0x5315
jmp 0x5312
jmp 0x5312
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x20e0
leaq -0x68(%rbp), %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2320
nop