#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*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int main(void) {
  struct termios raw_setting, new_setting;
  char password[(6) + 1];
  tcgetattr(fileno(stdin), &raw_setting);
  new_setting = raw_setting;
  new_setting.c_lflag &= ~ECHO;
  printf("Enter password:\n");
  if (tcsetattr(fileno(stdin), TCSAFLUSH, &new_setting) != 0) {
    fprintf(stderr, "Couldn't set attributes\n");
  } else {
    fgets(password, (6), stdin);
    tcsetattr(fileno(stdin), TCSANOW, &raw_setting);
    fprintf(stdout, "\nYou entered:%s\n", password);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1080 <tcsetattr@plt>
cmp    $0x0,%rax
je     11f4 <main+0x94>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1248 <main+0xe8>
lea    -0x17(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1040 <fgets@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    -0x17(%rbp),%rdx
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e72(%rip),%rbx
mov    (%rbx),%edi
call   1060 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <tcgetattr@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%edi
call   1060 <fileno@plt>
mov    0x2e3d(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
test   %rax,%rax
je     11d7 <main+0x77>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    121f <main+0xbf>
mov    (%rbx),%edx
lea    0x11(%rsp),%r14
mov    %r14,%rdi
mov    $0x6,%esi
call   1040 <fgets@plt>
mov    (%rbx),%edi
call   1060 <fileno@plt>
mov    0x2ddf(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32 0
@ECHO = global i32 0
@.str = [17 x i8] c"Enter password:\0A\00"
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"Couldn't set attributes\0A\00"
@TCSANOW = global i32 0
@stdout = global i32 0
@.str.2 = [17 x i8] c"\0AYou entered:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = alloca [7 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @stdin
%6 = call i32 @fileno(i32 %5)
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %2)
%8 = bitcast %struct.termios* %3 to i8*
%9 = bitcast %struct.termios* %2 to i8*
%10 = load i32, i32* @ECHO
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stdin
%17 = call i32 @fileno(i32 %16)
%18 = load i32, i32* @TCSAFLUSH
%19 = call i64 @tcsetattr(i32 %17, i32 %18, %struct.termios* %3)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %35
24: ; preds = %0
%25 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %25, i32 6, i32 %26)
%28 = load i32, i32* @stdin
%29 = call i32 @fileno(i32 %28)
%30 = load i32, i32* @TCSANOW
%31 = call i64 @tcsetattr(i32 %29, i32 %30, %struct.termios* %2)
%32 = load i32, i32* @stdout
%33 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %24, %21
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"Couldn't set attributes\0A\00"
@TCSANOW = global i32 0
@stdout = global i32 0
@.str.2 = [17 x i8] c"\0AYou entered:%s\0A\00"
@str = [16 x i8] c"Enter password:\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = alloca [7 x i8]
%4 = bitcast %struct.termios* %1 to i8*
%5 = bitcast %struct.termios* %2 to i8*
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = tail call i32 @fileno(i32 %7)
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %1)
%10 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%11 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%12 = load i32, i32* %10
%13 = load i32, i32* @ECHO
%14 = xor i32 %13, -1
%15 = and i32 %12, %14
store i32 %15, i32* %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @stdin
%18 = call i32 @fileno(i32 %17)
%19 = load i32, i32* @TCSAFLUSH
%20 = call i64 @tcsetattr(i32 %18, i32 %19, %struct.termios* %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %0
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %34
25: ; preds = %0
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %6, i32 6, i32 %26)
%28 = load i32, i32* @stdin
%29 = call i32 @fileno(i32 %28)
%30 = load i32, i32* @TCSANOW
%31 = call i64 @tcsetattr(i32 %29, i32 %30, %struct.termios* %1)
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %34
34: ; preds = %25, %22
ret i32 0
}