// File: /workspace/github_c_makefile_star2_O0/orestesleal[P]base64/base64.c
// Function: encode_wr_file
void encode_wr_file(const char *src, const char *dst, unsigned char mode)
{
	struct finfo *fd;
	char *enc_buf;
	int ofd;
	size_t wr;
	int flags = O_CREAT | O_RDWR;
	int perms = S_IRUSR | O_TRUNC | S_IWUSR; 
	
	if ((fd = get_file(src)) == NULL) { /* load the input file 'src' */
		fprintf(stderr, "error: get_file() failed to load %s in main memory\n", src);
		exit(EXIT_FAILURE);
	}
	enc_buf = alloc(fd->size*2); /* buffer for the encoded string */
	switch (mode) {
		case BASE64:
			b64_enc((unsigned char *)fd->addr, enc_buf, fd->size);
			break;
		case BASE32:
			b32_enc((unsigned char *)fd->addr, (unsigned char *)enc_buf, fd->size);
			break;
		case BASE16:
			b16_enc(fd->addr, enc_buf, fd->size); 
			break;
		default:
			fprintf(stderr, "error: encoding %d mode not supported\n", mode);
			exit(EXIT_FAILURE);
	}
    if ((ofd = open(dst, flags, perms)) == -1) {
   		fprintf(stderr, "open(2) error, can't create or truncate %s\n", dst);
	    exit(EXIT_FAILURE);
	}
	if ((wr = write(ofd, enc_buf, strlen(enc_buf))) == -1) {
		fprintf(stderr, "write(2) error, can't write to %s\n", dst);
		exit(EXIT_FAILURE);
	}
	close(ofd);
	free(enc_buf);
	free(fd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl $0x42, -0x3c(%rbp)
movl $0x380, -0x40(%rbp)     # imm = 0x380
movq -0x8(%rbp), %rdi
callq 0x2b00
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x299c
movq 0x267b(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x79a(%rip), %rsi       # 0x3125
movb $0x0, %al
callq 0x1080
movl $0x1, %edi
callq 0x10c0
movq -0x20(%rbp), %rax
movl 0x8(%rax), %edi
addl %edi, %edi
callq 0x2ca0
movq %rax, -0x28(%rbp)
movzbl -0x11(%rbp), %eax
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x29d0
jmp 0x29bc
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x29ec
jmp 0x29c6
movl -0x44(%rbp), %eax
subl $0x3, %eax
je 0x2a08
jmp 0x2a24
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
callq 0x1d20
jmp 0x2a4a
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
callq 0x2260
jmp 0x2a4a
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
callq 0x2740
jmp 0x2a4a
movq 0x25cd(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
leaq 0x720(%rip), %rsi       # 0x3159
movb $0x0, %al
callq 0x1080
movl $0x1, %edi
callq 0x10c0
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x40(%rbp), %edx
movb $0x0, %al
callq 0x10b0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
jne 0x2a89
movq 0x258e(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x5b9(%rip), %rsi       # 0x3031
movb $0x0, %al
callq 0x1080
movl $0x1, %edi
callq 0x10c0
movl -0x2c(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1050
movl -0x54(%rbp), %edi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x1040
movq %rax, -0x38(%rbp)
cmpq $-0x1, %rax
jne 0x2adf
movq 0x2538(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x58f(%rip), %rsi       # 0x305d
movb $0x0, %al
callq 0x1080
movl $0x1, %edi
callq 0x10c0
movl -0x2c(%rbp), %edi
callq 0x1060
movq -0x28(%rbp), %rdi
callq 0x1030
movq -0x20(%rbp), %rdi
callq 0x1030
addq $0x60, %rsp
popq %rbp
retq
nop