// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rdi, %rbx
movl $0x0, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movb (%rsi), %al
testb %al, %al
je 0x6eed
movq %rsi, %r14
incq %r14
movl $0x1, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r12d, %r12d
movzbl %al, %ecx
cmpl $0x3b, %ecx
jle 0x6e7a
cmpl $0x3c, %ecx
je 0x6ea9
cmpl $0x3d, %ecx
je 0x6eae
cmpl $0x3e, %ecx
jne 0x6e84
movl $0x1, %ebp
xorl %r13d, %r13d
jmp 0x6eae
cmpl $0x20, %ecx
je 0x6eae
cmpl $0x2d, %ecx
je 0x6eae
movsbl %al, %edi
testl %r13d, %r13d
je 0x6eba
movl $0x1, %r13d
cmpl $0xe, %r12d
jg 0x6eae
callq 0x2210
movslq %r12d, %rcx
incl %r12d
movb %al, 0x10(%rsp,%rcx)
jmp 0x6eae
xorl %r13d, %r13d
xorl %ebp, %ebp
movb (%r14), %al
incq %r14
testb %al, %al
jne 0x6e59
jmp 0x6ed0
cmpl $0xe, %r15d
jg 0x6e75
callq 0x2210
movslq %r15d, %rcx
incl %r15d
movb %al, (%rsp,%rcx)
jmp 0x6e75
movslq %r12d, %rax
movslq %r15d, %rcx
xorl %edx, %edx
movb %dl, 0x10(%rsp,%rax)
movb %dl, (%rsp,%rcx)
testl %ebp, %ebp
je 0x6ef6
movq %rsp, %r14
leaq 0x10(%rsp), %rdi
jmp 0x6efe
xorl %eax, %eax
movb %al, 0x10(%rsp)
movb %al, (%rsp)
leaq 0x10(%rsp), %r14
movq %rsp, %rdi
callq 0x705d
movl %eax, %ebp
movq %r14, %rdi
callq 0x705d
testl %ebp, %ebp
sete %dl
testl %eax, %eax
sete %sil
xorl %ecx, %ecx
orb %dl, %sil
jne 0x704c
movl $0x1, %ecx
cmpl %eax, %ebp
je 0x704c
leaq 0x8(%rbx), %rcx
leaq 0x10(%rbx), %rdx
leaq 0xecc5(%rip), %rdi      # 0x15c04
xorl %esi, %esi
movl -0x4(%rdi), %r8d
cmpl %r8d, %ebp
jne 0x6f52
cmpl (%rdi), %eax
je 0x6ffc
cmpl %r8d, %eax
jne 0x6f5f
cmpl (%rdi), %ebp
je 0x7012
addq $-0x18, %rsi
addq $0x18, %rdi
cmpq $-0x1b0, %rsi           # imm = 0xFE50
jne 0x6f41
movl $0x1, %edi
movl $0x18, %r8d
leaq 0xec7e(%rip), %rsi      # 0x15c00
leaq 0xec7f(%rip), %r9       # 0x15c08
leaq (%rdi,%rdi,2), %rcx
leaq (%rsi,%rcx,8), %rcx
movl 0x4(%rcx), %r10d
cmpl %r10d, %ebp
jne 0x6fba
movq %rdi, %r11
movq %r9, %r10
cmpl -0x4(%r10), %eax
jne 0x6faf
movl (%rcx), %r14d
cmpl -0x8(%r10), %r14d
je 0x6fec
addq $0x18, %r10
decq %r11
jne 0x6fa0
jmp 0x6fdb
cmpl %r10d, %eax
jne 0x6fdb
xorl %r10d, %r10d
cmpl 0x4(%r10,%rsi), %ebp
jne 0x6fd2
movl (%r10,%rsi), %r11d
cmpl (%rcx), %r11d
je 0x7028
addq $0x18, %r10
cmpq %r10, %r8
jne 0x6fc2
incq %rdi
addq $0x18, %r8
xorl %ecx, %ecx
cmpq $0x12, %rdi
jne 0x6f89
jmp 0x704c
movl $0x2, (%rbx)
movq 0x10(%rcx), %rax
movq %rax, 0x8(%rbx)
jmp 0x703e
movl $0x1, (%rbx)
leaq 0xebf7(%rip), %r10      # 0x15c00
subq %rsi, %r10
addq $0x8, %r10
jmp 0x7041
movl $0x1, (%rbx)
leaq 0xebe1(%rip), %r10      # 0x15c00
subq %rsi, %r10
addq $0x10, %r10
jmp 0x7041
movl $0x2, (%rbx)
movq 0x10(%r10,%rsi), %rax
movq %rax, 0x8(%rbx)
addq $0x8, %rcx
movq %rcx, %r10
movq %rdx, %rcx
movq (%r10), %rax
movq %rax, (%rcx)
movl $0x1, %ecx
movl %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq