// File: /workspace/github_c_makefile_star2_O2/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, 0x227b9(%rip)     # 0x2deec
jle 0xb752
leaq 0xafbf(%rip), %rdi      # 0x166fb
leaq 0xac01(%rip), %rsi      # 0x16344
movl $0x30a, %edx            # imm = 0x30A
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc2a1
cmpl $0x0, 0x22b9f(%rip)     # 0x2e2f8
je 0xb822
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x2240
cmpl $-0x1, %eax
je 0xb850
movq 0x30(%rsp), %r14
movslq %r14d, %r13
movq %r13, %rdi
callq 0x22a0
movq %rax, %r15
movq %rax, 0x22b73(%rip)     # 0x2e300
addq %r13, %rax
movq %rax, 0x22b71(%rip)     # 0x2e308
testq %r15, %r15
je 0xb87e
leaq 0x9d5d(%rip), %rsi      # 0x15504
movq %rbx, %rdi
callq 0x2350
testq %rax, %rax
je 0xb8ac
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r15, %rdi
movq %r13, %rdx
movq %rax, %rcx
callq 0x20c0
movq %rax, %r13
cmpl $0x0, 0x22716(%rip)     # 0x2deec
jle 0xb7f5
leaq 0xb052(%rip), %rdi      # 0x16831
leaq 0xab5e(%rip), %rsi      # 0x16344
movl $0x33e, %edx            # imm = 0x33E
movl %r13d, %ecx
xorl %eax, %eax
callq 0xc2a1
cmpl %r14d, %r13d
jge 0xb8e9
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xb046(%rip), %rdi      # 0x16857
leaq 0xab2c(%rip), %rsi      # 0x16344
movl $0x344, %edx            # imm = 0x344
jmp 0xb8cb
cmpl $0x0, 0x226c3(%rip)     # 0x2deec
jle 0xb92b
leaq 0xaef0(%rip), %rdi      # 0x16726
leaq 0xab07(%rip), %rsi      # 0x16344
xorl %ebx, %ebx
movl $0x30e, %edx            # imm = 0x30E
xorl %eax, %eax
callq 0xc2a1
jmp 0xb92d
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xaf06(%rip), %rdi      # 0x16769
leaq 0xaada(%rip), %rsi      # 0x16344
movl $0x317, %edx            # imm = 0x317
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc2a1
jmp 0xb8e4
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xaf20(%rip), %rdi      # 0x167b1
leaq 0xaaac(%rip), %rsi      # 0x16344
movl $0x32b, %edx            # imm = 0x32B
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0xc2a1
jmp 0xb8d8
callq 0x2060
movl (%rax), %edi
callq 0x23c0
leaq 0xaf39(%rip), %rdi      # 0x167f8
leaq 0xaa7e(%rip), %rsi      # 0x16344
movl $0x335, %edx            # imm = 0x335
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc2a1
movq 0x22a21(%rip), %rdi     # 0x2e300
callq 0x2030
pushq $-0x1
popq %rbx
jmp 0xb92d
movq %r12, %rdi
callq 0x20f0
movq %r15, %rdi
movl %r14d, %esi
callq 0xb54b
movq 0x229fd(%rip), %rdi     # 0x2e300
callq 0x2030
cmpl $0x0, 0x225dd(%rip)     # 0x2deec
jle 0xb92b
leaq 0xaf7e(%rip), %rdi      # 0x16896
leaq 0xaa25(%rip), %rsi      # 0x16344
xorl %ebx, %ebx
movl $0x354, %edx            # imm = 0x354
jmp 0xb844
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq