#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 */
struct termios {
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ TCSADRAIN;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ pamtester_compat_put_message(char const *,
                                                int /*<<< orphan*/);
char *pamtester_compat_readline(int /*<<< orphan*/);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
char *pamtester_compat_prompt(const char *msg, int echo) {
  char *retval;
  pamtester_compat_put_message(msg, stdout);
  setvbuf(stdin, NULL, _IONBF, 0);
  if (echo) {
    retval = pamtester_compat_readline(stdin);
  } else {
    struct termios tstat;
    tcgetattr(fileno(stdin), &tstat);
    tstat.c_lflag &= ~ECHO;
    tcsetattr(fileno(stdin), TCSAFLUSH, &tstat);
    retval = pamtester_compat_readline(stdin);
    tstat.c_lflag |= ECHO;
    tcsetattr(fileno(stdin), TCSADRAIN, &tstat);
  }
  pamtester_compat_put_message("\n", stdout);
  return retval;
}


x86 assembly (clang, -O0):
<pamtester_compat_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1040 <pamtester_compat_put_message@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
cmpl   $0x0,-0xc(%rbp)
je     11bf <pamtester_compat_prompt+0x5f>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1030 <pamtester_compat_readline@plt>
mov    %rax,-0x18(%rbp)
jmp    124f <pamtester_compat_prompt+0xef>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1030 <pamtester_compat_readline@plt>
mov    %rax,-0x18(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
lea    0xda1(%rip),%rdi
call   1040 <pamtester_compat_put_message@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pamtester_compat_prompt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    0x2e42(%rip),%r15
mov    (%r15),%esi
call   1040 <pamtester_compat_put_message@plt>
mov    0x2e5b(%rip),%r12
mov    (%r12),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
test   %ebx,%ebx
je     11ad <pamtester_compat_prompt+0x4d>
mov    (%r12),%edi
call   1030 <pamtester_compat_readline@plt>
mov    %rax,%rbx
jmp    1222 <pamtester_compat_prompt+0xc2>
mov    (%r12),%edi
call   1050 <fileno@plt>
lea    0x8(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <tcgetattr@plt>
mov    0x2e0c(%rip),%r13
mov    0x0(%r13),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    (%r12),%edi
call   1050 <fileno@plt>
mov    0x2e02(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
mov    (%r12),%edi
call   1030 <pamtester_compat_readline@plt>
mov    %rax,%rbx
mov    0x0(%r13),%eax
or     %eax,0x8(%rsp)
mov    (%r12),%edi
call   1050 <fileno@plt>
mov    0x2daa(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
mov    (%r15),%esi
lea    0xdd4(%rip),%rdi
call   1040 <pamtester_compat_put_message@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdout = global i32 0
@stdin = global i32 0
@_IONBF = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@TCSADRAIN = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @pamtester_compat_prompt(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.termios
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @stdout
%9 = call i32 @pamtester_compat_put_message(i8* %7, i32 %8)
%10 = load i32, i32* @stdin
%11 = load i32, i32* @_IONBF
%12 = call i32 @setvbuf(i32 %10, i32* null, i32 %11, i32 0)
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stdin
%17 = call i8* @pamtester_compat_readline(i32 %16)
store i8* %17, i8** %5
br label %41
18: ; preds = %2
%19 = load i32, i32* @stdin
%20 = call i32 @fileno(i32 %19)
%21 = call i32 @tcgetattr(i32 %20, %struct.termios* %6)
%22 = load i32, i32* @ECHO
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @stdin
%28 = call i32 @fileno(i32 %27)
%29 = load i32, i32* @TCSAFLUSH
%30 = call i32 @tcsetattr(i32 %28, i32 %29, %struct.termios* %6)
%31 = load i32, i32* @stdin
%32 = call i8* @pamtester_compat_readline(i32 %31)
store i8* %32, i8** %5
%33 = load i32, i32* @ECHO
%34 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%35 = load i32, i32* %34
%36 = or i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* @stdin
%38 = call i32 @fileno(i32 %37)
%39 = load i32, i32* @TCSADRAIN
%40 = call i32 @tcsetattr(i32 %38, i32 %39, %struct.termios* %6)
br label %41
41: ; preds = %18, %15
%42 = load i32, i32* @stdout
%43 = call i32 @pamtester_compat_put_message(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i8*, i8** %5
ret i8* %44
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdout = global i32 0
@stdin = global i32 0
@_IONBF = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@TCSADRAIN = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @pamtester_compat_prompt(i8* %0, i32 %1) {
%3 = alloca %struct.termios
%4 = load i32, i32* @stdout
%5 = tail call i32 @pamtester_compat_put_message(i8* %0, i32 %4)
%6 = load i32, i32* @stdin
%7 = load i32, i32* @_IONBF
%8 = tail call i32 @setvbuf(i32 %6, i32* null, i32 %7, i32 0)
%9 = icmp eq i32 %1, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @stdin
%12 = tail call i8* @pamtester_compat_readline(i32 %11)
br label %36
13: ; preds = %2
%14 = bitcast %struct.termios* %3 to i8*
%15 = load i32, i32* @stdin
%16 = tail call i32 @fileno(i32 %15)
%17 = call i32 @tcgetattr(i32 %16, %struct.termios* %3)
%18 = load i32, i32* @ECHO
%19 = xor i32 %18, -1
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @stdin
%24 = call i32 @fileno(i32 %23)
%25 = load i32, i32* @TCSAFLUSH
%26 = call i32 @tcsetattr(i32 %24, i32 %25, %struct.termios* %3)
%27 = load i32, i32* @stdin
%28 = call i8* @pamtester_compat_readline(i32 %27)
%29 = load i32, i32* @ECHO
%30 = load i32, i32* %20
%31 = or i32 %30, %29
store i32 %31, i32* %20
%32 = load i32, i32* @stdin
%33 = call i32 @fileno(i32 %32)
%34 = load i32, i32* @TCSADRAIN
%35 = call i32 @tcsetattr(i32 %33, i32 %34, %struct.termios* %3)
br label %36
36: ; preds = %13, %10
%37 = phi i8* [ %12, %10 ], [ %28, %13 ]
%38 = load i32, i32* @stdout
%39 = call i32 @pamtester_compat_put_message(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %38)
ret i8* %37
}