#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ tcflag_t;
struct timespec {
  int dummy;
};
struct termios {
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
char *prompt(char const *, struct timespec const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
char *prompt_echo_off(const char *msg, const struct timespec *timeout) {
  struct termios term;
  tcflag_t lflag;
  char *result;
  (void)tcgetattr(STDIN_FILENO, &term);
  lflag = term.c_lflag;
  term.c_lflag &= ~ECHO;
  (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
  result = prompt(msg, timeout);
  term.c_lflag = lflag;
  (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
  if (result != NULL)
    fputc('\n', stderr);
  return result;
}


x86 assembly (clang, -O0):
<prompt_echo_off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <prompt@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmpq   $0x0,-0x28(%rbp)
je     11e5 <prompt_echo_off+0xa5>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_echo_off>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e70(%rip),%r12
mov    (%r12),%edi
mov    %rsp,%r14
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    (%rsp),%ebp
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ebp,%eax
mov    %eax,(%rsp)
mov    (%r12),%edi
mov    0x2e63(%rip),%r13
mov    0x0(%r13),%esi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <prompt@plt>
mov    %rax,%rbx
mov    %ebp,(%rsp)
mov    (%r12),%edi
mov    0x0(%r13),%esi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rbx,%rbx
je     11ca <prompt_echo_off+0x8a>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
define i8* @prompt_echo_off(i8* %0, %struct.timespec* %1) {
%3 = alloca i8*
%4 = alloca %struct.timespec*
%5 = alloca %struct.termios
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store %struct.timespec* %1, %struct.timespec** %4
%8 = load i32, i32* @STDIN_FILENO
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %5)
%10 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %6
%12 = load i32, i32* @ECHO
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, %13
store i32 %16, i32* %14
%17 = load i32, i32* @STDIN_FILENO
%18 = load i32, i32* @TCSAFLUSH
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %5)
%20 = load i8*, i8** %3
%21 = load %struct.timespec*, %struct.timespec** %4
%22 = call i8* @prompt(i8* %20, %struct.timespec* %21)
store i8* %22, i8** %7
%23 = load i32, i32* %6
%24 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @STDIN_FILENO
%26 = load i32, i32* @TCSAFLUSH
%27 = call i32 @tcsetattr(i32 %25, i32 %26, %struct.termios* %5)
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %2
%31 = load i32, i32* @stderr
%32 = call i32 @fputc(i8 signext 10, i32 %31)
br label %33
33: ; preds = %30, %2
%34 = load i8*, i8** %7
ret i8* %34
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
define i8* @prompt_echo_off(i8* %0, %struct.timespec* %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %3)
%7 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @ECHO
%10 = xor i32 %9, -1
%11 = and i32 %8, %10
store i32 %11, i32* %7
%12 = load i32, i32* @STDIN_FILENO
%13 = load i32, i32* @TCSAFLUSH
%14 = call i32 @tcsetattr(i32 %12, i32 %13, %struct.termios* %3)
%15 = call i8* @prompt(i8* %0, %struct.timespec* %1)
store i32 %8, i32* %7
%16 = load i32, i32* @STDIN_FILENO
%17 = load i32, i32* @TCSAFLUSH
%18 = call i32 @tcsetattr(i32 %16, i32 %17, %struct.termios* %3)
%19 = icmp eq i8* %15, null
br i1 %19, label %23, label %20
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fputc(i8 signext 10, i32 %21)
br label %23
23: ; preds = %20, %2
ret i8* %15
}