// File: /workspace/github_c_makefile_star2_O3/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, 0x23378(%rip)     # 0x2eeec
jle 0xbb93
leaq 0xbb7e(%rip), %rdi      # 0x176fb
leaq 0xb7c0(%rip), %rsi      # 0x17344
movl $0x30a, %edx            # imm = 0x30A
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc84f
cmpl $0x0, 0x2375e(%rip)     # 0x2f2f8
je 0xbc65
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x2240
cmpl $-0x1, %eax
je 0xbc93
movq 0x30(%rsp), %r14
movslq %r14d, %r13
movq %r13, %rdi
callq 0x22a0
movq %rax, %r15
movq %rax, 0x23732(%rip)     # 0x2f300
addq %r13, %rax
movq %rax, 0x23730(%rip)     # 0x2f308
testq %r15, %r15
je 0xbcc9
leaq 0xa91c(%rip), %rsi      # 0x16504
movq %rbx, %rdi
callq 0x2340
testq %rax, %rax
je 0xbcf7
movq %rax, %r12
movl $0x1, %esi
movq %r15, %rdi
movq %r13, %rdx
movq %rax, %rcx
callq 0x20c0
movq %rax, %r13
cmpl $0x0, 0x232d3(%rip)     # 0x2eeec
jle 0xbc38
leaq 0xbc0f(%rip), %rdi      # 0x17831
leaq 0xb71b(%rip), %rsi      # 0x17344
movl $0x33e, %edx            # imm = 0x33E
movl %r13d, %ecx
xorl %eax, %eax
callq 0xc84f
cmpl %r14d, %r13d
jge 0xbd3b
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xbc03(%rip), %rdi      # 0x17857
leaq 0xb6e9(%rip), %rsi      # 0x17344
movl $0x344, %edx            # imm = 0x344
jmp 0xbd16
cmpl $0x0, 0x23280(%rip)     # 0x2eeec
jle 0xbd82
leaq 0xbaad(%rip), %rdi      # 0x17726
leaq 0xb6c4(%rip), %rsi      # 0x17344
xorl %ebx, %ebx
movl $0x30e, %edx            # imm = 0x30E
xorl %eax, %eax
callq 0xc84f
jmp 0xbd84
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xbac3(%rip), %rdi      # 0x17769
leaq 0xb697(%rip), %rsi      # 0x17344
movl $0x317, %edx            # imm = 0x317
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc84f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xbd84
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xbad5(%rip), %rdi      # 0x177b1
leaq 0xb661(%rip), %rsi      # 0x17344
movl $0x32b, %edx            # imm = 0x32B
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0xc84f
jmp 0xbd23
callq 0x2060
movl (%rax), %edi
callq 0x23b0
leaq 0xbaee(%rip), %rdi      # 0x177f8
leaq 0xb633(%rip), %rsi      # 0x17344
movl $0x335, %edx            # imm = 0x335
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc84f
movq 0x235d6(%rip), %rdi     # 0x2f300
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0xbd84
callq 0x2030
jmp 0xbd84
movq %r12, %rdi
callq 0x20f0
movq %r15, %rdi
movl %r14d, %esi
callq 0xb981
movq 0x235ab(%rip), %rdi     # 0x2f300
testq %rdi, %rdi
je 0xbd5f
callq 0x2030
cmpl $0x0, 0x23186(%rip)     # 0x2eeec
jle 0xbd82
leaq 0xbb27(%rip), %rdi      # 0x17896
leaq 0xb5ce(%rip), %rsi      # 0x17344
xorl %ebx, %ebx
movl $0x354, %edx            # imm = 0x354
jmp 0xbc87
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop