// File: /workspace/github_cpp_makefile_star2_O1/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 $0x4f8, %rsp            # imm = 0x4F8
movq %rdi, %rbx
leaq 0x28(%rdi), %rsi
leaq 0x2f0(%rsp), %r13
movq %r13, %rdi
movl $0x8, %edx
callq 0x2250
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
xorl %eax, %eax
movq %rax, -0x8(%r15)
movb %al, (%r15)
leaq 0x80(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x110(%rbx), %rax
movq %rax, 0xc0(%rsp)
leaq 0xa0(%rbx), %rax
movq %rax, 0xb8(%rsp)
leaq 0x68(%rbx), %rax
movq %rax, 0x98(%rsp)
leaq 0xd8(%rbx), %rax
movq %rax, 0x20(%rsp)
movl $0x1f4, %edx            # imm = 0x1F4
movq %r13, %rdi
leaq 0xf0(%rsp), %rsi
movl $0xa, %ecx
callq 0x22a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x33c7
incl (%rbx)
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
callq 0x20d0
movq %rax, %rbp
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3ab6
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x21c0
movq %rax, %rdi
leaq 0x23c0(%rip), %rsi      # 0x5090
callq 0x2070
movl %eax, %r14d
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x2cfd
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2190
testl %r14d, %r14d
setne %al
testl %ebp, %ebp
setg %cl
testb %cl, %al
je 0x2c62
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpb $0x22, 0xf0(%rsp,%rcx)
sete %sil
addl %esi, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x2d1b
cmpl $0xa, %edx
jne 0x2c62
movq %rbx, 0x90(%rsp)
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0xa0(%rsp)
movslq %ebp, %rax
movq %rax, 0xa8(%rsp)
movq $0x0, 0xb0(%rsp)
movb $0x1, 0x18(%rsp)
xorl %r15d, %r15d
cmpl %ebp, %r15d
jge 0x2d97
movslq %r15d, %rax
addq %rsp, %rax
addq $0xf0, %rax
cmpb $0x22, (%rax)
je 0x2d97
incl %r15d
incq %rax
cmpl %r15d, %ebp
jne 0x2d83
movl %ebp, %edx
jmp 0x2d9a
movl %r15d, %edx
cmpl %ebp, %edx
movl %ebp, %r12d
cmovll %edx, %r12d
leal 0x1(%r12), %esi
movl %esi, %ebx
cmpl %ebp, %esi
jge 0x2dde
movslq %edx, %rax
movq 0xa8(%rsp), %rcx
cmpq %rcx, %rax
cmovgeq %rcx, %rax
leal 0x1(%rax), %ebx
leaq 0xf1(%rsp), %rcx
addq %rcx, %rax
cmpb $0x22, (%rax)
je 0x2dde
incl %ebx
incq %rax
cmpl %ebx, %ebp
jne 0x2dce
movl %ebp, %ebx
cmpl %ebp, %ebx
movl %ebp, %r15d
cmovll %ebx, %r15d
movl %r15d, %r14d
subl %r12d, %r14d
cmpl $0x2, %r14d
je 0x310d
movl %esi, 0x28(%rsp)
movl %edx, 0x2c(%rsp)
movslq %r12d, %rcx
leaq 0xf1(%rsp), %rax
movq %rcx, 0xc8(%rsp)
leaq (%rax,%rcx), %rdi
movl $0x3, %edx
movq %rdi, %r13
leaq 0x226e(%rip), %rsi      # 0x5093
callq 0x20e0
testl %eax, %eax
je 0x2f5c
movl $0x4, %edx
movq %r13, %rdi
leaq 0x2256(%rip), %rsi      # 0x5097
callq 0x20e0
testl %eax, %eax
je 0x2f5c
movl $0x4, %edx
movq %r13, %rdi
leaq 0x223f(%rip), %rsi      # 0x509c
callq 0x20e0
testl %eax, %eax
je 0x2f5c
movl $0x3, %edx
movq %r13, %rdi
leaq 0x2228(%rip), %rsi      # 0x50a1
callq 0x20e0
testl %eax, %eax
je 0x2f5c
movl $0x6, %edx
movq %r13, %rdi
leaq 0x2210(%rip), %rsi      # 0x50a5
callq 0x20e0
testl %eax, %eax
je 0x2f5c
movl $0x7, %edx
movq %r13, %rdi
leaq 0x21fb(%rip), %rsi      # 0x50ac
callq 0x20e0
testl %eax, %eax
je 0x2f5c
movl $0x7, %edx
movq %r13, %rdi
leaq 0x21e7(%rip), %rsi      # 0x50b4
callq 0x20e0
testl %eax, %eax
je 0x2f5c
leaq 0xf0(%rsp), %rax
movq 0xc8(%rsp), %rcx
movsbl 0x2(%rcx,%rax), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x3138
movslq %r15d, %rcx
movb 0xee(%rsp,%rcx), %sil
movl $0x0, 0x14(%rsp)
cmpb $0x20, %sil
leaq 0x2f0(%rsp), %r13
je 0x2f53
addq $-0x2, %rcx
leaq 0xef(%rsp), %rdx
addq %rdx, %rcx
movl $0x1, %edx
xorl %edi, %edi
movsbl %sil, %esi
addl $-0x30, %esi
imull %edx, %esi
addl %esi, %edi
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movb (%rcx), %sil
decq %rcx
cmpb $0x20, %sil
jne 0x2f32
movl %edi, 0x14(%rsp)
movl %eax, 0x10(%rsp)
jmp 0x310d
movslq %ebx, %rax
xorl %ecx, %ecx
leaq 0xf1(%rsp), %rsi
movq 0xa8(%rsp), %rdi
leal 0x1(%r12), %r14d
cmpl %r15d, %r14d
jge 0x2f94
movslq %r12d, %rdx
addq %rsi, %rdx
cmpb $0x2f, (%rdx)
je 0x2f94
incl %r14d
incq %rdx
cmpl %r14d, %r15d
jne 0x2f81
movl %r15d, %r14d
cmpl %r15d, %r14d
movl %r15d, %r12d
cmovll %r14d, %r12d
incl %r12d
cmpl %r15d, %r12d
jge 0x2fd1
movslq %r14d, %rdx
cmpq %rax, %rdx
cmovgeq %rax, %rdx
cmpq %rdi, %rdx
cmovgeq %rdi, %rdx
leal 0x1(%rdx), %r12d
addq %rsi, %rdx
cmpb $0x2f, (%rdx)
je 0x2fd1
incl %r12d
incq %rdx
cmpl %r12d, %r15d
jne 0x2fbe
movl %r15d, %r12d
cmpl %r15d, %r12d
cmovgel %r15d, %r12d
leal 0x1(%rcx), %edx
testl %ecx, %ecx
movl %edx, %ecx
je 0x2f71
movq 0x78(%rsp), %rdx
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
leaq 0x2195(%rip), %rcx      # 0x5189
xorl %r8d, %r8d
callq 0x2230
cmpl %ebx, %r14d
cmovgel %ebx, %r14d
movslq %r14d, %r14
movq 0xa0(%rsp), %rax
cmpq %rax, %r14
cmovgeq %rax, %r14
movslq %r12d, %r13
incq %r14
cmpq %r13, %r14
jge 0x3038
movsbl 0xf0(%rsp,%r14), %esi
incq %r14
leaq 0x70(%rsp), %rdi
callq 0x2160
jmp 0x301b
incl %r12d
cmpl %r15d, %r12d
jge 0x3069
movslq %r12d, %rax
addq %rsp, %rax
addq $0xf0, %rax
leaq 0x2f0(%rsp), %r13
cmpb $0x28, (%rax)
je 0x3071
incl %r12d
incq %rax
cmpl %r12d, %r15d
jne 0x3054
movl %r15d, %r12d
jmp 0x3071
leaq 0x2f0(%rsp), %r13
cmpl %r12d, %r15d
jle 0x31b8
movslq %r12d, %rax
movsbl 0xf1(%rsp,%rax), %ecx
leal (%rcx,%rcx,4), %ecx
leaq 0xf0(%rsp), %rdx
movsbl 0x2(%rax,%rdx), %edx
leal (%rdx,%rcx,2), %ecx
addl $0xfffffdf0, %ecx       # imm = 0xFFFFFDF0
movl %ecx, 0xc(%rsp)
cmpb $0x29, 0xf3(%rsp,%rax)
je 0x30cd
leaq 0x3(%rax), %rdx
leaq 0xf1(%rsp), %rsi
addq %rsi, %rdx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
cmpb $0x29, (%rdx)
leaq 0x1(%rdx), %rdx
jne 0x30bb
movl %ecx, 0xc(%rsp)
leaq 0x1(%rax), %rcx
cmpl %r15d, %ecx
jge 0x30f1
addq %rsp, %rax
addq $0xf1, %rax
cmpb $0x28, (%rax)
je 0x30f1
incl %ecx
incq %rax
cmpl %ecx, %r15d
jne 0x30df
movl %r15d, %ecx
cmpl %ecx, %r15d
jle 0x31b8
movslq %ecx, %rax
leaq 0xf0(%rsp), %rcx
movb 0x1(%rax,%rcx), %al
movb %al, 0xb(%rsp)
movq 0xb0(%rsp), %rax
cmpl $0x4, %eax
leal 0x1(%rax), %eax
setb 0x18(%rsp)
movl %eax, %ecx
movq %rcx, 0xb0(%rsp)
cmpl $0x5, %eax
jne 0x2d72
jmp 0x31b8
leaq 0x2f0(%rsp), %r13
movq 0x58(%rsp), %rdx
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
leaq 0x2036(%rip), %rcx      # 0x5189
xorl %r8d, %r8d
callq 0x2230
cmpl %r15d, 0x28(%rsp)
movl 0x2c(%rsp), %eax
jge 0x310d
cltq
movq 0xa0(%rsp), %rcx
cmpq %rcx, %rax
cmovgeq %rcx, %rax
leaq (%rsp,%rax), %r12
addq $0xf0, %r12
movl %r14d, %eax
movq %rax, 0x18(%rsp)
movl $0x1, %r14d
movb (%r12,%r14), %al
cmpb $0x20, %al
je 0x310d
movsbl %al, %esi
leaq 0x50(%rsp), %rdi
callq 0x2160
incq %r14
cmpl %r14d, 0x18(%rsp)
jne 0x3190
jmp 0x310d
leal -0x1(%rbp), %ecx
cmpl %ecx, %ebx
setge %al
jl 0x31d1
leaq 0x40(%rsp), %r15
movq 0x90(%rsp), %rbx
jmp 0x322d
movslq %ecx, %rcx
movslq %r15d, %rdx
leaq 0x40(%rsp), %r15
movq 0x90(%rsp), %rbx
cmpb $0x63, 0xf0(%rsp,%rcx)
jne 0x320b
movslq %ebp, %rsi
cmpb $0x73, 0xf0(%rsp,%rsi)
jne 0x320b
leal 0x1(%rbp), %esi
movslq %esi, %rsi
cmpb $0x3d, 0xf0(%rsp,%rsi)
je 0x321a
decq %rcx
decl %ebp
cmpq %rdx, %rcx
setle %al
jg 0x31e4
jmp 0x322d
addl $0x2, %ebp
movslq %ebp, %rcx
cmpb $0x48, 0xf0(%rsp,%rcx)
sete 0xa(%rsp)
movb 0x18(%rsp), %cl
orb %al, %cl
testb $0x1, %cl
jne 0x2c62
incl 0x4(%rbx)
movslq 0x14(%rsp), %rax
addq %rax, 0x148(%rbx)
movb 0xa(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, 0x8(%rbx)
cmpb $0x61, 0xb(%rsp)
movq 0xc0(%rsp), %r14
movq 0xb8(%rsp), %r12
jne 0x3273
incl 0x10(%rbx)
jmp 0x3276
incl 0xc(%rbx)
movl 0x10(%rsp), %eax
cltq
incl 0x10(%rbx,%rax,4)
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x3cd6
testq %rax, %rax
je 0x32a3
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x3dee
incl (%rax)
jmp 0x32b6
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x3dee
movl $0x1, (%rax)
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3cd6
testq %rax, %rax
je 0x32d9
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3dee
incl (%rax)
jmp 0x32ec
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3dee
movl $0x1, (%rax)
movslq 0xc(%rsp), %rcx
movq 0x68(%rbx), %rdi
movq 0x70(%rbx), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rsi
movq (%rdi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x334a
movq (%rdx), %r9
movq %rdx, %rax
cmpl 0x8(%r9), %ecx
je 0x334a
movq %r9, %r10
movq (%r9), %r9
testq %r9, %r9
je 0x3348
movslq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
movl $0x0, %eax
cmpq %rsi, %rdx
jne 0x334a
movq %r10, %rax
cmpl %edi, %ecx
jne 0x331e
jmp 0x334a
xorl %eax, %eax
testq %rax, %rax
je 0x336b
cmpq $0x0, (%rax)
je 0x336b
movq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x4190
incl (%rax)
jmp 0x3383
movq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x4190
movl $0x1, (%rax)
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x3cd6
testq %rax, %rax
je 0x33ad
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x3dee
incl (%rax)
jmp 0x2c62
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x3dee
movl $0x1, (%rax)
jmp 0x2c62
leaq 0x2f0(%rsp), %rdi
callq 0x2040
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x33f0
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x3412
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x3429
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x2f0(%rsp), %rdi
callq 0x2050
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3458
jmp 0x3458
jmp 0x3458
jmp 0x345d
jmp 0x3458
jmp 0x3458
jmp 0x345d
jmp 0x3458
movq %rax, %rbx
jmp 0x3465
movq %rax, %rbx
leaq 0x40(%rsp), %r15
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x3481
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x34a3
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x34ba
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x2f0(%rsp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2280
nop