// File: allasandeep[P]LocationBoundaryFinder/prog2.cc
// Function: getRegionData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, pg_conn*)
void getRegionData(string str, PGconn *db)
{
	char query[100];
	char temp[str.length() + 1];
	//Converting the string to lowercase
	std::transform(str.begin(), str.end(), str.begin(), ::tolower);
	//Copying the string to char*
	strcpy(temp , str.c_str());
	//Deleting the spacing in the char*
	delSpaces(temp);
	PGresult * result = nullptr;
	//Psql Query by concatinating with c++ variables
	sprintf(query,"select *from region where lower(iname) = '%s';",temp);
	//Executing the query and storing the result in result.
	result = PQexec(db,query);
	//Number of tuples in the result
	int nrows = PQntuples(result);

	//Checking 
	if( PGRES_TUPLES_OK != PQresultStatus(result)) 
	{
		//Error	
		cerr << "Query is not successfull" << endl;
		cerr << PQresultErrorMessage(result) << endl;
	}

	if(nrows > 0)
	{
		for(int r = 0; r < nrows; r++)
		{			
			string sID(PQgetvalue(result,r,0));
			int stateId = stoi(sID.substr(0,2));
			char queryTemp[50];
			PGresult * resultTemp = nullptr;
			//Psql Query by concatinating with c++ variables
			sprintf(queryTemp,"select iname from region where id = %d;",stateId);
			//Executing the query and storing the result in result.
			resultTemp = PQexec(db,queryTemp);
			string stateName = PQgetvalue(resultTemp,0,0);
			PQclear(resultTemp);
			string outputString = toDecimalDegree(PQgetvalue(result, r, 0),PQgetvalue(result, r, 1),PQgetvalue(result, r, 3),PQgetvalue(result, r, 4),PQgetvalue(result, r, 5),PQgetvalue(result, r, 6), stateName);
			cout<<outputString<<endl;
			cout<<endl;
		}
	}
	else
		cout<<"No tuples found with the given name"<<endl;

	//Clearing the result
	PQclear(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x1d0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x21a0
movq -0x1d0(%rbp), %rdi
movq %rax, %rdx
movq %rdx, %rax
incq %rax
movq %rsp, %rcx
movq %rcx, -0x88(%rbp)
addq $0x10, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1c8(%rbp)
movq %rcx, %rsp
movq %rax, -0x90(%rbp)
callq 0x2150
movq -0x1d0(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x2190
movq -0x1d0(%rbp), %rdi
movq %rax, -0xa0(%rbp)
callq 0x2150
movq %rax, -0xa8(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq 0x4832(%rip), %rcx      # 0x6fc8
callq 0x38f0
movq -0x1d0(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x2080
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x2130
movq -0x1c8(%rbp), %rdi
callq 0x24d0
movq -0x1c8(%rbp), %rdx
movq $0x0, -0xb8(%rbp)
leaq -0x80(%rbp), %rdi
leaq 0x28dc(%rip), %rsi      # 0x50c2
movb $0x0, %al
callq 0x2310
movq -0x10(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2340
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x2220
movl %eax, -0xbc(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x2370
movl %eax, %ecx
movl $0x2, %eax
cmpl %ecx, %eax
je 0x2876
movq 0x47bf(%rip), %rdi      # 0x6ff0
leaq 0x28b9(%rip), %rsi      # 0x50f1
callq 0x21b0
movq %rax, %rdi
movq 0x4799(%rip), %rsi      # 0x6fe0
callq 0x2300
movq -0xb8(%rbp), %rdi
callq 0x2090
movq %rax, %rsi
movq 0x478e(%rip), %rdi      # 0x6ff0
callq 0x21b0
movq %rax, %rdi
movq 0x476f(%rip), %rsi      # 0x6fe0
callq 0x2300
cmpl $0x0, -0xbc(%rbp)
jle 0x2c93
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jge 0x2c91
movq -0xb8(%rbp), %rdi
movl -0xc0(%rbp), %esi
xorl %edx, %edx
callq 0x20f0
movq %rax, -0x1e0(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x22c0
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0x3840
jmp 0x28e9
leaq -0xe1(%rbp), %rdi
callq 0x2380
xorl %eax, %eax
movl %eax, %edx
leaq -0x118(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movl $0x2, %ecx
callq 0x22d0
jmp 0x2913
xorl %eax, %eax
movl %eax, %esi
leaq -0x118(%rbp), %rdi
movl $0xa, %edx
callq 0x3970
movl %eax, -0x1e4(%rbp)
jmp 0x2930
leaq -0x118(%rbp), %rdi
callq 0x2240
movl -0x1e4(%rbp), %eax
movl %eax, -0xf8(%rbp)
movq $0x0, -0x158(%rbp)
movl -0xf8(%rbp), %edx
leaq 0x27aa(%rip), %rsi      # 0x510a
xorl %eax, %eax
leaq -0x150(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x2310
movq -0x1f8(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x2340
movq %rax, -0x1f0(%rbp)
jmp 0x298e
movq -0x1f0(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x20f0
movq %rax, -0x200(%rbp)
jmp 0x29b5
leaq -0x179(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x22c0
movq -0x200(%rbp), %rsi
movq -0x208(%rbp), %rdx
leaq -0x178(%rbp), %rdi
callq 0x3840
jmp 0x29e4
leaq -0x179(%rbp), %rdi
callq 0x2380
movq -0x158(%rbp), %rdi
callq 0x2170
jmp 0x29fe
movq -0xb8(%rbp), %rdi
movl -0xc0(%rbp), %esi
xorl %edx, %edx
callq 0x20f0
movq %rax, -0x210(%rbp)
jmp 0x2a1b
movq -0xb8(%rbp), %rdi
movl -0xc0(%rbp), %esi
movl $0x1, %edx
callq 0x20f0
movq %rax, -0x218(%rbp)
jmp 0x2a3b
movq -0xb8(%rbp), %rdi
movl -0xc0(%rbp), %esi
movl $0x3, %edx
callq 0x20f0
movq %rax, -0x220(%rbp)
jmp 0x2a5b
movq -0xb8(%rbp), %rdi
movl -0xc0(%rbp), %esi
movl $0x4, %edx
callq 0x20f0
movq %rax, -0x228(%rbp)
jmp 0x2a7b
movq -0xb8(%rbp), %rdi
movl -0xc0(%rbp), %esi
movl $0x5, %edx
callq 0x20f0
movq %rax, -0x230(%rbp)
jmp 0x2a9b
movq -0xb8(%rbp), %rdi
movl -0xc0(%rbp), %esi
movl $0x6, %edx
callq 0x20f0
movq %rax, -0x238(%rbp)
jmp 0x2abb
leaq -0x1c0(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x20a0
jmp 0x2ad0
movq -0x230(%rbp), %r9
movq -0x228(%rbp), %r8
movq -0x220(%rbp), %rcx
movq -0x218(%rbp), %rdx
movq -0x210(%rbp), %rsi
movq -0x238(%rbp), %rdi
subq $0x10, %rsp
movq %rsp, %rax
leaq -0x1c0(%rbp), %r10
movq %r10, 0x8(%rax)
movq %rdi, (%rax)
leaq -0x1a0(%rbp), %rdi
callq 0x2ce0
addq $0x10, %rsp
jmp 0x2b21
leaq -0x1c0(%rbp), %rdi
callq 0x2240
movq 0x447c(%rip), %rdi      # 0x6fb0
leaq -0x1a0(%rbp), %rsi
callq 0x2100
movq %rax, -0x240(%rbp)
jmp 0x2b49
movq -0x240(%rbp), %rdi
movq 0x4489(%rip), %rsi      # 0x6fe0
callq 0x2300
jmp 0x2b5e
movq 0x444b(%rip), %rdi      # 0x6fb0
movq 0x4474(%rip), %rsi      # 0x6fe0
callq 0x2300
jmp 0x2b73
leaq -0x1a0(%rbp), %rdi
callq 0x2240
leaq -0x178(%rbp), %rdi
callq 0x2240
leaq -0xe0(%rbp), %rdi
callq 0x2240
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x288d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0x2380
jmp 0x2cd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
jmp 0x2c83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x2240
jmp 0x2c83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x179(%rbp), %rdi
callq 0x2380
jmp 0x2c83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
jmp 0x2c77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x2240
jmp 0x2c77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x2240
leaq -0x178(%rbp), %rdi
callq 0x2240
leaq -0xe0(%rbp), %rdi
callq 0x2240
jmp 0x2cd0
jmp 0x2cb5
movq 0x4316(%rip), %rdi      # 0x6fb0
leaq 0x2491(%rip), %rsi      # 0x5132
callq 0x21b0
movq %rax, %rdi
movq 0x4330(%rip), %rsi      # 0x6fe0
callq 0x2300
movq -0xb8(%rbp), %rdi
callq 0x2170
movq -0x88(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
movq -0xf0(%rbp), %rdi
callq 0x2200
nopl (%rax)