#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 c_lflag;
};

/* Variables and functions */
int ECHO;
int ECHOE;
int ECHOK;
int ECHONL;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
scalar_t__ read(int /*<<< orphan*/, char *, int);
int strlen(char *);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(void) {
  struct termios term, oldterm;
  int i;
  char pass[20 + 1], ch, echo = '*';
  write(STDOUT_FILENO, "\nPassword? ", 11);
  tcgetattr(STDIN_FILENO, &oldterm);
  term = oldterm;
  term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
  i = 0;
  while (i < 20 && read(STDIN_FILENO, &ch, 1) && ch != '\n') {
    pass[i++] = ch;
    write(STDOUT_FILENO, &echo, 1);
  }
  pass[i] = 0;
  tcsetattr(STDIN_FILENO, TCSANOW, &oldterm);
  write(STDOUT_FILENO, "\n\nPassword: ", 12);
  write(STDOUT_FILENO, pass, strlen(pass));
  write(STDOUT_FILENO, "\n", 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x2a,-0x32(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    0x2e23(%rip),%rcx
or     (%rcx),%eax
mov    0x2e0a(%rip),%rcx
or     (%rcx),%eax
mov    0x2df9(%rip),%rcx
or     (%rcx),%eax
mov    0x2de0(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1070 <tcsetattr@plt>
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x14,-0x14(%rbp)
mov    %al,-0x33(%rbp)
jge    1232 <main+0xe2>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    -0x31(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x33(%rbp)
je     1232 <main+0xe2>
movsbl -0x31(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x33(%rbp)
mov    -0x33(%rbp),%al
test   $0x1,%al
jne    1242 <main+0xf2>
jmp    1272 <main+0x122>
mov    -0x31(%rbp),%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0x30(%rbp,%rax,1)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    -0x32(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11ed <main+0x9d>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd2e(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
movb   $0x2a,0xe(%rsp)
mov    0x2e87(%rip),%r15
mov    (%r15),%edi
lea    0xe8d(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    0x2e24(%rip),%r12
mov    (%r12),%edi
lea    0x10(%rsp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2e37(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e0d(%rip),%rax
or     (%rax),%ecx
mov    0x2dfc(%rip),%rax
or     (%rax),%ecx
mov    0x2de3(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x10(%rsp),%ecx
mov    %ecx,0x18(%rsp)
mov    (%r12),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
call   1070 <tcsetattr@plt>
xor    %ebx,%ebx
lea    0xf(%rsp),%r14
lea    0xe(%rsp),%r13
nopl   0x0(%rax)
mov    (%r12),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
je     1232 <main+0xe2>
movzbl 0xf(%rsp),%eax
cmp    $0xa,%al
je     1232 <main+0xe2>
mov    %al,0x20(%rsp,%rbx,1)
add    $0x1,%rbx
mov    (%r15),%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x14,%rbx
jne    11f0 <main+0xa0>
mov    $0x14,%ebx
mov    %ebx,%eax
movb   $0x0,0x20(%rsp,%rax,1)
mov    (%r12),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1070 <tcsetattr@plt>
mov    (%r15),%edi
lea    0xdb2(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    (%r15),%ebx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r15),%edi
lea    0xd8f(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDOUT_FILENO = global i32 0
@.str = [12 x i8] c"\0APassword? \00"
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@TCSAFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [13 x i8] c"\0A\0APassword: \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = alloca i32
%5 = alloca [21 x i8]
%6 = alloca i8
%7 = alloca i8
store i32 0, i32* %1
store i8 42, i8* %7
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @write(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%10 = load i32, i32* @STDIN_FILENO
%11 = call i32 @tcgetattr(i32 %10, %struct.termios* %3)
%12 = bitcast %struct.termios* %2 to i8*
%13 = bitcast %struct.termios* %3 to i8*
%14 = load i32, i32* @ECHO
%15 = load i32, i32* @ECHOE
%16 = or i32 %14, %15
%17 = load i32, i32* @ECHOK
%18 = or i32 %16, %17
%19 = load i32, i32* @ECHONL
%20 = or i32 %18, %19
%21 = load i32, i32* @ICANON
%22 = or i32 %20, %21
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @STDIN_FILENO
%28 = load i32, i32* @TCSAFLUSH
%29 = call i32 @tcsetattr(i32 %27, i32 %28, %struct.termios* %2)
store i32 0, i32* %4
br label %30
30: ; preds = %43, %0
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 20
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i32, i32* @STDIN_FILENO
%35 = call i64 @read(i32 %34, i8* %6, i32 1)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8, i8* %6
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br label %41
41: ; preds = %37, %33, %30
%42 = phi i1 [ false, %33 ], [ false, %30 ], [ %40, %37 ]
br i1 %42, label %43, label %51
43: ; preds = %41
%44 = load i8, i8* %6
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 %47
store i8 %44, i8* %48
%49 = load i32, i32* @STDOUT_FILENO
%50 = call i32 @write(i32 %49, i8* %7, i32 1)
br label %30
51: ; preds = %41
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 %53
store i8 0, i8* %54
%55 = load i32, i32* @STDIN_FILENO
%56 = load i32, i32* @TCSANOW
%57 = call i32 @tcsetattr(i32 %55, i32 %56, %struct.termios* %3)
%58 = load i32, i32* @STDOUT_FILENO
%59 = call i32 @write(i32 %58, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%60 = load i32, i32* @STDOUT_FILENO
%61 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%62 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = call i32 @write(i32 %60, i8* %61, i32 %63)
%65 = load i32, i32* @STDOUT_FILENO
%66 = call i32 @write(i32 %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDOUT_FILENO = global i32 0
@.str = [12 x i8] c"\0APassword? \00"
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@TCSAFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [13 x i8] c"\0A\0APassword: \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = alloca [21 x i8]
%4 = alloca i8
%5 = alloca i8
%6 = bitcast %struct.termios* %1 to i8*
%7 = bitcast %struct.termios* %2 to i8*
%8 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
store i8 42, i8* %5
%9 = load i32, i32* @STDOUT_FILENO
%10 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%11 = load i32, i32* @STDIN_FILENO
%12 = call i32 @tcgetattr(i32 %11, %struct.termios* %2)
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%14 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%15 = load i32, i32* %13
%16 = load i32, i32* @ECHO
%17 = load i32, i32* @ECHOE
%18 = or i32 %17, %16
%19 = load i32, i32* @ECHOK
%20 = or i32 %18, %19
%21 = load i32, i32* @ECHONL
%22 = or i32 %20, %21
%23 = load i32, i32* @ICANON
%24 = or i32 %22, %23
%25 = xor i32 %24, -1
%26 = and i32 %15, %25
store i32 %26, i32* %14
%27 = load i32, i32* @STDIN_FILENO
%28 = load i32, i32* @TCSAFLUSH
%29 = call i32 @tcsetattr(i32 %27, i32 %28, %struct.termios* %1)
br label %30
30: ; preds = %0, %38
%31 = phi i64 [ 0, %0 ], [ %39, %38 ]
%32 = load i32, i32* @STDIN_FILENO
%33 = call i64 @read(i32 %32, i8* %4, i32 1)
%34 = icmp ne i64 %33, 0
%35 = load i8, i8* %4
%36 = icmp ne i8 %35, 10
%37 = select i1 %34, i1 %36, i1 false
br i1 %37, label %38, label %44
38: ; preds = %30
%39 = add nuw nsw i64 %31, 1
%40 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 %31
store i8 %35, i8* %40
%41 = load i32, i32* @STDOUT_FILENO
%42 = call i32 @write(i32 %41, i8* %5, i32 1)
%43 = icmp eq i64 %39, 20
br i1 %43, label %44, label %30
44: ; preds = %38, %30
%45 = phi i64 [ 20, %38 ], [ %31, %30 ]
%46 = and i64 %45, 4294967295
%47 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 %46
store i8 0, i8* %47
%48 = load i32, i32* @STDIN_FILENO
%49 = load i32, i32* @TCSANOW
%50 = call i32 @tcsetattr(i32 %48, i32 %49, %struct.termios* %2)
%51 = load i32, i32* @STDOUT_FILENO
%52 = call i32 @write(i32 %51, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%53 = load i32, i32* @STDOUT_FILENO
%54 = call i32 @strlen(i8* %8)
%55 = call i32 @write(i32 %53, i8* %8, i32 %54)
%56 = load i32, i32* @STDOUT_FILENO
%57 = call i32 @write(i32 %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret i32 0
}