// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
andl $0x0, (%rdi)
leaq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x10(%rdi), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movq %rdi, 0x8(%rsp)
movups %xmm0, 0x8(%rdi)
xorl %ebp, %ebp
pushq $0x1
popq %rdx
xorl %r12d, %r12d
xorl %r15d, %r15d
movl %edx, %eax
incq %r14
movzbl -0x1(%r14), %ecx
cmpl $0x20, %ecx
je 0x5de4
cmpl $0x2d, %ecx
je 0x5de4
cmpl $0x3d, %ecx
je 0x5de4
movl %ebp, %r13d
movslq %r12d, %rbx
testl %ecx, %ecx
je 0x5e5d
cmpl $0x3c, %ecx
je 0x5e16
cmpl $0x3e, %ecx
jne 0x5e1d
xorl %eax, %eax
movl %edx, %r15d
jmp 0x5de4
xorl %eax, %eax
xorl %r15d, %r15d
jmp 0x5de4
movsbl %cl, %edi
testl %eax, %eax
je 0x5e2d
movl %edx, %eax
cmpl $0xe, %ebp
ja 0x5de4
jmp 0x5e4b
xorl %eax, %eax
cmpl $0xe, %r12d
jg 0x5de4
movl %edx, %r13d
callq 0x21f0
movl %r13d, %edx
incl %r12d
movb %al, 0x20(%rsp,%rbx)
xorl %eax, %eax
jmp 0x5de4
movl %edx, %ebx
callq 0x21f0
movl %ebx, %edx
incl %ebp
movb %al, 0x30(%rsp,%r13)
jmp 0x5de2
xorl %ebp, %ebp
movb %bpl, 0x30(%rsp,%r13)
movb %bpl, 0x20(%rsp,%rbx)
testl %r15d, %r15d
leaq 0x20(%rsp), %r15
leaq 0x30(%rsp), %rax
movq %rax, %rdi
cmoveq %r15, %rdi
cmoveq %rax, %r15
callq 0x5ff1
movl %eax, %r14d
movq %r15, %rdi
callq 0x5ff1
testl %r14d, %r14d
sete %cl
testl %eax, %eax
sete %dl
orb %cl, %dl
jne 0x5fdc
pushq $0x1
popq %rbp
cmpl %eax, %r14d
je 0x5fdc
leaq 0xed4d(%rip), %rdx      # 0x14c04
xorl %ecx, %ecx
cmpq $-0x1b0, %rcx           # imm = 0xFE50
je 0x5ee9
movl -0x4(%rdx), %esi
cmpl %esi, %r14d
jne 0x5ed2
cmpl (%rdx), %eax
je 0x5f7b
cmpl %esi, %eax
jne 0x5edf
cmpl (%rdx), %r14d
je 0x5f96
addq $-0x18, %rcx
addq $0x18, %rdx
jmp 0x5eb9
pushq $0x1
popq %rdx
pushq $0x18
popq %rsi
leaq 0xed0a(%rip), %rcx      # 0x14c00
leaq 0xed0b(%rip), %rdi      # 0x14c08
cmpq $0x12, %rdx
je 0x5fed
imulq $0x18, %rdx, %r9
leaq (%rcx,%r9), %r8
movl 0x4(%r9,%rcx), %r9d
cmpl %r9d, %r14d
jne 0x5f3a
movq %rdi, %r9
movq %rdx, %r10
subq $0x1, %r10
jb 0x5f5d
cmpl -0x4(%r9), %eax
jne 0x5f34
movl (%r8), %r11d
cmpl -0x8(%r9), %r11d
je 0x5f66
addq $0x18, %r9
jmp 0x5f1f
cmpl %r9d, %eax
jne 0x5f5d
xorl %r9d, %r9d
cmpq %r9, %rsi
je 0x5f5d
cmpl 0x4(%r9,%rcx), %r14d
jne 0x5f57
movl (%r9,%rcx), %r10d
cmpl (%r8), %r10d
je 0x5fb6
addq $0x18, %r9
jmp 0x5f42
incq %rdx
addq $0x18, %rsi
jmp 0x5efd
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%r8), %rax
movq %rax, 0x8(%rcx)
jmp 0x5fd1
movq 0x8(%rsp), %rax
movl $0x1, (%rax)
leaq 0xec73(%rip), %r9       # 0x14c00
subq %rcx, %r9
addq $0x8, %r9
jmp 0x5faf
movq 0x8(%rsp), %rax
movl $0x1, (%rax)
leaq 0xec58(%rip), %r9       # 0x14c00
subq %rcx, %r9
addq $0x10, %r9
movq 0x18(%rsp), %rcx
jmp 0x5fd6
movq 0x8(%rsp), %rdx
movl $0x2, (%rdx)
movq 0x10(%r9,%rcx), %rax
movq %rax, 0x8(%rdx)
addq $0x8, %r8
movq %r8, %r9
movq 0x10(%rsp), %rcx
movq (%r9), %rax
movq %rax, (%rcx)
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x5fdc