// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
cmpl $0x0, 0x25106(%rip)     # 0x352dc
jle 0x101f6
movq -0x10(%rbp), %rcx
leaq 0xe60c(%rip), %rdi      # 0x1e7ef
leaq 0xe24e(%rip), %rsi      # 0x1e438
movl $0x30a, %edx            # imm = 0x30A
movb $0x0, %al
callq 0x117c0
cmpl $0x0, 0x254eb(%rip)     # 0x356e8
jne 0x1022e
cmpl $0x0, 0x250d6(%rip)     # 0x352dc
jle 0x10222
leaq 0xe60b(%rip), %rdi      # 0x1e81a
leaq 0xe222(%rip), %rsi      # 0x1e438
movl $0x30e, %edx            # imm = 0x30E
movb $0x0, %al
callq 0x117c0
movl $0x0, -0x4(%rbp)
jmp 0x104b2
movq -0x10(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2230
cmpl $-0x1, %eax
jne 0x1028a
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0xc0(%rbp), %rcx
movq %rax, %r8
leaq 0xe5f2(%rip), %rdi      # 0x1e85d
leaq 0xe1c6(%rip), %rsi      # 0x1e438
movl $0x317, %edx            # imm = 0x317
movb $0x0, %al
callq 0x117c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x104b2
movq -0x78(%rbp), %rax
movl %eax, -0xb4(%rbp)
movslq -0xb4(%rbp), %rdi
callq 0x2290
movq %rax, -0xb0(%rbp)
movq %rax, 0x25442(%rip)     # 0x356f0
movq 0x2543b(%rip), %rax     # 0x356f0
movslq -0xb4(%rbp), %rcx
addq %rcx, %rax
movq %rax, 0x25432(%rip)     # 0x356f8
cmpq $0x0, -0xb0(%rbp)
jne 0x1032d
movl -0xb4(%rbp), %eax
movl %eax, -0xc4(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movl -0xc4(%rbp), %ecx
movq %rax, %r8
leaq 0xe5ad(%rip), %rdi      # 0x1e8a5
leaq 0xe139(%rip), %rsi      # 0x1e438
movl $0x32b, %edx            # imm = 0x32B
movb $0x0, %al
callq 0x117c0
cmpq $0x0, 0x253dd(%rip)     # 0x356f0
je 0x10321
movq 0x253d4(%rip), %rdi     # 0x356f0
callq 0x2030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x104b2
movq -0x10(%rbp), %rdi
leaq 0xd35c(%rip), %rsi      # 0x1d694
callq 0x2330
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x103a4
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0xd0(%rbp), %rcx
movq %rax, %r8
leaq 0xe57d(%rip), %rdi      # 0x1e8ec
leaq 0xe0c2(%rip), %rsi      # 0x1e438
movl $0x335, %edx            # imm = 0x335
movb $0x0, %al
callq 0x117c0
cmpq $0x0, 0x25366(%rip)     # 0x356f0
je 0x10398
movq 0x2535d(%rip), %rdi     # 0x356f0
callq 0x2030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x104b2
movq -0xb0(%rbp), %rdi
movslq -0xb4(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x20b0
movl %eax, -0xb8(%rbp)
cmpl $0x0, 0x24f0f(%rip)     # 0x352dc
jle 0x103ef
movl -0xb8(%rbp), %ecx
leaq 0xe549(%rip), %rdi      # 0x1e925
leaq 0xe055(%rip), %rsi      # 0x1e438
movl $0x33e, %edx            # imm = 0x33E
movb $0x0, %al
callq 0x117c0
movl -0xb8(%rbp), %eax
cmpl -0xb4(%rbp), %eax
jge 0x10457
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
callq 0x2050
movl (%rax), %edi
callq 0x23a0
movq -0xd8(%rbp), %rcx
movq %rax, %r8
leaq 0xe526(%rip), %rdi      # 0x1e94b
leaq 0xe00c(%rip), %rsi      # 0x1e438
movl $0x344, %edx            # imm = 0x344
movb $0x0, %al
callq 0x117c0
cmpq $0x0, 0x252b0(%rip)     # 0x356f0
je 0x1044e
movq 0x252a7(%rip), %rdi     # 0x356f0
callq 0x2030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x104b2
movq -0x18(%rbp), %rdi
callq 0x20e0
movq -0xb0(%rbp), %rdi
movl -0xb4(%rbp), %esi
callq 0xffb0
cmpq $0x0, 0x25276(%rip)     # 0x356f0
je 0x10488
movq 0x2526d(%rip), %rdi     # 0x356f0
callq 0x2030
cmpl $0x0, 0x24e4d(%rip)     # 0x352dc
jle 0x104ab
leaq 0xe4f2(%rip), %rdi      # 0x1e98a
leaq 0xdf99(%rip), %rsi      # 0x1e438
movl $0x354, %edx            # imm = 0x354
movb $0x0, %al
callq 0x117c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nop