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

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ ISIG;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
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() {
  struct termios initialrsettings, newrsettings;
  char password[8 + 1];
  tcgetattr(fileno(stdin), &initialrsettings);
  newrsettings = initialrsettings;
  newrsettings.c_lflag &= ~ECHO;
  newrsettings.c_lflag &= ~ICANON;
  newrsettings.c_lflag &= ~ISIG;
  newrsettings.c_cc[VTIME] = 0;
  newrsettings.c_cc[VMIN] = 1;
  printf("Enter password: ");
  if (tcsetattr(fileno(stdin), TCSANOW, &newrsettings) != 0) {
    fprintf(stderr, "Could not set attributes\n");
  } else {
    fgets(password, 8, stdin);
    tcsetattr(fileno(stdin), TCSANOW, &initialrsettings);
    fprintf(stdout, "\nYou entered %s\n", password);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2dca(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1080 <tcsetattr@plt>
cmp    $0x0,%rax
je     125c <main+0xec>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12b0 <main+0x140>
lea    -0x31(%rbp),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1040 <fgets@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    -0x31(%rbp),%rdx
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x2e68(%rip),%r15
mov    (%r15),%edi
call   1060 <fileno@plt>
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1070 <tcgetattr@plt>
movups 0x10(%rsp),%xmm0
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    0x2df7(%rip),%rcx
or     (%rcx),%eax
movaps %xmm0,(%rsp)
mov    0x2e1a(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    (%rsp),%rax
mov    0x2ddf(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dee(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
mov    (%r15),%edi
call   1060 <fileno@plt>
mov    0x2de1(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
test   %rax,%rax
jne    125c <main+0xec>
mov    (%r15),%edx
lea    0x27(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   1040 <fgets@plt>
mov    (%r15),%edi
call   1060 <fileno@plt>
mov    (%rbx),%esi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i32 }
@stdin = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@.str = [17 x i8] c"Enter password: \00"
@TCSANOW = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not set attributes\0A\00"
@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 [9 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 1
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @ICANON
%16 = xor i32 %15, -1
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* @ISIG
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%26 = load i32*, i32** %25
%27 = load i64, i64* @VTIME
%28 = getelementptr inbounds i32, i32* %26, i64 %27
store i32 0, i32* %28
%29 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%30 = load i32*, i32** %29
%31 = load i64, i64* @VMIN
%32 = getelementptr inbounds i32, i32* %30, i64 %31
store i32 1, i32* %32
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = call i32 @fileno(i32 %34)
%36 = load i32, i32* @TCSANOW
%37 = call i64 @tcsetattr(i32 %35, i32 %36, %struct.termios* %3)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %0
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %53
42: ; preds = %0
%43 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%44 = load i32, i32* @stdin
%45 = call i32 @fgets(i8* %43, i32 8, i32 %44)
%46 = load i32, i32* @stdin
%47 = call i32 @fileno(i32 %46)
%48 = load i32, i32* @TCSANOW
%49 = call i64 @tcsetattr(i32 %47, i32 %48, %struct.termios* %2)
%50 = load i32, i32* @stdout
%51 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %42, %39
%54 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32 }
@stdin = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@.str = [17 x i8] c"Enter password: \00"
@TCSANOW = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not set attributes\0A\00"
@stdout = global i32 0
@.str.2 = [17 x i8] c"\0AYou entered %s\0A\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = alloca [9 x i8]
%4 = bitcast %struct.termios* %1 to i8*
%5 = bitcast %struct.termios* %2 to i8*
%6 = getelementptr inbounds [9 x i8], [9 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 = load i32, i32* @ECHO
%11 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%12 = load i32, i32* %11
%13 = load i32, i32* @ICANON
%14 = or i32 %10, %13
%15 = load i32, i32* @ISIG
%16 = or i32 %14, %15
%17 = xor i32 %16, -1
%18 = and i32 %12, %17
store i32 %18, i32* %11
%19 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%20 = load i32*, i32** %19
%21 = load i64, i64* @VTIME
%22 = getelementptr inbounds i32, i32* %20, i64 %21
store i32 0, i32* %22
%23 = load i64, i64* @VMIN
%24 = getelementptr inbounds i32, i32* %20, i64 %23
store i32 1, i32* %24
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @stdin
%27 = call i32 @fileno(i32 %26)
%28 = load i32, i32* @TCSANOW
%29 = call i64 @tcsetattr(i32 %27, i32 %28, %struct.termios* %2)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %0
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %43
34: ; preds = %0
%35 = load i32, i32* @stdin
%36 = call i32 @fgets(i8* %6, i32 8, i32 %35)
%37 = load i32, i32* @stdin
%38 = call i32 @fileno(i32 %37)
%39 = load i32, i32* @TCSANOW
%40 = call i64 @tcsetattr(i32 %38, i32 %39, %struct.termios* %1)
%41 = load i32, i32* @stdout
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %43
43: ; preds = %34, %31
%44 = call i32 @exit(i32 0)
unreachable
}