// File: /workspace/github_c_makefile_star2_O1/inflex[P]ripMIME/tnef/tnef.c
// Function: TNEF_decode_tnef
int TNEF_decode_tnef(uint8 *tnef_stream, int size)
{

	int ra_response;
	uint32 tnefs;
	uint16 tnef_attachkey;
	uint8 *tsp;

	if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_decode_tnef:DEBUG: Start. Size = %d\n", FL,size);

	// TSP == TNEF Stream Pointer (well memory block actually!)
	//
	tsp = tnef_stream;

	// Read in the signature of this TNEF
	//
	ra_response = read_32(&tnefs, tsp);
	if ((ra_response != -1)&&(TNEF_SIGNATURE == tnefs))
	{
		if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_decode_tnef:DEBUG: TNEF signature is good\n",FL);
	} else {
		if (TNEF_VERBOSE) LOGGER_log("%s:%d:TNEF_decode_tnef:WARNING: Bad TNEF signature, expecting %lx got %lx\n",FL,TNEF_SIGNATURE,tnefs);
	}

	// Move tsp pointer along
	//
	tsp += sizeof(TNEF_SIGNATURE);

	/** Read the TNEF Attach key **/
	if (read_16(&tnef_attachkey, tsp) == -1) return -1;
	if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_decode_tnef:DEBUG: TNEF Attach Key: %x\n",FL,tnef_attachkey);

	// Move tsp pointer along
	//
	tsp += sizeof(uint16);

	// While we still have more bytes to process,
	//		go through entire memory block and extract
	//		all the required attributes and files
	//
	if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_decode_tnef:DEBUG: TNEF - Commence reading attributes\n",FL);
	while ((tsp - tnef_stream) < size)
	{
		if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_decode_tnef:DEBUG: Offset = %d\n", FL,tsp -TNEF_glb.tnef_home);
		ra_response = read_attribute(tsp);
		if ( ra_response > 0 )
		{
			tsp += ra_response;
		} else {

			// Must find out /WHY/ this happens, and, how to rectify the issue.

			tsp++;
			if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_decode_tnef:WARNING: TNEF - Attempting to read attribute at %d resulted in a sub-zero response, ending decoding to be safe\n",FL,tsp);
			break;
		}
	}

	if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_decode_tnef:DEBUG: Done.\n",FL);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
cmpl $0x0, 0x2347b(%rip)     # 0x2eeec
jle 0xba8f
leaq 0xba54(%rip), %rdi      # 0x174ce
leaq 0xb893(%rip), %rsi      # 0x17314
movl $0x2c0, %edx            # imm = 0x2C0
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc960
leaq 0x4(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xb3a2
cmpl $-0x1, %eax
setne %al
movl (%r14), %r8d
cmpl $0x223e9f78, %r8d       # imm = 0x223E9F78
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xbade
cmpl $0x0, 0x2342c(%rip)     # 0x2eeec
jle 0xbb06
leaq 0xba35(%rip), %rdi      # 0x174fe
leaq 0xb844(%rip), %rsi      # 0x17314
movl $0x2cb, %edx            # imm = 0x2CB
xorl %eax, %eax
callq 0xc960
jmp 0xbb06
cmpl $0x0, 0x233ff(%rip)     # 0x2eee4
jle 0xbb06
leaq 0xba46(%rip), %rdi      # 0x17534
leaq 0xb81f(%rip), %rsi      # 0x17314
movl $0x2cd, %edx            # imm = 0x2CD
movl $0x223e9f78, %ecx       # imm = 0x223E9F78
xorl %eax, %eax
callq 0xc960
leaq 0x4(%rbx), %rsi
leaq 0x2(%rsp), %rdi
callq 0xb3ed
cmpl $-0x1, %eax
je 0xbbc9
cmpl $0x0, 0x233c8(%rip)     # 0x2eeec
jle 0xbb45
movzwl 0x2(%rsp), %ecx
leaq 0xba4d(%rip), %rdi      # 0x1757f
leaq 0xb7db(%rip), %rsi      # 0x17314
movl $0x2d6, %edx            # imm = 0x2D6
xorl %eax, %eax
callq 0xc960
cmpl $0x0, 0x233a0(%rip)     # 0x2eeec
jle 0xbb68
leaq 0xba5d(%rip), %rdi      # 0x175b2
leaq 0xb7b8(%rip), %rsi      # 0x17314
movl $0x2e0, %edx            # imm = 0x2E0
xorl %eax, %eax
callq 0xc960
cmpl $0x7, %ebp
jl 0xbbf9
leaq 0x6(%rbx), %r14
movslq %ebp, %r13
leaq 0xba75(%rip), %r15      # 0x175f4
leaq 0xb78e(%rip), %r12      # 0x17314
cmpl $0x0, 0x2335f(%rip)     # 0x2eeec
jle 0xbbab
movq %r14, %rcx
subq 0x23767(%rip), %rcx     # 0x2f300
movq %r15, %rdi
movq %r12, %rsi
movl $0x2e3, %edx            # imm = 0x2E3
xorl %eax, %eax
callq 0xc960
movq %r14, %rdi
callq 0xb754
testl %eax, %eax
jle 0xbbd0
movl %eax, %eax
addq %rax, %r14
movq %r14, %rax
subq %rbx, %rax
cmpq %r13, %rax
jl 0xbb86
jmp 0xbbf9
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xbc22
cmpl $0x0, 0x23315(%rip)     # 0x2eeec
jle 0xbbf9
incq %r14
leaq 0xba3c(%rip), %rdi      # 0x1761f
leaq 0xb72a(%rip), %rsi      # 0x17314
movl $0x2ed, %edx            # imm = 0x2ED
movq %r14, %rcx
xorl %eax, %eax
callq 0xc960
cmpl $0x0, 0x232ec(%rip)     # 0x2eeec
jle 0xbc20
leaq 0xba9d(%rip), %rdi      # 0x176a6
leaq 0xb704(%rip), %rsi      # 0x17314
xorl %ebx, %ebx
movl $0x2f2, %edx            # imm = 0x2F2
xorl %eax, %eax
callq 0xc960
jmp 0xbc22
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq