#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;
char EOF;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
char getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int main(int argc, char const *argv[], char const *envp[]) {
  char pass[50] = "";
  struct termios old, new;
  tcgetattr(STDIN_FILENO, &old);
  new = old;
  new.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &new);
  printf("Pass ? ");
  for (char c = getc(stdin); c != EOF && c != '\n'; c = getc(stdin)) {
    strncat(pass, &c, 1);
    printf("*");
  }
  printf("\n%s\n", pass);
  tcsetattr(STDIN_FILENO, TCSANOW, &old);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1040 <memset@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    -0x58(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    0x2e16(%rip),%rcx
or     (%rcx),%eax
mov    0x2df5(%rip),%rcx
or     (%rcx),%eax
mov    0x2de4(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x60(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdx
call   1070 <tcsetattr@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1080 <getc@plt>
mov    %al,-0x61(%rbp)
movsbl -0x61(%rbp),%ecx
mov    0x2da3(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x62(%rbp)
je     123a <main+0xda>
movsbl -0x61(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x62(%rbp)
mov    -0x62(%rbp),%al
test   $0x1,%al
jne    124a <main+0xea>
jmp    1280 <main+0x120>
lea    -0x50(%rbp),%rdi
lea    -0x61(%rbp),%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   1080 <getc@plt>
mov    %al,-0x61(%rbp)
jmp    1212 <main+0xb2>
lea    -0x50(%rbp),%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1070 <tcsetattr@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movw   $0x0,0x50(%rsp)
mov    0x2e13(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2e2f(%rip),%rax
mov    0x2e20(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2dfd(%rip),%rax
or     (%rax),%ecx
mov    0x2dec(%rip),%rax
or     (%rax),%ecx
mov    0x2dd3(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x10(%rsp),%ecx
mov    %ecx,0x18(%rsp)
mov    (%r15),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
call   1070 <tcsetattr@plt>
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2de4(%rip),%r12
mov    (%r12),%edi
call   1080 <getc@plt>
mov    %al,0xf(%rsp)
cmp    $0xa,%al
je     1261 <main+0x101>
mov    0x2dac(%rip),%r13
cmp    0x0(%r13),%al
je     1261 <main+0x101>
lea    0x20(%rsp),%r14
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    (%r12),%edi
call   1080 <getc@plt>
mov    %al,0xf(%rsp)
cmp    $0xa,%al
je     1261 <main+0x101>
cmp    0x0(%r13),%al
jne    1230 <main+0xd0>
lea    0xda0(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%edi
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1070 <tcsetattr@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.termios = type { i32 }
@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
@.str = [8 x i8] c"Pass ? \00"
@stdin = global i32 0
@EOF = global i8 0
@.str.2 = [5 x i8] c"\0A%s\0A\00"
@TCSANOW = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [50 x i8]
%5 = alloca %struct.termios
%6 = alloca %struct.termios
%7 = alloca i8
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.termios* %5 to i8*
%10 = bitcast %struct.termios* %6 to i8*
%11 = load i32, i32* @STDIN_FILENO
%12 = call i32 @tcgetattr(i32 %11, %struct.termios* %5)
%13 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%14 = getelementptr inbounds %struct.termios, %struct.termios* %6, 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* %6)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @stdin
%32 = call signext i8 @getc(i32 %31)
store i8 %32, i8* %7
%33 = load i8, i8* @EOF
%34 = icmp ne i8 %32, %33
%35 = icmp ne i8 %32, 10
%36 = and i1 %35, %34
br i1 %36, label %42, label %37
37: ; preds = %42, %3
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%39 = load i32, i32* @STDIN_FILENO
%40 = load i32, i32* @TCSANOW
%41 = call i32 @tcsetattr(i32 %39, i32 %40, %struct.termios* %5)
ret i32 0
42: ; preds = %3, %42
%43 = call i32 @strncat(i8* %8, i8* %7, i32 1)
%44 = call i32 @putchar(i32 42)
%45 = load i32, i32* @stdin
%46 = call signext i8 @getc(i32 %45)
store i8 %46, i8* %7
%47 = load i8, i8* @EOF
%48 = icmp ne i8 %46, %47
%49 = icmp ne i8 %46, 10
%50 = and i1 %49, %48
br i1 %50, label %42, label %37
}