// File: /workspace/github_cpp_makefile_star2_O2/burakbugrul[P]NginxLogParser/NginxParser.cpp
// Function: NginxParser::parse()
void NginxParser::parse(){
	
	ifstream input(input_file);
	int length, left, right, begin, end, bitrate, ten, http_status, sent_bytes;
	char line[MAX_LINE], type;
	string ip, id, user_agent;
	bool flag = true, cs_hit, cs_flag;
	
	while( input.getline(line,MAX_LINE,'\n') ){
		
		lines++;
		length = strlen(line);
		
		if( (ip = findIP(line)) == "-1" )
			continue;
		if( characterCount(line,length,'"') != 10 )
			continue;
		
		right = 0;
		flag = true;
		
		for( int i=0 ; i<5 ; i++ ){
			
			left = findCharacter(line,right,length,'"');
			right = findCharacter(line,left+1,length,'"');
			
			if( right-left == 2 ) // Empty parts
				continue;
			
			else if( strncmp(line+left+1,"GET",3)==0 || 
				strncmp(line+left+1,"POST",4)==0 || 
				strncmp(line+left+1,"HEAD",4)==0 || 
				strncmp(line+left+1,"PUT",3)==0 || 
				strncmp(line+left+1,"DELETE",6)==0 || 
				strncmp(line+left+1,"OPTIONS",7)==0 || 
				strncmp(line+left+1,"CONNECT",7)==0 ){ // Url part
				
				end = left;
				for( int j=0 ; j<2; j++ ){ // Finding ID
					begin = findCharacter(line,end+1,right,'/');
					end = findCharacter(line,begin+1,right,'/');
				}
				
				id = ""; // Saving ID
				for( int j=begin+1 ; j<end ; j++ )
					id += line[j];
				
				begin = findCharacter(line,end+1,right,'('); // Finding bitrate
				if( begin == right ){
					flag = false;
					break;
				}
				
				bitrate = (line[begin+1]-'0')*10+(line[begin+2]-'0');
				
				for( int j=begin+3 ; line[j]!=')' ; j++ ) // Saving bitrate
					bitrate = bitrate*10;
				
				begin = findCharacter(line,begin+1,right,'('); // Finding type
				if( begin == right ){
					flag = false;
					break;
				}
				
				type = line[begin+1]; // Saving type
				
			}
			
			else if( isdigit(line[left+2]) ){ // HTTP Status and sent bytes
				
				http_status = line[left+2]-'0'; // Saving HTTP Status
				
				sent_bytes = 0;
				ten = 1;
				for( int j=right-2 ; line[j]!=' ' ; j--,ten*=10 ) // Saving sent bytes
					sent_bytes += (line[j]-'0')*ten;
				
			}
			else{
				
				user_agent = "";

				for( int j=left+1 ; j < right && line[j] != ' ' ; j++ ) // Finding User Agent
					user_agent += line[j];
			}
			
		}
		
		cs_flag = false;
		for( int j=length-1 ; j>right ; j-- ) // Finding cs hit
			if( line[j] == 'c' && line[j+1] == 's' && line[j+2] == '=' ){
				cs_flag = true;
				cs_hit = (line[j+3] == 'H');
				break;
			}
		
		if( !flag || !cs_flag )
			continue;
		
		valid_lines++;
		total_data += sent_bytes;
		cs_hits += cs_hit;
		if( type == 'a' )
			audios++;
		else
			videos++;
		http_statuses[http_status-1]++;
		
		/* // This part is for comparing users by amount of their data transfers. If used, type of the second parameter of map should be 'long long int'
		 * if( users.find(ip) == users.end() )
			users[ip] = sent_bytes;
		else
			users[ip] += sent_bytes;
		*/
		
		// This part is for comparing users by amount of their data requests
		if( users.find(ip) == users.end() )
			users[ip] = 1;
		else
			users[ip] += 1;
		
		if( contents.find(id) == contents.end() )
			contents[id] = 1;
		else
			contents[id] ++;
			
		if( bitrates.find(bitrate) == bitrates.end() )
			bitrates[bitrate] = 1;
		else
			bitrates[bitrate] ++;
		
		if( user_agents.find(user_agent) == user_agents.end() )
			user_agents[user_agent] = 1;
		else
			user_agents[user_agent] ++;
		
	}
	
	input.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movq %rdi, %r13
leaq 0x28(%rdi), %rsi
leaq 0x2d0(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2230
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x80(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
leaq 0x60(%rsp), %rsi
movq %rsi, -0x10(%rsi)
andq $0x0, -0x8(%rsi)
movb %cl, (%rax)
movb %cl, (%rdx)
movb %cl, (%rsi)
leaq 0x110(%r13), %rax
movq %rax, 0x38(%rsp)
leaq 0xa0(%r13), %rax
movq %rax, 0x40(%rsp)
leaq 0x68(%r13), %rax
movq %rax, 0x28(%rsp)
leaq 0xd8(%r13), %rax
movq %rax, 0x20(%rsp)
leaq 0xd0(%rsp), %rbp
movq %rax, 0x10(%rsp)
movl $0x1f4, %edx            # imm = 0x1F4
leaq 0x2d0(%rsp), %rdi
movq %rbp, %rsi
pushq $0xa
popq %rcx
callq 0x2280
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
leaq 0xb0(%rsp), %r14
jne 0x2efa
incl (%r13)
movq %rbp, %rdi
callq 0x20c0
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rbx
movq %rbp, %rdx
callq 0x3452
leaq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x1616(%rip), %rsi      # 0x4060
callq 0x3444
movl %eax, %ebp
movq %r14, %rdi
callq 0x20e0
testb %bpl, %bpl
movq %rbx, %rbp
jne 0x29dc
movq %r13, %rdi
movq %rbp, %rsi
movq 0x8(%rsp), %rdx
pushq $0x22
popq %rcx
callq 0x3596
cmpl $0xa, %eax
jne 0x29dc
xorl %ebp, %ebp
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
cmpl $0x5, %eax
je 0x2d4a
movq %r13, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movq 0x8(%rsp), %r12
movl %r12d, %ecx
pushq $0x22
popq %rbp
movl %ebp, %r8d
callq 0x35b8
movl %eax, %r14d
leal 0x1(%r14), %edx
movq %r13, %rdi
movq %rbx, %rsi
movl %edx, 0x34(%rsp)
movl %r12d, %ecx
movl %ebp, %r8d
callq 0x35b8
movl %eax, %ebp
subl %r14d, %eax
cmpl $0x2, %eax
je 0x2cf6
movslq %r14d, %rcx
leaq 0xd1(%rsp), %rax
leaq (%rax,%rcx), %r12
movq %rcx, 0x48(%rsp)
movb 0xd1(%rsp,%rcx), %r15b
cmpb $0x47, %r15b
jne 0x2b0d
cmpb $0x45, 0x1(%r12)
jne 0x2b0d
cmpb $0x54, 0x2(%r12)
je 0x2bef
movq %r12, %rdi
leaq 0x154c(%rip), %rsi      # 0x4063
pushq $0x4
popq %rdx
callq 0x20f0
testl %eax, %eax
je 0x2bef
movq %r12, %rdi
leaq 0x1537(%rip), %rsi      # 0x4068
pushq $0x4
popq %rdx
callq 0x20f0
testl %eax, %eax
je 0x2bef
cmpb $0x50, %r15b
jne 0x2b5c
movq %r12, %rcx
cmpb $0x55, 0x1(%r12)
jne 0x2b5c
cmpb $0x54, 0x2(%rcx)
je 0x2bef
movq %r12, %rdi
leaq 0x1507(%rip), %rsi      # 0x406d
pushq $0x6
popq %rdx
callq 0x20f0
testl %eax, %eax
je 0x2bef
movq %r12, %rdi
leaq 0x14f8(%rip), %rsi      # 0x4074
pushq $0x7
popq %rdx
callq 0x20f0
testl %eax, %eax
je 0x2bef
movq %r12, %rdi
leaq 0x14ea(%rip), %rsi      # 0x407c
pushq $0x7
popq %rdx
callq 0x20f0
testl %eax, %eax
je 0x2bef
movq 0x48(%rsp), %rax
movsbl 0x2(%rax,%rbx), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2d01
movl %ebp, %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
addq %rsp, %rcx
addq $0xd0, %rcx
movl $0x0, 0x18(%rsp)
pushq $0x1
popq %rdx
movsbl (%rcx), %esi
cmpl $0x20, %esi
je 0x2d3d
addl $-0x30, %esi
imull %edx, %esi
addl %esi, 0x18(%rsp)
imull $0xa, %edx, %edx
decq %rcx
jmp 0x2bd1
pushq $0x2
popq %r15
subl $0x1, %r15d
jb 0x2c30
incl %r14d
movq %r13, %rdi
movq %rbx, %rsi
movl %r14d, %edx
movl %ebp, %ecx
pushq $0x2f
popq %r14
movl %r14d, %r8d
callq 0x35b8
movq %rax, 0x10(%rsp)
leal 0x1(%rax), %edx
movq %r13, %rdi
movq %rbx, %rsi
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x35b8
movl %eax, %r14d
jmp 0x2bf3
leaq 0x70(%rsp), %rdi
leaq 0x1515(%rip), %rsi      # 0x4151
callq 0x2270
movslq 0x10(%rsp), %r15
movslq %r14d, %r12
incq %r15
cmpq %r12, %r15
jge 0x2c69
movsbl 0xd0(%rsp,%r15), %esi
incq %r15
leaq 0x70(%rsp), %rdi
callq 0x2140
jmp 0x2c4c
incl %r14d
movq %r13, %rdi
movq %rbx, %r15
movq %rbx, %rsi
movl %r14d, %edx
movl %ebp, %ecx
pushq $0x28
popq %r8
callq 0x35b8
cmpl %ebp, %eax
je 0x2d43
movslq %eax, %rcx
leaq 0x1(%rcx), %rdx
movsbl 0xd1(%rsp,%rcx), %esi
imull $0xa, %esi, %esi
movsbl 0x2(%rcx,%r15), %ecx
addl %esi, %ecx
addl $0xfffffdf0, %ecx       # imm = 0xFFFFFDF0
movl %ecx, 0x4(%rsp)
addl $0x3, %eax
cltq
addq %rsp, %rax
addq $0xd0, %rax
cmpb $0x29, (%rax)
je 0x2cce
imull $0xa, %ecx, %ecx
movl %ecx, 0x4(%rsp)
incq %rax
jmp 0x2cbd
movq %r13, %rdi
movq %rbx, %r14
movq %rbx, %rsi
movl %ebp, %ecx
pushq $0x28
popq %r8
callq 0x35b8
cmpl %ebp, %eax
je 0x2d43
movq %rax, 0x10(%rsp)
cltq
movb 0x1(%rax,%r14), %al
movb %al, 0x3(%rsp)
movl 0x1c(%rsp), %eax
incl %eax
jmp 0x2a85
leaq 0x50(%rsp), %rdi
leaq 0x1444(%rip), %rsi      # 0x4151
callq 0x2270
movslq 0x34(%rsp), %r14
movslq %ebp, %r15
cmpq %r15, %r14
jge 0x2cf6
movb 0xd0(%rsp,%r14), %al
cmpb $0x20, %al
je 0x2cf6
movsbl %al, %esi
leaq 0x50(%rsp), %rdi
callq 0x2140
incq %r14
jmp 0x2d1a
movl %eax, 0x30(%rsp)
jmp 0x2cf6
movl %ebp, %eax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rsi
movslq %esi, %rax
movslq %ebp, %rcx
shlq $0x20, %rsi
movabsq $0x200000000, %rdx      # imm = 0x200000000
addq %rdx, %rsi
decq %rax
movq %rbx, %rbp
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
movl 0x1c(%rsp), %edi
cmpq %rcx, %rax
jle 0x29dc
cmpb $0x63, 0xd0(%rsp,%rax)
jne 0x2da1
cmpb $0x73, 0xd1(%rsp,%rax)
jne 0x2da1
cmpb $0x3d, 0xd2(%rsp,%rax)
je 0x2da9
addq %rdx, %rsi
decq %rax
jmp 0x2d7a
cmpl $0x5, %edi
jb 0x29dc
cmpq %rcx, %rax
jle 0x29dc
sarq $0x20, %rsi
xorl %eax, %eax
cmpb $0x48, 0xd0(%rsp,%rsi)
sete %al
incl 0x4(%r13)
movslq 0x18(%rsp), %rcx
addq %rcx, 0x148(%r13)
addl %eax, 0x8(%r13)
cmpb $0x61, 0x3(%rsp)
jne 0x2ded
incl 0x10(%r13)
jmp 0x2df1
incl 0xc(%r13)
movq 0x38(%rsp), %r14
movslq 0x30(%rsp), %rax
incl 0x10(%r13,%rax,4)
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
callq 0x35e0
movq 0x40(%rsp), %r15
testq %rax, %rax
je 0x2e2e
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
callq 0x36fc
incl (%rax)
jmp 0x2e44
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
callq 0x36fc
movl $0x1, (%rax)
movq %r15, %rdi
leaq 0x70(%rsp), %rsi
callq 0x35e0
testq %rax, %rax
je 0x2e67
movq %r15, %rdi
leaq 0x70(%rsp), %rsi
callq 0x36fc
incl (%rax)
jmp 0x2e7a
movq %r15, %rdi
leaq 0x70(%rsp), %rsi
callq 0x36fc
movl $0x1, (%rax)
movq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x3a8a
testq %rax, %rax
je 0x2ea1
movq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x3b06
incl (%rax)
jmp 0x2eb6
movq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x3b06
movl $0x1, (%rax)
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x35e0
testq %rax, %rax
je 0x2ee0
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x36fc
incl (%rax)
jmp 0x29dc
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x36fc
movl $0x1, (%rax)
jmp 0x29dc
leaq 0x2d0(%rsp), %rdi
callq 0x2040
leaq 0x50(%rsp), %rdi
callq 0x20e0
leaq 0x70(%rsp), %rdi
callq 0x20e0
leaq 0x90(%rsp), %rdi
callq 0x20e0
leaq 0x2d0(%rsp), %rdi
callq 0x2050
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
jmp 0x2f5b
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x20e0
leaq 0x70(%rsp), %rdi
callq 0x20e0
leaq 0x90(%rsp), %rdi
callq 0x20e0
leaq 0x2d0(%rsp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2260