#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*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int main(void) {
  char password[50];
  struct termios oldTer, newTer;
  tcgetattr(STDIN_FILENO, &oldTer);
  newTer = oldTer;
  newTer.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &newTer);
  char c;
  int i = 0;
  do {
    c = fgetc(stdin);
    password[i++] = c;
    if (c != '\n')
      fputc('*', stdout);
    else
      fputc('\n', stdout);
  } while (c != '\n' && i < 50);
  password[i - 1] = '\0';
  printf("Password: %s\n", password);
  tcsetattr(STDIN_FILENO, TCSANOW, &oldTer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    0x2e41(%rip),%rcx
or     (%rcx),%eax
mov    0x2e28(%rip),%rcx
or     (%rcx),%eax
mov    0x2e17(%rip),%rcx
or     (%rcx),%eax
mov    0x2df6(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1070 <tcsetattr@plt>
movl   $0x0,-0x58(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%cl
mov    -0x58(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x58(%rbp)
cltq
mov    %cl,-0x40(%rbp,%rax,1)
movsbl -0x51(%rbp),%eax
cmp    $0xa,%eax
je     1219 <main+0xc9>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
mov    $0x2a,%edi
call   1050 <fputc@plt>
jmp    122c <main+0xdc>
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
jmp    1231 <main+0xe1>
movsbl -0x51(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x59(%rbp)
je     124d <main+0xfd>
cmpl   $0x32,-0x58(%rbp)
setl   %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    11cf <main+0x7f>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rsi
lea    0xd90(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1070 <tcsetattr@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2e3e(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
call   1060 <tcgetattr@plt>
mov    0x2e5c(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e32(%rip),%rax
or     (%rax),%ecx
mov    0x2e21(%rip),%rax
or     (%rax),%ecx
mov    0x2e00(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    (%rsp),%ecx
mov    %ecx,0x8(%rsp)
mov    (%r14),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1070 <tcsetattr@plt>
xor    %ebx,%ebx
mov    0x2e1e(%rip),%r12
mov    0x2ddf(%rip),%r15
nopl   0x0(%rax)
mov    (%r12),%edi
call   1040 <fgetc@plt>
mov    %al,0x10(%rsp,%rbx,1)
cmp    $0xa,%al
je     11ff <main+0xaf>
add    $0x1,%rbx
mov    (%r15),%esi
mov    $0x2a,%edi
call   1050 <fputc@plt>
cmp    $0x32,%rbx
jne    11d0 <main+0x80>
mov    $0x31,%ebx
jmp    120c <main+0xbc>
mov    (%r15),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0xde8(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1030 <printf@plt>
mov    (%r14),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1070 <tcsetattr@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
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
@stdin = global i32 0
@stdout = global i32 0
@.str = [14 x i8] c"Password: %s\0A\00"
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = alloca i8
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %3)
%9 = bitcast %struct.termios* %4 to i8*
%10 = bitcast %struct.termios* %3 to i8*
%11 = load i32, i32* @ECHO
%12 = load i32, i32* @ECHOE
%13 = or i32 %11, %12
%14 = load i32, i32* @ECHOK
%15 = or i32 %13, %14
%16 = load i32, i32* @ECHONL
%17 = or i32 %15, %16
%18 = load i32, i32* @ICANON
%19 = or i32 %17, %18
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* @STDIN_FILENO
%25 = load i32, i32* @TCSAFLUSH
%26 = call i32 @tcsetattr(i32 %24, i32 %25, %struct.termios* %4)
store i32 0, i32* %6
br label %27
27: ; preds = %52, %0
%28 = load i32, i32* @stdin
%29 = call signext i8 @fgetc(i32 %28)
store i8 %29, i8* %5
%30 = load i8, i8* %5
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %33
store i8 %30, i8* %34
%35 = load i8, i8* %5
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 10
br i1 %37, label %38, label %41
38: ; preds = %27
%39 = load i32, i32* @stdout
%40 = call i32 @fputc(i8 signext 42, i32 %39)
br label %44
41: ; preds = %27
%42 = load i32, i32* @stdout
%43 = call i32 @fputc(i8 signext 10, i32 %42)
br label %44
44: ; preds = %41, %38
br label %45
45: ; preds = %44
%46 = load i8, i8* %5
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 10
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i32, i32* %6
%51 = icmp slt i32 %50, 50
br label %52
52: ; preds = %49, %45
%53 = phi i1 [ false, %45 ], [ %51, %49 ]
br i1 %53, label %27, label %54
54: ; preds = %52
%55 = load i32, i32* %6
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %57
store i8 0, i8* %58
%59 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%60 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %59)
%61 = load i32, i32* @STDIN_FILENO
%62 = load i32, i32* @TCSANOW
%63 = call i32 @tcsetattr(i32 %61, i32 %62, %struct.termios* %3)
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
@stdin = global i32 0
@stdout = global i32 0
@.str = [14 x i8] c"Password: %s\0A\00"
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.termios* %2 to i8*
%6 = bitcast %struct.termios* %3 to i8*
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %2)
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%11 = load i32, i32* %9
%12 = load i32, i32* @ECHO
%13 = load i32, i32* @ECHOE
%14 = or i32 %13, %12
%15 = load i32, i32* @ECHOK
%16 = or i32 %14, %15
%17 = load i32, i32* @ECHONL
%18 = or i32 %16, %17
%19 = load i32, i32* @ICANON
%20 = or i32 %18, %19
%21 = xor i32 %20, -1
%22 = and i32 %11, %21
store i32 %22, i32* %10
%23 = load i32, i32* @STDIN_FILENO
%24 = load i32, i32* @TCSAFLUSH
%25 = call i32 @tcsetattr(i32 %23, i32 %24, %struct.termios* %3)
br label %26
26: ; preds = %36, %0
%27 = phi i64 [ %37, %36 ], [ 0, %0 ]
%28 = load i32, i32* @stdin
%29 = call signext i8 @fgetc(i32 %28)
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %27
store i8 %29, i8* %30
%31 = icmp eq i8 %29, 10
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* @stdout
%34 = call i32 @fputc(i8 signext 10, i32 %33)
%35 = and i64 %27, 4294967295
br label %41
36: ; preds = %26
%37 = add nuw nsw i64 %27, 1
%38 = load i32, i32* @stdout
%39 = call i32 @fputc(i8 signext 42, i32 %38)
%40 = icmp eq i64 %37, 50
br i1 %40, label %41, label %26
41: ; preds = %36, %32
%42 = phi i64 [ %35, %32 ], [ 49, %36 ]
%43 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %42
store i8 0, i8* %43
%44 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %4)
%45 = load i32, i32* @STDIN_FILENO
%46 = load i32, i32* @TCSANOW
%47 = call i32 @tcsetattr(i32 %45, i32 %46, %struct.termios* %2)
ret i32 0
}