// File: rishabh-battulwar[P]imageprocessing/./include/colorspace.h
// Function: GetColorTransform(colortransform*, char const*)
int GetColorTransform(colortransform *Trans, const char *TransformString)
{
	int LeftNumChars = 0, RightNumChars = 0, LeftSide = 1, LeftToRight = 0;
	int i, j, SrcSpaceId, DestSpaceId;
	char LeftSpace[16], RightSpace[16], c;
	
	
	Trans->NumStages = 0;
	Trans->Fun[0] = 0;
	Trans->Fun[1] = 0;
	
	/* Parse the transform string */
	while(1)
	{
		c = *(TransformString++);	/* Read the next character */
		
		if(!c)
			break;
		else if(c == '<')
		{
			LeftToRight = 0;
			LeftSide = 0;
		}
		else if(c == '>')
		{
			LeftToRight = 1;
			LeftSide = 0;
		}
		else if(c != ' ' && c != '-' && c != '=')
		{
			if(LeftSide)
			{	/* Append the character to LeftSpace */
				if(LeftNumChars < 15)
					LeftSpace[LeftNumChars++] = tolower(c);
			}
			else
			{	/* Append the character to RightSpace */
				if(RightNumChars < 15)
					RightSpace[RightNumChars++] = tolower(c);
			}
		}
	}
	
	/* Append null terminators on the LeftSpace and RightSpace strings */
	LeftSpace[LeftNumChars] = 0;
	RightSpace[RightNumChars] = 0;
	
	/* Convert names to colorspace enum */
	if(LeftToRight)
	{
		SrcSpaceId = IdFromName(LeftSpace);
		DestSpaceId = IdFromName(RightSpace);
	}
	else
	{
		SrcSpaceId = IdFromName(RightSpace);
		DestSpaceId = IdFromName(LeftSpace);
	}
	
	/* Is either space is unknown? (probably a parsing error) */
	if(SrcSpaceId == UNKNOWN_SPACE || DestSpaceId == UNKNOWN_SPACE)
		return 0;	/* Return failure */
	
	/* Is this an identity transform? */
	if(SrcSpaceId == DestSpaceId)
		return 1;	/* Return successfully */
	
	/* Search the TransformPair table for a direct transformation */
	for(i = 0; i < NUM_TRANSFORM_PAIRS; i++)
	{
		if(SrcSpaceId == TransformPair[i].Space[0] 
			&& DestSpaceId == TransformPair[i].Space[1])
		{
			Trans->NumStages = 1;
			Trans->Fun[0] = TransformPair[i].Fun[0];
			return 1;
		}
		else if(DestSpaceId == TransformPair[i].Space[0] 
			&& SrcSpaceId == TransformPair[i].Space[1])
		{
			Trans->NumStages = 1;
			Trans->Fun[0] = TransformPair[i].Fun[1];
			return 1;
		}
	}
	
	/* Search the TransformPair table for a two-stage transformation */
	for(i = 1; i < NUM_TRANSFORM_PAIRS; i++)
		if(SrcSpaceId == TransformPair[i].Space[1])
			for(j = 0; j < i; j++)
			{
				if(DestSpaceId == TransformPair[j].Space[1]
					&& TransformPair[i].Space[0] == TransformPair[j].Space[0])
				{
					Trans->NumStages = 2;
					Trans->Fun[0] = TransformPair[i].Fun[1];
					Trans->Fun[1] = TransformPair[j].Fun[0];
					return 1;
				}
			}
		else if(DestSpaceId == TransformPair[i].Space[1])
			for(j = 0; j < i; j++)
			{
				if(SrcSpaceId == TransformPair[j].Space[1]
					&& TransformPair[j].Space[0] == TransformPair[i].Space[0])
				{
					Trans->NumStages = 2;
					Trans->Fun[0] = TransformPair[j].Fun[1];
					Trans->Fun[1] = TransformPair[i].Fun[0];
					return 1;
				}
			}
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb (%rax), %al
movb %al, -0x61(%rbp)
cmpb $0x0, -0x61(%rbp)
jne 0xb27d
jmp 0xb328
movsbl -0x61(%rbp), %eax
cmpl $0x3c, %eax
jne 0xb299
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
jmp 0xb321
movsbl -0x61(%rbp), %eax
cmpl $0x3e, %eax
jne 0xb2b2
movl $0x1, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
jmp 0xb31f
movsbl -0x61(%rbp), %eax
cmpl $0x20, %eax
je 0xb31d
movsbl -0x61(%rbp), %eax
cmpl $0x2d, %eax
je 0xb31d
movsbl -0x61(%rbp), %eax
cmpl $0x3d, %eax
je 0xb31d
cmpl $0x0, -0x24(%rbp)
je 0xb2f7
cmpl $0xf, -0x1c(%rbp)
jge 0xb2f5
movsbl -0x61(%rbp), %edi
callq 0x22b0
movb %al, %cl
movl -0x1c(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1c(%rbp)
cltq
movb %cl, -0x50(%rbp,%rax)
jmp 0xb31b
cmpl $0xf, -0x20(%rbp)
jge 0xb319
movsbl -0x61(%rbp), %edi
callq 0x22b0
movb %al, %cl
movl -0x20(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x20(%rbp)
cltq
movb %cl, -0x60(%rbp,%rax)
jmp 0xb31b
jmp 0xb31d
jmp 0xb31f
jmp 0xb321
jmp 0xb323
jmp 0xb25e
movslq -0x1c(%rbp), %rax
movb $0x0, -0x50(%rbp,%rax)
movslq -0x20(%rbp), %rax
movb $0x0, -0x60(%rbp,%rax)
cmpl $0x0, -0x28(%rbp)
je 0xb35a
leaq -0x50(%rbp), %rdi
callq 0xb680
movl %eax, -0x34(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xb680
movl %eax, -0x38(%rbp)
jmp 0xb372
leaq -0x60(%rbp), %rdi
callq 0xb680
movl %eax, -0x34(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xb680
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0xb37e
cmpl $0x0, -0x38(%rbp)
jne 0xb38a
movl $0x0, -0x4(%rbp)
jmp 0xb66b
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0xb39e
movl $0x1, -0x4(%rbp)
jmp 0xb66b
movl $0x0, -0x2c(%rbp)
cmpl $0x12, -0x2c(%rbp)
jge 0xb48f
movl -0x34(%rbp), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x15833(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0xb416
movl -0x38(%rbp), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x1581a(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xb416
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movslq -0x2c(%rbp), %rcx
leaq 0x157f9(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xb66b
movl -0x38(%rbp), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x157cc(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0xb47d
movl -0x34(%rbp), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x157b3(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xb47d
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movslq -0x2c(%rbp), %rcx
leaq 0x15792(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xb66b
jmp 0xb47f
jmp 0xb481
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb3a5
movl $0x1, -0x2c(%rbp)
cmpl $0x12, -0x2c(%rbp)
jge 0xb664
movl -0x34(%rbp), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x15742(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xb57c
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xb577
movl -0x38(%rbp), %eax
movslq -0x30(%rbp), %rdx
leaq 0x15711(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xb567
movslq -0x2c(%rbp), %rcx
leaq 0x156fa(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movslq -0x30(%rbp), %rdx
leaq 0x156e6(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0xb567
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
movslq -0x2c(%rbp), %rcx
leaq 0x156c6(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x30(%rbp), %rcx
leaq 0x156a8(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xb66b
jmp 0xb569
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb4c5
jmp 0xb654
movl -0x38(%rbp), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x15666(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xb652
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xb650
movl -0x34(%rbp), %eax
movslq -0x30(%rbp), %rdx
leaq 0x15635(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xb640
movslq -0x30(%rbp), %rcx
leaq 0x1561e(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x1560a(%rip), %rcx     # 0x20bf0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0xb640
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
movslq -0x30(%rbp), %rcx
leaq 0x155ea(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x2c(%rbp), %rcx
leaq 0x155cc(%rip), %rax     # 0x20bf0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xb66b
jmp 0xb642
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb5a1
jmp 0xb652
jmp 0xb654
jmp 0xb656
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb496
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)