// File: /workspace/github_c_makefile_star2_O2/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, 0x2298a(%rip)     # 0x2deec
jle 0xb580
leaq 0xaf93(%rip), %rdi      # 0x164fe
leaq 0xadd2(%rip), %rsi      # 0x16344
movl $0x2c0, %edx            # imm = 0x2C0
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc2a1
leaq 0x4(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xaf2b
cmpl $-0x1, %eax
setne %al
movl (%r14), %r8d
cmpl $0x223e9f78, %r8d       # imm = 0x223E9F78
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xb5cf
cmpl $0x0, 0x2293b(%rip)     # 0x2deec
jle 0xb5f7
leaq 0xaf74(%rip), %rdi      # 0x1652e
leaq 0xad83(%rip), %rsi      # 0x16344
movl $0x2cb, %edx            # imm = 0x2CB
xorl %eax, %eax
callq 0xc2a1
jmp 0xb5f7
cmpl $0x0, 0x2290e(%rip)     # 0x2dee4
jle 0xb5f7
leaq 0xaf85(%rip), %rdi      # 0x16564
leaq 0xad5e(%rip), %rsi      # 0x16344
movl $0x2cd, %edx            # imm = 0x2CD
movl $0x223e9f78, %ecx       # imm = 0x223E9F78
xorl %eax, %eax
callq 0xc2a1
leaq 0x4(%rbx), %rsi
leaq 0x2(%rsp), %rdi
callq 0xaf74
cmpl $-0x1, %eax
je 0xb6b1
cmpl $0x0, 0x228d7(%rip)     # 0x2deec
jle 0xb659
movzwl 0x2(%rsp), %ecx
leaq 0xaf8c(%rip), %rdi      # 0x165af
leaq 0xad1a(%rip), %rsi      # 0x16344
movl $0x2d6, %edx            # imm = 0x2D6
xorl %eax, %eax
callq 0xc2a1
cmpl $0x0, 0x228af(%rip)     # 0x2deec
jle 0xb659
leaq 0xaf9c(%rip), %rdi      # 0x165e2
leaq 0xacf7(%rip), %rsi      # 0x16344
movl $0x2e0, %edx            # imm = 0x2E0
xorl %eax, %eax
callq 0xc2a1
leaq 0x6(%rbx), %r14
movslq %ebp, %r13
leaq 0xafbd(%rip), %r15      # 0x16624
leaq 0xacd6(%rip), %r12      # 0x16344
movq %r14, %rax
subq %rbx, %rax
cmpq %r13, %rax
jge 0xb6df
cmpl $0x0, 0x2286c(%rip)     # 0x2deec
jle 0xb69e
movq %r14, %rcx
subq 0x22c74(%rip), %rcx     # 0x2e300
movq %r15, %rdi
movq %r12, %rsi
movl $0x2e3, %edx            # imm = 0x2E3
xorl %eax, %eax
callq 0xc2a1
movq %r14, %rdi
callq 0xb26b
testl %eax, %eax
jle 0xb6b6
movl %eax, %eax
addq %rax, %r14
jmp 0xb66e
pushq $-0x1
popq %rbx
jmp 0xb708
cmpl $0x0, 0x2282f(%rip)     # 0x2deec
jle 0xb706
incq %r14
leaq 0xaf86(%rip), %rdi      # 0x1664f
leaq 0xac74(%rip), %rsi      # 0x16344
movl $0x2ed, %edx            # imm = 0x2ED
movq %r14, %rcx
xorl %eax, %eax
callq 0xc2a1
cmpl $0x0, 0x22806(%rip)     # 0x2deec
jle 0xb706
leaq 0xafe7(%rip), %rdi      # 0x166d6
leaq 0xac4e(%rip), %rsi      # 0x16344
xorl %ebx, %ebx
movl $0x2f2, %edx            # imm = 0x2F2
xorl %eax, %eax
callq 0xc2a1
jmp 0xb708
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq