// File: /workspace/github_cpp_makefile_star2_O3/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 0x6e52
movq %rsi, %r14
incq %r14
movl $0x1, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r12d, %r12d
movzbl %al, %ecx
cmpl $0x3b, %ecx
jle 0x6ddf
cmpl $0x3c, %ecx
je 0x6e0e
cmpl $0x3d, %ecx
je 0x6e13
cmpl $0x3e, %ecx
jne 0x6de9
movl $0x1, %ebp
xorl %r13d, %r13d
jmp 0x6e13
cmpl $0x20, %ecx
je 0x6e13
cmpl $0x2d, %ecx
je 0x6e13
movsbl %al, %edi
testl %r13d, %r13d
je 0x6e1f
movl $0x1, %r13d
cmpl $0xe, %r12d
jg 0x6e13
callq 0x2200
movslq %r12d, %rcx
incl %r12d
movb %al, 0x10(%rsp,%rcx)
jmp 0x6e13
xorl %r13d, %r13d
xorl %ebp, %ebp
movb (%r14), %al
incq %r14
testb %al, %al
jne 0x6dbe
jmp 0x6e35
cmpl $0xe, %r15d
jg 0x6dda
callq 0x2200
movslq %r15d, %rcx
incl %r15d
movb %al, (%rsp,%rcx)
jmp 0x6dda
movslq %r12d, %rax
movslq %r15d, %rcx
xorl %edx, %edx
movb %dl, 0x10(%rsp,%rax)
movb %dl, (%rsp,%rcx)
testl %ebp, %ebp
je 0x6e5b
movq %rsp, %r14
leaq 0x10(%rsp), %rdi
jmp 0x6e63
xorl %eax, %eax
movb %al, 0x10(%rsp)
movb %al, (%rsp)
leaq 0x10(%rsp), %r14
movq %rsp, %rdi
callq 0x6fc2
movl %eax, %ebp
movq %r14, %rdi
callq 0x6fc2
testl %ebp, %ebp
sete %dl
testl %eax, %eax
sete %sil
xorl %ecx, %ecx
orb %dl, %sil
jne 0x6fb1
movl $0x1, %ecx
cmpl %eax, %ebp
je 0x6fb1
leaq 0x8(%rbx), %rcx
leaq 0x10(%rbx), %rdx
leaq 0xed60(%rip), %rdi      # 0x15c04
xorl %esi, %esi
movl -0x4(%rdi), %r8d
cmpl %r8d, %ebp
jne 0x6eb7
cmpl (%rdi), %eax
je 0x6f61
cmpl %r8d, %eax
jne 0x6ec4
cmpl (%rdi), %ebp
je 0x6f77
addq $-0x18, %rsi
addq $0x18, %rdi
cmpq $-0x1b0, %rsi           # imm = 0xFE50
jne 0x6ea6
movl $0x1, %edi
movl $0x18, %r8d
leaq 0xed19(%rip), %rsi      # 0x15c00
leaq 0xed1a(%rip), %r9       # 0x15c08
leaq (%rdi,%rdi,2), %rcx
leaq (%rsi,%rcx,8), %rcx
movl 0x4(%rcx), %r10d
cmpl %r10d, %ebp
jne 0x6f1f
movq %rdi, %r11
movq %r9, %r10
cmpl -0x4(%r10), %eax
jne 0x6f14
movl (%rcx), %r14d
cmpl -0x8(%r10), %r14d
je 0x6f51
addq $0x18, %r10
decq %r11
jne 0x6f05
jmp 0x6f40
cmpl %r10d, %eax
jne 0x6f40
xorl %r10d, %r10d
cmpl 0x4(%r10,%rsi), %ebp
jne 0x6f37
movl (%r10,%rsi), %r11d
cmpl (%rcx), %r11d
je 0x6f8d
addq $0x18, %r10
cmpq %r10, %r8
jne 0x6f27
incq %rdi
addq $0x18, %r8
xorl %ecx, %ecx
cmpq $0x12, %rdi
jne 0x6eee
jmp 0x6fb1
movl $0x2, (%rbx)
movq 0x10(%rcx), %rax
movq %rax, 0x8(%rbx)
jmp 0x6fa3
movl $0x1, (%rbx)
leaq 0xec92(%rip), %r10      # 0x15c00
subq %rsi, %r10
addq $0x8, %r10
jmp 0x6fa6
movl $0x1, (%rbx)
leaq 0xec7c(%rip), %r10      # 0x15c00
subq %rsi, %r10
addq $0x10, %r10
jmp 0x6fa6
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