// File: kebwi[P]Trifid/src/main.cpp
// Function: programBehaviorNoisify()
void programBehaviorNoisify()
{
	readNoiseParamsFile();
	
	if (sInputFilenames.size() < 1)
		die("Supply at least one image as argument:\n  -- PGM - original gray image\n  -- PPM - original RGB image\n");
	
	for (int imageIdx = 0; imageIdx < sInputFilenames.size(); imageIdx++)
	{
		string fileExtension = sInputFilenames[imageIdx].substr(sInputFilenames[imageIdx].length() - 3, 3);
		myAssert(fileExtension == "pgm" || fileExtension == "ppm");
		
		if (fileExtension == "pgm")	//Noisify a grayscale image
		{
			ImageReal grayImg;
			grayImg.readFile(sInputFilenames[imageIdx]);
			
			if (sNoiseParams.ampGain_ >= 0)	//No auto-ISO
				addSensorNoise(grayImg, false, sNoiseParams);
			else addSensorNoiseWithAutoISO(grayImg, false, sNoiseParams);	//Auto-ISO
			
			cout << endl;
			grayImg.writeFile(1);
			//Write 16-bit file --- grayImg.writeFile(2);
		}
		else if (fileExtension == "ppm")	//Noisify a color image
		{
			Image3ChnlReal rgbImg;
			rgbImg.readFile(sInputFilenames[imageIdx]);
			
			if (!sBayerize)
			{
				if (sNoiseParams.ampGain_ >= 0)	//No auto-ISO
					addSensorNoise(rgbImg, false, sNoiseParams);
				else addSensorNoiseWithAutoISO(rgbImg, false, sNoiseParams);	//Auto-ISO
				
				cout << endl;
				rgbImg.writeFile(1);
				//Write 16-bit file --- rgbImg.writeFile(2);
			}
			else	//Bayerize
			{
				//Bayerize the input image (convert from rgb to gray)
				ImageReal grayImg;
				grayImg.resize(rgbImg.width(), rgbImg.height());
				bayer(rgbImg, grayImg);
				
				if (gGenerateIntermediateImages)
				{
					grayImg.writeFile(1);
					//Write 16-bit file --- grayImg.writeFile(2);
				}
				
				if (gGenerateIntermediateImages)
				{
					//Immediately deBayer
					//Strictly speaking, this isn't an "intermediate" image (ala gGenerateIntermediateImages),
					//but it might be interesting to see.
					deBayer(grayImg, rgbImg);
					rgbImg.writeFile(1);
				}
				
				//Denoise the gray Bayer image
				if (sNoiseParams.ampGain_ >= 0)	//No auto-ISO
					addSensorNoise(grayImg, true, sNoiseParams);
				else addSensorNoiseWithAutoISO(grayImg, true, sNoiseParams);	//Auto-ISO
				
				if (gGenerateIntermediateImages)
				{
					//Strictly speaking, this isn't an "intermediate" image (ala gGenerateIntermediateImages),
					//but it might be interesting to see.
					cout << endl;
					grayImg.writeFile(1);
					//Write 16-bit file --- grayImg.writeFile(2);
				}
				
				//Debayerize back to color
				deBayer(grayImg, rgbImg);
				rgbImg.writeFile(1);
				//Write 16-bit file --- rgbImg.writeFile(2);
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x6b0, %rsp            # imm = 0x6B0
callq 0x8350
leaq 0x51ae1(%rip), %rdi     # 0x5a5f8
callq 0xe730
cmpq $0x1, %rax
jae 0x8b2e
leaq 0x40d8a(%rip), %rdi     # 0x498b3
callq 0x5360
movl $0x0, -0x4(%rbp)
movslq -0x4(%rbp), %rax
movq %rax, -0x680(%rbp)
leaq 0x51ab1(%rip), %rdi     # 0x5a5f8
callq 0xe730
movq %rax, %rcx
movq -0x680(%rbp), %rax
cmpq %rcx, %rax
jae 0x9263
movslq -0x4(%rbp), %rsi
leaq 0x51a8e(%rip), %rdi     # 0x5a5f8
movq %rdi, -0x6a0(%rbp)
callq 0xe750
movq -0x6a0(%rbp), %rdi
movq %rax, -0x698(%rbp)
movslq -0x4(%rbp), %rsi
callq 0xe750
movq %rax, %rdi
callq 0x4550
movq -0x698(%rbp), %rsi
movq %rax, %rdx
addq $-0x3, %rdx
leaq -0x28(%rbp), %rdi
movq %rdi, -0x690(%rbp)
movl $0x3, %ecx
callq 0x43c0
movq -0x690(%rbp), %rdi
leaq 0x416f0(%rip), %rsi     # 0x4a2b6
callq 0xe570
movb %al, -0x681(%rbp)
jmp 0x8bd3
movb -0x681(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x6a1(%rbp)
jne 0x8c0e
jmp 0x8be8
leaq 0x418b8(%rip), %rsi     # 0x4a4a7
leaq -0x28(%rbp), %rdi
callq 0xe570
movb %al, -0x6a2(%rbp)
jmp 0x8c00
movb -0x6a2(%rbp), %al
movb %al, -0x6a1(%rbp)
jmp 0x8c0e
movb -0x6a1(%rbp), %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x5470
jmp 0x8c21
leaq 0x4168e(%rip), %rsi     # 0x4a2b6
leaq -0x28(%rbp), %rdi
callq 0xe570
movb %al, -0x6a3(%rbp)
jmp 0x8c39
movb -0x6a3(%rbp), %al
testb $0x1, %al
jne 0x8c48
jmp 0x8de2
leaq -0x78(%rbp), %rdi
callq 0x155e0
jmp 0x8c53
movslq -0x4(%rbp), %rsi
leaq 0x5199a(%rip), %rdi     # 0x5a5f8
callq 0xe750
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x4180
jmp 0x8c74
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x16200
jmp 0x8c86
leaq -0x98(%rbp), %rdi
callq 0x46c8
movsd 0x51a7e(%rip), %xmm0    # 0x5a718
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x8d3d
leaq 0x519ca(%rip), %rsi     # 0x5a678
leaq -0x148(%rbp), %rdi
callq 0xec90
jmp 0x8cbc
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
leaq -0x148(%rbp), %rdx
callq 0x203e0
jmp 0x8cd0
leaq -0x148(%rbp), %rdi
callq 0xe3d0
jmp 0x8d8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x9258
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x8dd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x46c8
jmp 0x8dd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xe3d0
jmp 0x8dd4
leaq 0x51934(%rip), %rsi     # 0x5a678
leaq -0x1f8(%rbp), %rdi
callq 0xec90
jmp 0x8d52
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
leaq -0x1f8(%rbp), %rdx
callq 0x22b50
jmp 0x8d66
leaq -0x1f8(%rbp), %rdi
callq 0xe3d0
jmp 0x8d8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0xe3d0
jmp 0x8dd4
movq 0x5123b(%rip), %rdi     # 0x59fd0
movq 0x5121c(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x8da3
leaq -0x218(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x1, %edx
callq 0x168c0
jmp 0x8dba
leaq -0x218(%rbp), %rdi
callq 0x46c8
leaq -0x78(%rbp), %rdi
callq 0x157e0
jmp 0x9241
leaq -0x78(%rbp), %rdi
callq 0x157e0
jmp 0x9258
leaq 0x416be(%rip), %rsi     # 0x4a4a7
leaq -0x28(%rbp), %rdi
callq 0xe570
movb %al, -0x6a4(%rbp)
jmp 0x8dfa
movb -0x6a4(%rbp), %al
testb $0x1, %al
jne 0x8e09
jmp 0x923f
leaq -0x268(%rbp), %rdi
callq 0x17000
jmp 0x8e17
movslq -0x4(%rbp), %rsi
leaq 0x517d6(%rip), %rdi     # 0x5a5f8
callq 0xe750
movq %rax, %rsi
leaq -0x288(%rbp), %rdi
callq 0x4180
jmp 0x8e38
leaq -0x268(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x17cc0
jmp 0x8e4d
leaq -0x288(%rbp), %rdi
callq 0x46c8
testb $0x1, 0x518e4(%rip)     # 0x5a744
jne 0x8f9a
movsd 0x518aa(%rip), %xmm0    # 0x5a718
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x8f03
leaq 0x517f6(%rip), %rsi     # 0x5a678
leaq -0x338(%rbp), %rdi
callq 0xec90
jmp 0x8e90
leaq -0x268(%rbp), %rdi
xorl %esi, %esi
leaq -0x338(%rbp), %rdx
callq 0x23510
jmp 0x8ea7
leaq -0x338(%rbp), %rdi
callq 0xe3d0
jmp 0x8f5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x9231
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x46c8
jmp 0x9231
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x338(%rbp), %rdi
callq 0xe3d0
jmp 0x9231
leaq 0x5176e(%rip), %rsi     # 0x5a678
leaq -0x3e8(%rbp), %rdi
callq 0xec90
jmp 0x8f18
leaq -0x268(%rbp), %rdi
xorl %esi, %esi
leaq -0x3e8(%rbp), %rdx
callq 0x23850
jmp 0x8f2f
leaq -0x3e8(%rbp), %rdi
callq 0xe3d0
jmp 0x8f5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x3e8(%rbp), %rdi
callq 0xe3d0
jmp 0x9231
movq 0x5106f(%rip), %rdi     # 0x59fd0
movq 0x51050(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x8f6f
leaq -0x408(%rbp), %rdi
leaq -0x268(%rbp), %rsi
movl $0x1, %edx
callq 0x18430
jmp 0x8f89
leaq -0x408(%rbp), %rdi
callq 0x46c8
jmp 0x9223
leaq -0x448(%rbp), %rdi
callq 0x155e0
jmp 0x8fa8
leaq -0x268(%rbp), %rdi
callq 0xedd0
movl %eax, -0x6a8(%rbp)
jmp 0x8fbc
leaq -0x268(%rbp), %rdi
callq 0xedf0
movl %eax, -0x6ac(%rbp)
jmp 0x8fd0
movl -0x6ac(%rbp), %edx
movl -0x6a8(%rbp), %esi
leaq -0x448(%rbp), %rdi
callq 0x15910
jmp 0x8fea
leaq -0x498(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x17170
jmp 0x8fff
leaq -0x498(%rbp), %rdi
leaq -0x448(%rbp), %rsi
callq 0x1d370
jmp 0x9014
leaq -0x498(%rbp), %rdi
callq 0x175b0
testb $0x1, 0x5158a(%rip)     # 0x5a5b1
je 0x907f
leaq -0x4b8(%rbp), %rdi
leaq -0x448(%rbp), %rsi
movl $0x1, %edx
callq 0x168c0
jmp 0x9043
leaq -0x4b8(%rbp), %rdi
callq 0x46c8
jmp 0x907f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x9215
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x498(%rbp), %rdi
callq 0x175b0
jmp 0x9215
testb $0x1, 0x5152b(%rip)     # 0x5a5b1
je 0x90c3
leaq -0x448(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x1d5b0
jmp 0x909d
leaq -0x4d8(%rbp), %rdi
leaq -0x268(%rbp), %rsi
movl $0x1, %edx
callq 0x18430
jmp 0x90b7
leaq -0x4d8(%rbp), %rdi
callq 0x46c8
movsd 0x5164d(%rip), %xmm0    # 0x5a718
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x912e
leaq 0x5159d(%rip), %rsi     # 0x5a678
leaq -0x588(%rbp), %rdi
callq 0xec90
jmp 0x90e9
leaq -0x448(%rbp), %rdi
movl $0x1, %esi
leaq -0x588(%rbp), %rdx
callq 0x203e0
jmp 0x9103
leaq -0x588(%rbp), %rdi
callq 0xe3d0
jmp 0x9188
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x588(%rbp), %rdi
callq 0xe3d0
jmp 0x9215
leaq 0x51543(%rip), %rsi     # 0x5a678
leaq -0x638(%rbp), %rdi
callq 0xec90
jmp 0x9143
leaq -0x448(%rbp), %rdi
movl $0x1, %esi
leaq -0x638(%rbp), %rdx
callq 0x22b50
jmp 0x915d
leaq -0x638(%rbp), %rdi
callq 0xe3d0
jmp 0x9188
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x638(%rbp), %rdi
callq 0xe3d0
jmp 0x9215
testb $0x1, 0x51422(%rip)     # 0x5a5b1
je 0x91cc
movq 0x50e38(%rip), %rdi     # 0x59fd0
movq 0x50e19(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x91a6
leaq -0x658(%rbp), %rdi
leaq -0x448(%rbp), %rsi
movl $0x1, %edx
callq 0x168c0
jmp 0x91c0
leaq -0x658(%rbp), %rdi
callq 0x46c8
leaq -0x448(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x1d5b0
jmp 0x91e1
leaq -0x678(%rbp), %rdi
leaq -0x268(%rbp), %rsi
movl $0x1, %edx
callq 0x18430
jmp 0x91fb
leaq -0x678(%rbp), %rdi
callq 0x46c8
leaq -0x448(%rbp), %rdi
callq 0x157e0
jmp 0x9223
leaq -0x448(%rbp), %rdi
callq 0x157e0
jmp 0x9231
leaq -0x268(%rbp), %rdi
callq 0x175b0
jmp 0x923f
leaq -0x268(%rbp), %rdi
callq 0x175b0
jmp 0x9258
jmp 0x9241
leaq -0x28(%rbp), %rdi
callq 0x46c8
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x8b35
leaq -0x28(%rbp), %rdi
callq 0x46c8
jmp 0x926c
addq $0x6b0, %rsp            # imm = 0x6B0
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)