// File: /workspace/github_c_makefile_star2_O1/inflex[P]ripMIME/tnef/tnef.c
// Function: TNEF_main
int TNEF_main( char *filename )
{
	FILE *fp;
	struct stat sb;
	uint8 *tnef_stream;
	int size, nread;

	if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_main:DEBUG: Start, decoding %s\n",FL, filename);

	if (TNEF_glb.savedata == 0 )
	{
		if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_name:DEBUG: decode_tnef is set to 0, not decoding file.",FL);
		return 0;
	}


	// Test to see if the file actually exists
	//
	if (stat(filename,&sb) == -1)
	{
		LOGGER_log("%s:%d:TNEF_main:ERROR: while attempting to get details on file %s (%s)\n", FL, filename,strerror(errno));
		return -1;
	}

	// Get the filesize
	//
	size = sb.st_size;

	// Allocate enough memory to read in the ENTIRE file
	// FIXME - This could be a real consumer if multiple
	// instances of TNEF decoding is going on
	//
	TNEF_glb.tnef_home = tnef_stream = (uint8 *)malloc(size);
	TNEF_glb.tnef_limit = TNEF_glb.tnef_home +size;

	// If we were unable to allocate enough memory, then we
	// should report this
	//
	if (tnef_stream == NULL)
	{
		LOGGER_log("%s:%d:TNEF_main:ERROR: When allocating %d bytes for loading file (%s)\n", FL, size,strerror(errno));
		if (TNEF_glb.tnef_home) free(TNEF_glb.tnef_home);
		return -1;
	}

	// Attempt to open up the TNEF encoded file... if it fails
	// 	then report the failed condition to syslog
	//
	if ((fp = fopen(filename,"r")) == NULL)
	{
		LOGGER_log("%s:%d:TNEF_main:ERROR: opening file %s for reading (%s)\n", FL, filename,strerror(errno));
		if (TNEF_glb.tnef_home) free(TNEF_glb.tnef_home);
		return -1;
	}

	// Attempt to read in the entire file
	//
	nread = fread(tnef_stream, sizeof(uint8), size, fp);

	if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_main:DEBUG: Read %d bytes\n", FL, nread);

	// If we did not read in all the bytes, then let syslogs know!
	//
	if (nread < size)
	{
		LOGGER_log("%s:%d:TNEF_main:ERROR: while reading stream from file %s (%s)\n", FL, filename,strerror(errno));
		if (TNEF_glb.tnef_home) free(TNEF_glb.tnef_home);
		return -1;
	}

	// Close the file
	//
	fclose(fp);

	// Proceed to decode the file
	//
	TNEF_decode_tnef(tnef_stream,size);

	if (TNEF_glb.tnef_home) free(TNEF_glb.tnef_home);


	if (TNEF_DEBUG) LOGGER_log("%s:%d:TNEF_main:DEBUG: finished decoding.\n",FL);

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rdi, %rbx
cmpl $0x0, 0x2329f(%rip)     # 0x2eeec
jle 0xbc6c
leaq 0xba75(%rip), %rdi      # 0x176cb
leaq 0xb6b7(%rip), %rsi      # 0x17314
movl $0x30a, %edx            # imm = 0x30A
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc960
cmpl $0x0, 0x23685(%rip)     # 0x2f2f8
je 0xbd3e
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x2250
cmpl $-0x1, %eax
je 0xbd6c
movq 0x30(%rsp), %r14
movslq %r14d, %r13
movq %r13, %rdi
callq 0x22b0
movq %rax, %r15
movq %rax, 0x23659(%rip)     # 0x2f300
addq %r13, %rax
movq %rax, 0x23657(%rip)     # 0x2f308
testq %r15, %r15
je 0xbda2
leaq 0xa813(%rip), %rsi      # 0x164d4
movq %rbx, %rdi
callq 0x2350
testq %rax, %rax
je 0xbdd0
movq %rax, %r12
movl $0x1, %esi
movq %r15, %rdi
movq %r13, %rdx
movq %rax, %rcx
callq 0x20c0
movq %rax, %r13
cmpl $0x0, 0x231fa(%rip)     # 0x2eeec
jle 0xbd11
leaq 0xbb06(%rip), %rdi      # 0x17801
leaq 0xb612(%rip), %rsi      # 0x17314
movl $0x33e, %edx            # imm = 0x33E
movl %r13d, %ecx
xorl %eax, %eax
callq 0xc960
cmpl %r14d, %r13d
jge 0xbe14
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xbafa(%rip), %rdi      # 0x17827
leaq 0xb5e0(%rip), %rsi      # 0x17314
movl $0x344, %edx            # imm = 0x344
jmp 0xbdef
cmpl $0x0, 0x231a7(%rip)     # 0x2eeec
jle 0xbe5b
leaq 0xb9a4(%rip), %rdi      # 0x176f6
leaq 0xb5bb(%rip), %rsi      # 0x17314
xorl %ebx, %ebx
movl $0x30e, %edx            # imm = 0x30E
xorl %eax, %eax
callq 0xc960
jmp 0xbe5d
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xb9ba(%rip), %rdi      # 0x17739
leaq 0xb58e(%rip), %rsi      # 0x17314
movl $0x317, %edx            # imm = 0x317
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc960
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xbe5d
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xb9cc(%rip), %rdi      # 0x17781
leaq 0xb558(%rip), %rsi      # 0x17314
movl $0x32b, %edx            # imm = 0x32B
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0xc960
jmp 0xbdfc
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xb9e5(%rip), %rdi      # 0x177c8
leaq 0xb52a(%rip), %rsi      # 0x17314
movl $0x335, %edx            # imm = 0x335
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc960
movq 0x234fd(%rip), %rdi     # 0x2f300
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0xbe5d
callq 0x2030
jmp 0xbe5d
movq %r12, %rdi
callq 0x20f0
movq %r15, %rdi
movl %r14d, %esi
callq 0xba5a
movq 0x234d2(%rip), %rdi     # 0x2f300
testq %rdi, %rdi
je 0xbe38
callq 0x2030
cmpl $0x0, 0x230ad(%rip)     # 0x2eeec
jle 0xbe5b
leaq 0xba1e(%rip), %rdi      # 0x17866
leaq 0xb4c5(%rip), %rsi      # 0x17314
xorl %ebx, %ebx
movl $0x354, %edx            # imm = 0x354
jmp 0xbd60
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq