// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/io/drivers/driver_ansi.cpp
// Function: smooth::IO::DriverANSI::DriverANSI(smooth::String const&, int)
S::IO::DriverANSI::DriverANSI(const String &file, Int mode) : Driver()
{
	stream	    = NIL;
	closeStream = False;

#if defined __WIN32__
	/* Add N mode option and Unicode prefix on Windows.
	 */
	String	 options  = "N";
	String	 fileName = Directory::MakeExtendedPath(file);
#else
	/* Use e mode option on other systems.
	 */
	String	 options  = "e";
	String	 fileName = file;

	/* Set output format to UTF-8 on non-Windows systems.
	 */
	String::OutputFormat	 outputFormat("UTF-8");
#endif

	switch (mode)
	{
		default:
			lastError = IO_ERROR_BADPARAM;

			return;
		case OS_APPEND:		   // open a file for appending data
			stream = fopen(fileName, String("r+b").Append(options));

			if (stream != NIL)
			{
				Int64	 size = GetSize();

				if (size >= 0) Seek(size);
			}

			break;
		case OS_REPLACE:	   // create or overwrite a file
			stream = fopen(fileName, String("w+b").Append(options));

			break;
		case IS_READ | IS_WRITE:   // open a file for reading data
			stream = fopen(fileName, String("r+b").Append(options));

			break;
		case IS_READ:		   // open a file in read only mode
			stream = fopen(fileName, String("rb").Append(options));

			break;
	}

	/* Check if stream was opened successfully.
	 */
	if (stream == NIL)
	{
		if (errno == EACCES) lastError = IO_ERROR_NOACCESS;
		else		     lastError = IO_ERROR_UNEXPECTED;

		return;
	}

	streamID = fileName;

	closeStream = True;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x58560
movq 0xcb324(%rip), %rax     # 0x16b610
addq $0x10, %rax
movq %rax, (%rbx)
movq $0x0, 0x38(%rbx)
movb $0x0, 0x40(%rbx)
leaq 0x73976(%rip), %rsi     # 0x113c7c
leaq 0x30(%rsp), %rdi
callq 0x579f0
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x71fb2(%rip), %rsi     # 0x1122d6
leaq 0x48(%rsp), %rdi
callq 0x55ed0
cmpl $0x6, %ebp
ja 0xa049b
movl %ebp, %eax
leaq 0x71678(%rip), %rcx     # 0x1119b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x18(%rsp), %rdi
callq 0x585e0
movq %rax, %r14
leaq 0x71690(%rip), %rsi     # 0x1119ed
movq %rsp, %rdi
callq 0x579f0
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x562f0
movq %rax, %rdi
callq 0x585e0
movq %r14, %rdi
movq %rax, %rsi
callq 0x586e0
movq %rax, 0x38(%rbx)
movq %rsp, %rdi
callq 0x59200
cmpq $0x0, 0x38(%rbx)
je 0xa0488
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
testq %rax, %rax
js 0xa046d
movq (%rbx), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x20(%rcx)
jmp 0xa046d
leaq 0x18(%rsp), %rdi
callq 0x585e0
movq %rax, %r14
leaq 0x52f8a(%rip), %rsi     # 0xf335d
movq %rsp, %rdi
callq 0x579f0
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x562f0
movq %rax, %rdi
callq 0x585e0
jmp 0xa0456
leaq 0x18(%rsp), %rdi
callq 0x585e0
movq %rax, %r14
leaq 0x715eb(%rip), %rsi     # 0x1119f1
movq %rsp, %rdi
callq 0x579f0
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x562f0
movq %rax, %rdi
callq 0x585e0
jmp 0xa0456
leaq 0x18(%rsp), %rdi
callq 0x585e0
movq %rax, %r14
leaq 0x715b4(%rip), %rsi     # 0x1119ed
movq %rsp, %rdi
callq 0x579f0
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x562f0
movq %rax, %rdi
callq 0x585e0
movq %r14, %rdi
movq %rax, %rsi
callq 0x586e0
movq %rax, 0x38(%rbx)
movq %rsp, %rdi
callq 0x59200
cmpq $0x0, 0x38(%rbx)
je 0xa0488
leaq 0x20(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0x555f0
movb $0x1, 0x40(%rbx)
jmp 0xa04ab
callq 0x58490
cmpl $0xd, (%rax)
jne 0xa04a4
movl $0x9, 0x18(%rbx)
jmp 0xa04ab
movl $0x2, 0x18(%rbx)
jmp 0xa04ab
movl $0x3, 0x18(%rbx)
leaq 0x48(%rsp), %rdi
callq 0x58680
leaq 0x18(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0xa04fe
jmp 0xa04fe
jmp 0xa04fe
jmp 0xa04fe
jmp 0xa04fe
jmp 0xa04e2
jmp 0xa04e2
jmp 0xa04e2
movq %rax, %r14
movq %rsp, %rdi
callq 0x59200
jmp 0xa0501
movq %rax, %r14
jmp 0xa050b
movq %rax, %r14
jmp 0xa0515
movq %rax, %r14
jmp 0xa051f
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x58680
leaq 0x18(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x56c30
movq %r14, %rdi
callq 0x57090
nop