// File: /workspace/github_cpp_makefile_star2_O2/allasandeep[P]LocationBoundaryFinder/prog1.cc
// Function: processNameFiles(std::basic_ifstream<char, std::char_traits<char>>&, pg_conn*)
void processNameFiles(ifstream& is, PGconn *db)
{
	//Required Variable declarations
	string line = "";
	string state_id = "";
	string county_id = "";
	string place_id = "";
	string region_type = "";
	string name = "";
	string year = "";
	int Id = 0;
	string type = "";
	bool insert_flag = false;
	char r_type;

	//Reading data from file line by line 
	while(std::getline(is,line))
	{
		//Getting the substrings and putting them into the respective variables
		insert_flag = false;
		state_id = line.substr(5,2);
		county_id = state_id + line.substr(7,3);
		year = line.substr(10,4);
		place_id = state_id + line.substr(14,5);
		region_type = line.substr(24,1); 
		name = line.substr(52,60);
		r_type = region_type[0];

		if( year == "2000" || year == "    ")
		{
			//Depending upon the type of region the ID and type variables are set and setting the insert_flag to true
			switch(r_type)
			{
				case 'S':
					type = "State";
					//checking whether the state length is 2
					if(state_id.length() == 2)
					{
						Id = stoi(state_id);
						insert_flag = true;
					}
					break;
				case 'C':
					type = "County";
					//checking whether the countyid length is 5
					if(county_id.length() == 5)
					{
						Id = stoi(county_id);
						insert_flag = true;
					}
					break;
				case 'M':
					type = "Subcounty";
					//checking whether the subcounty length is 7
					if(place_id.length() == 7)
					{
						Id = stoi(place_id);
						insert_flag = true;	      
					}
				case 'P':
					type = "Place";
					//checking whether the placeid length is 5
					if(place_id.length() == 7)
					{
						Id = stoi(place_id);
						insert_flag = true;
					}
			}

			PGresult * result = nullptr;
			//Psql Query by concatinating with c++ variables
			string query = "select id from region;";
			//Executing the query and storing the result in result.
			result = PQexec(db,query.c_str());
			//Number of tuples in the result
			int nrows = PQntuples(result);
			bool alreadyExits = false;

			if(nrows > 0)
			{
				for(int r = 0; r < nrows; r++)
				{
					if(PQgetvalue(result, r, 0) == to_string(Id))
					{
						alreadyExits = true;
					}
				}
			}	
					
			//Clearing the result
			PQclear(result);

			//If the insert flag is true then insert the data into database region
			if(insert_flag && !alreadyExits)
			{
				char query[100];
				char c_name[name.length()+1];
				strcpy(c_name, name.c_str());
				delSpaces(c_name);
				char c_type[type.length()+1];
				strcpy(c_type, type.c_str());

				//Psql Query by concatinating with c++ variables
				sprintf(query,"insert into region(id,iname,rtype) values(%d,'%s','%s');", Id, c_name, c_type);
				//Executing the query and storing the result in result.
				result = PQexec(db,query);

				//Clearing the result
				PQclear(result);			
			}
		}	
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, -0x40(%rbp)
movq %rdi, %r14
leaq 0x1b15(%rip), %rbx      # 0x41b7
leaq -0x168(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
movq %rbx, %rsi
callq 0x2f72
leaq -0x148(%rbp), %r15
leaq -0x1d0(%rbp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2f72
leaq 0x1adf(%rip), %rsi      # 0x41b7
leaq -0xe8(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x2f72
leaq 0x1ac5(%rip), %rsi      # 0x41b7
leaq -0x88(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x2f72
leaq 0x1aab(%rip), %rsi      # 0x41b7
leaq -0x128(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x2f72
leaq 0x1a91(%rip), %rsi      # 0x41b7
leaq -0xc8(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x2f72
leaq 0x1a77(%rip), %rsi      # 0x41b7
leaq -0x108(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x2f72
leaq 0x1a5d(%rip), %rsi      # 0x41b7
leaq -0x60(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x2f72
leaq -0x1d0(%rbp), %r12
movl $0x0, -0x30(%rbp)
movq %r14, -0x68(%rbp)
movq %r14, %rdi
leaq -0x168(%rbp), %rbx
movq %rbx, %rsi
callq 0x20d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2b0f
movq %r12, %rdi
movq %rbx, %rsi
pushq $0x5
popq %rdx
pushq $0x2
popq %rcx
callq 0x2200
movq %r15, %rdi
movq %r12, %rsi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
pushq $0x7
popq %rdx
pushq $0x3
popq %rcx
callq 0x2200
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2fce
leaq -0xe8(%rbp), %rdi
movq %r12, %rsi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
movq %r13, %rdi
callq 0x21a0
movq %r12, %rdi
movq %rbx, %rsi
pushq $0xa
popq %rdx
pushq $0x4
popq %rcx
callq 0x2200
leaq -0x108(%rbp), %rdi
movq %r12, %rsi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
movq %r13, %rdi
movq %rbx, %rsi
pushq $0xe
popq %rdx
pushq $0x5
popq %rcx
callq 0x2200
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2fce
leaq -0x88(%rbp), %rdi
movq %r12, %rsi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
movq %r13, %rdi
callq 0x21a0
movq %r12, %rdi
movq %rbx, %rsi
pushq $0x18
popq %rdx
pushq $0x1
popq %rcx
callq 0x2200
leaq -0x128(%rbp), %rdi
movq %r12, %rsi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
movq %r12, %rdi
movq %rbx, %rsi
pushq $0x34
popq %rdx
pushq $0x3c
popq %rcx
callq 0x2200
leaq -0xc8(%rbp), %rdi
movq %r12, %rsi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
movq -0x128(%rbp), %rax
movzbl (%rax), %ebx
leaq -0x108(%rbp), %r13
movq %r13, %rdi
leaq 0x18d4(%rip), %rsi      # 0x41ae
callq 0x2ffc
testb %al, %al
jne 0x28fa
movq %r13, %rdi
leaq 0x18c6(%rip), %rsi      # 0x41b3
callq 0x2ffc
testb %al, %al
je 0x277c
cmpl $0x43, %ebx
je 0x2971
cmpl $0x4d, %ebx
je 0x293f
movl $0x0, -0x2c(%rbp)
cmpl $0x50, %ebx
je 0x29a2
cmpl $0x53, %ebx
jne 0x29d2
leaq -0x60(%rbp), %rdi
leaq 0x1890(%rip), %rsi      # 0x41b8
callq 0x2260
cmpq $0x2, -0x140(%rbp)
movq %r15, %rdi
jne 0x2992
jmp 0x29c0
leaq -0x60(%rbp), %rdi
leaq 0x187b(%rip), %rsi      # 0x41c5
callq 0x2260
cmpq $0x7, -0x80(%rbp)
jne 0x299b
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x2fad
movl %eax, -0x30(%rbp)
movb $0x1, %al
movl %eax, -0x2c(%rbp)
jmp 0x29a2
leaq -0x60(%rbp), %rdi
leaq 0x1842(%rip), %rsi      # 0x41be
callq 0x2260
cmpq $0x5, -0xe0(%rbp)
leaq -0xe8(%rbp), %rdi
je 0x29c0
movl $0x0, -0x2c(%rbp)
jmp 0x29d2
movl $0x0, -0x2c(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x1822(%rip), %rsi      # 0x41cf
callq 0x2260
cmpq $0x7, -0x80(%rbp)
leaq -0x88(%rbp), %rdi
jne 0x29d2
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x2fad
movl %eax, -0x30(%rbp)
movb $0x1, %al
movl %eax, -0x2c(%rbp)
leaq -0xa8(%rbp), %rdi
leaq 0x17f5(%rip), %rsi      # 0x41d5
movq %r12, %rdx
callq 0x2f72
movq -0xa8(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x2250
movq %rax, %rbx
movq %rax, %rdi
callq 0x2180
xorl %r14d, %r14d
testl %eax, %eax
jle 0x2a54
movl %eax, -0x34(%rbp)
xorl %r15d, %r15d
cmpl %r14d, -0x34(%rbp)
je 0x2a57
movq %rbx, %r13
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x2090
movq %rax, %rbx
movq %r12, %rdi
movl -0x30(%rbp), %esi
callq 0x3025
movq %rbx, %rdi
movq %r12, %rsi
callq 0x300c
movl %eax, %ebx
movq %r12, %rdi
callq 0x21a0
orb %bl, %r15b
incl %r14d
movq %r13, %rbx
jmp 0x2a10
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x20e0
movl -0x2c(%rbp), %eax
notb %al
orb %r15b, %al
testb $0x1, %al
jne 0x2af3
movq %rsp, %r15
movq -0xc0(%rbp), %rax
movq %rsp, %r14
addq $0x10, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq -0xc8(%rbp), %rsi
movq %r14, %rdi
callq 0x20c0
movq %r14, %rdi
callq 0x23ac
movq -0x58(%rbp), %rax
movq %rsp, %rbx
addq $0x10, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq -0x60(%rbp), %rsi
movq %rbx, %rdi
callq 0x20c0
movq %r12, %rdi
leaq 0x1720(%rip), %rsi      # 0x41ec
movl -0x30(%rbp), %edx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x2240
movq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x2250
movq %rax, %rdi
callq 0x20e0
movq %r15, %rsp
leaq -0xa8(%rbp), %rdi
callq 0x21a0
movq -0x68(%rbp), %r14
leaq -0x148(%rbp), %r15
jmp 0x277c
leaq -0x60(%rbp), %rdi
callq 0x21a0
leaq -0x108(%rbp), %rdi
callq 0x21a0
leaq -0xc8(%rbp), %rdi
callq 0x21a0
leaq -0x128(%rbp), %rdi
callq 0x21a0
leaq -0x88(%rbp), %rdi
callq 0x21a0
leaq -0xe8(%rbp), %rdi
callq 0x21a0
leaq -0x148(%rbp), %rdi
callq 0x21a0
leaq -0x168(%rbp), %rdi
callq 0x21a0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2bdc
movq %rax, %rbx
jmp 0x2be8
movq %rax, %rbx
jmp 0x2bf4
movq %rax, %rbx
jmp 0x2c00
movq %rax, %rbx
jmp 0x2c0c
movq %rax, %rbx
jmp 0x2c18
movq %rax, %rbx
jmp 0x2c24
jmp 0x2bbd
jmp 0x2bc4
jmp 0x2bc4
jmp 0x2bc4
jmp 0x2bc4
jmp 0x2bbd
jmp 0x2bbd
jmp 0x2bbd
jmp 0x2bbd
jmp 0x2bbd
jmp 0x2bc4
jmp 0x2bc4
jmp 0x2bbd
jmp 0x2bbd
movq %rax, %rbx
jmp 0x2bd3
jmp 0x2bc4
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x21a0
leaq -0x60(%rbp), %rdi
callq 0x21a0
leaq -0x108(%rbp), %rdi
callq 0x21a0
leaq -0xc8(%rbp), %rdi
callq 0x21a0
leaq -0x128(%rbp), %rdi
callq 0x21a0
leaq -0x88(%rbp), %rdi
callq 0x21a0
leaq -0xe8(%rbp), %rdi
callq 0x21a0
leaq -0x148(%rbp), %rdi
callq 0x21a0
leaq -0x168(%rbp), %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x2160