#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*/ 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;
  printf("Enter password: ");
  if (tcsetattr(fileno(stdin), TCSAFLUSH, &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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%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    0x2e2b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1080 <tcsetattr@plt>
cmp    $0x0,%rax
je     1204 <main+0x94>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1258 <main+0xe8>
lea    -0x19(%rbp),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1040 <fgets@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    -0x19(%rbp),%rdx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e62(%rip),%rbx
mov    (%rbx),%edi
call   1060 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <tcgetattr@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%edi
call   1060 <fileno@plt>
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
test   %rax,%rax
jne    121d <main+0xad>
mov    (%rbx),%edx
lea    0xf(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   1040 <fgets@plt>
mov    (%rbx),%edi
call   1060 <fileno@plt>
mov    0x2de8(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32 0
@ECHO = global i32 0
@.str = [17 x i8] c"Enter password: \00"
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not 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 [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 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 ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %35
24: ; preds = %0
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %25, i32 8, 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 [9 x i8], [9 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
%36 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32 0
@ECHO = global i32 0
@.str = [17 x i8] c"Enter password: \00"
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not 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 %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 = 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 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 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 ([26 x i8], [26 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 8, 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
%35 = call i32 @exit(i32 0)
unreachable
}