// File: /workspace/github_c_makefile_star2_O0/charMstr[P]minishell/sources/termios_utils.c
// Function: termios_enable_raw_mode
int	termios_enable_raw_mode(t_control *control, struct termios *old)
{
	struct termios new;
	struct termios current;

	if (tcgetattr(STDIN_FILENO, &current) == -1)
	{
		control->quit = 1;
		control->exit_status = 1;
		ft_perror("tcgetattr can't get", NULL, strerror(errno));
		return (0);
	}
	new = *old;
	//This would turn off the fact that carriage return (ENTER, 13, '\r') are
	// translated into newline (10, '\n'). we dont want that.
	// old.c_iflag &= ~(ICRNL);

	//Similarly, It turns out that the terminal does a similar translation on
	// the output side. It translates each newline ("\n") we print into a
	// carriage return followed by a newline ("\r\n"). we dont need that.
	//old.c_oflag &= ~(OPOST);

	//disable the software flow control (not really used but ok to do it.)
	new.c_iflag &= ~(IXON);

	//disable the the fact that characters are echo back to the screen
	new.c_lflag &= ~(ECHO);

	//this flag is the one repsonsible for printing ^C or ^D when ISIG has not
	//been disabled yet.
	new.c_lflag &= ~(ECHOCTL);

	//read doesnt wait for a ENTER to be pressed anymore. read char by char
	new.c_lflag &= ~(ICANON);

	//disable the signals like SIGINT or SIGQUIT
	// note: as soon as we come out of this read_line process. we shoud restore
	//the SIGNALS so that ctrl_C  and ctrl_\ will be caught by our processes...
	new.c_lflag &= ~(ISIG);

	//needed to differenciate an escape sequence sent by a key like UP arrow
	//, thus staring by the esc value 27, from the "esc" key its self, 27 as
	// well. we differenciate them because of the timing.
	// if you type on your keyboard the keys "esc" + '[' + 'A' if becomes the
	// up arrow!!!
	new.c_cc[VTIME] = 1;
	new.c_cc[VMIN] = 0;
	//finally apply all the changes
	if (!ft_memcmp(&current, &new, sizeof(struct termios)))
		return (1);
	if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &new) == -1)
	{
		control->quit = 1;
		control->exit_status = 1;
		ft_perror("tcsetattr can't set", NULL, strerror(errno));
		return (0);
	}
	return (1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
xorl %edi, %edi
leaq -0x90(%rbp), %rsi
callq 0x21c0
cmpl $-0x1, %eax
jne 0x537a
movq -0x10(%rbp), %rax
movb (%rax), %cl
andb $-0x2, %cl
orb $0x1, %cl
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
callq 0x2040
movl (%rax), %edi
callq 0x2210
movq %rax, %rdx
leaq 0xbed7(%rip), %rdi      # 0x1123c
xorl %eax, %eax
movl %eax, %esi
callq 0x2620
movl $0x0, -0x4(%rbp)
jmp 0x5445
movq -0x18(%rbp), %rsi
leaq -0x54(%rbp), %rdi
movl $0x3c, %edx
callq 0x2160
movl -0x54(%rbp), %eax
andl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
andl $-0x9, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
andl $0xfffffdff, %eax       # imm = 0xFFFFFDFF
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
andl $-0x3, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
andl $-0x2, %eax
movl %eax, -0x48(%rbp)
movb $0x1, -0x3e(%rbp)
movb $0x0, -0x3d(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x54(%rbp), %rsi
movl $0x3c, %edx
callq 0xed20
cmpl $0x0, %eax
jne 0x53e8
movl $0x1, -0x4(%rbp)
jmp 0x5445
xorl %edi, %edi
movl $0x2, %esi
leaq -0x54(%rbp), %rdx
callq 0x21d0
cmpl $-0x1, %eax
jne 0x543e
movq -0x10(%rbp), %rax
movb (%rax), %cl
andb $-0x2, %cl
orb $0x1, %cl
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
callq 0x2040
movl (%rax), %edi
callq 0x2210
movq %rax, %rdx
leaq 0xbe24(%rip), %rdi      # 0x11250
xorl %eax, %eax
movl %eax, %esi
callq 0x2620
movl $0x0, -0x4(%rbp)
jmp 0x5445
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)