// File: brianwu02[P]ImageProcessing/IPutil.cpp
// Function: IP_readImage(char*)
imageP
IP_readImage(char *file) 
{

	imageP	 I;
	int	 w, h, maxGray;
   	char  	 buf[1024];
	uchar	*out;

	// open binary file for reading
	ifstream inFile (file, ios::binary);
	
	// error checking
	if(!inFile) {
		cerr << "readImage: Can't open " << file << endl;
		exit(1);
	}

   	// verify that the image is in PGM format. 
   	inFile.getline(buf, 3);
   	if(strncmp(buf,"P5",2) && strncmp(buf,"P6",2)){
      		cerr << "The file " << file << " is not in PGM format" << endl;
      		inFile.close();
      		exit(1);
   	}

	// read width, height, and maximum gray value
	inFile >> w >> h >> maxGray;

	// skip over linefeed and carriage return
	inFile.getline(buf, 2);

	// allocate image and read file
	I = IP_allocImage(w, h, sizeof(uchar));
	out = I->image;
	inFile.read((char *) out, w*h);

	return (imageP) I;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x690, %rsp            # imm = 0x690
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x630(%rbp), %rdi
movl $0x4, %edx
callq 0x1180
movq -0x630(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x630(%rbp,%rax), %rdi
callq 0x1060
movb %al, -0x63d(%rbp)
jmp 0x1b04
movb -0x63d(%rbp), %al
testb $0x1, %al
jne 0x1b10
jmp 0x1b87
movq 0x34d9(%rip), %rdi      # 0x4ff0
leaq 0x1542(%rip), %rsi      # 0x3060
callq 0x10a0
movq %rax, -0x648(%rbp)
jmp 0x1b2c
movq -0x648(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x10a0
movq %rax, -0x650(%rbp)
jmp 0x1b45
movq -0x650(%rbp), %rdi
movq 0x346d(%rip), %rsi      # 0x4fc0
callq 0x10b0
jmp 0x1b5a
movl $0x1, %edi
callq 0x10e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x638(%rbp)
movl %eax, -0x63c(%rbp)
leaq -0x630(%rbp), %rdi
callq 0x1040
jmp 0x1d36
leaq -0x630(%rbp), %rdi
leaq -0x420(%rbp), %rsi
movl $0x3, %edx
callq 0x1050
jmp 0x1ba1
leaq -0x420(%rbp), %rdi
leaq 0x14c8(%rip), %rsi      # 0x3077
movl $0x2, %edx
callq 0x1070
cmpl $0x0, %eax
je 0x1c5d
leaq -0x420(%rbp), %rdi
leaq 0x14aa(%rip), %rsi      # 0x307a
movl $0x2, %edx
callq 0x1070
cmpl $0x0, %eax
je 0x1c5d
movq 0x340a(%rip), %rdi      # 0x4ff0
leaq 0x1490(%rip), %rsi      # 0x307d
callq 0x10a0
movq %rax, -0x658(%rbp)
jmp 0x1bfb
movq -0x658(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x10a0
movq %rax, -0x660(%rbp)
jmp 0x1c14
movq -0x660(%rbp), %rdi
leaq 0x1465(%rip), %rsi      # 0x3087
callq 0x10a0
movq %rax, -0x668(%rbp)
jmp 0x1c30
movq -0x668(%rbp), %rdi
movq 0x3382(%rip), %rsi      # 0x4fc0
callq 0x10b0
jmp 0x1c45
leaq -0x630(%rbp), %rdi
callq 0x1030
jmp 0x1c53
movl $0x1, %edi
callq 0x10e0
leaq -0x630(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x1080
movq %rax, -0x670(%rbp)
jmp 0x1c76
movq -0x670(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1080
movq %rax, -0x678(%rbp)
jmp 0x1c8f
movq -0x678(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x1080
jmp 0x1ca1
leaq -0x630(%rbp), %rdi
leaq -0x420(%rbp), %rsi
movl $0x2, %edx
callq 0x1050
jmp 0x1cbb
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
movl $0x1, %edx
callq 0x1d50
movq %rax, -0x680(%rbp)
jmp 0x1cd4
movq -0x680(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x428(%rbp)
movq -0x428(%rbp), %rsi
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
imull %ecx, %eax
movslq %eax, %rdx
leaq -0x630(%rbp), %rdi
callq 0x10f0
jmp 0x1d0f
movq -0x10(%rbp), %rax
movq %rax, -0x688(%rbp)
leaq -0x630(%rbp), %rdi
callq 0x1040
movq -0x688(%rbp), %rax
addq $0x690, %rsp            # imm = 0x690
popq %rbp
retq
movq -0x638(%rbp), %rdi
callq 0x1170
nopw %cs:(%rax,%rax)