#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 ECHONL;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, 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 *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int main(void) {
  struct termios ts, ots;
  char passbuf[1024];
  tcgetattr(STDIN_FILENO, &ts);
  ots = ts;
  ts.c_lflag &= ~ECHO;
  ts.c_lflag |= ECHONL;
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &ts);
  tcgetattr(STDIN_FILENO, &ts);
  if (ts.c_lflag & ECHO) {
    fprintf(stderr, "Failed to turn off echo\n");
    tcsetattr(STDIN_FILENO, TCSANOW, &ots);
    exit(1);
  }
  printf("enter password: ");
  fflush(stdout);
  fgets(passbuf, 1024, stdin);
  printf("read password: %s", passbuf);
  tcsetattr(STDIN_FILENO, TCSANOW, &ots);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    0x2dde(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1237 <main+0xc7>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    -0x410(%rbp),%rdi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x410(%rbp),%rsi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1080 <tcsetattr@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2e25(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <tcgetattr@plt>
mov    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x2e31(%rip),%r15
mov    (%r15),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2e0b(%rip),%rax
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    (%r14),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1080 <tcsetattr@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
call   1070 <tcgetattr@plt>
mov    (%r15),%eax
test   %eax,(%rsp)
jne    123e <main+0xce>
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    0xe13(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1080 <tcsetattr@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%r14),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1080 <tcsetattr@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Failed to turn off echo\0A\00"
@TCSANOW = global i32 0
@.str.1 = [17 x i8] c"enter password: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.2 = [18 x i8] c"read password: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %2)
%7 = bitcast %struct.termios* %3 to i8*
%8 = bitcast %struct.termios* %2 to i8*
%9 = load i32, i32* @ECHO
%10 = xor i32 %9, -1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%12 = load i32, i32* %11
%13 = and i32 %12, %10
store i32 %13, i32* %11
%14 = load i32, i32* @ECHONL
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%16 = load i32, i32* %15
%17 = or i32 %16, %14
store i32 %17, i32* %15
%18 = load i32, i32* @STDIN_FILENO
%19 = load i32, i32* @TCSAFLUSH
%20 = call i32 @tcsetattr(i32 %18, i32 %19, %struct.termios* %2)
%21 = load i32, i32* @STDIN_FILENO
%22 = call i32 @tcgetattr(i32 %21, %struct.termios* %2)
%23 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @ECHO
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %0
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @STDIN_FILENO
%32 = load i32, i32* @TCSANOW
%33 = call i32 @tcsetattr(i32 %31, i32 %32, %struct.termios* %3)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%40 = load i32, i32* @stdin
%41 = call i32 @fgets(i8* %39, i32 1024, i32 %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @STDIN_FILENO
%45 = load i32, i32* @TCSANOW
%46 = call i32 @tcsetattr(i32 %44, i32 %45, %struct.termios* %3)
%47 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Failed to turn off echo\0A\00"
@TCSANOW = global i32 0
@.str.1 = [17 x i8] c"enter password: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.2 = [18 x i8] c"read password: %s\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = alloca [1024 x i8]
%4 = bitcast %struct.termios* %1 to i8*
%5 = bitcast %struct.termios* %2 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %1)
%9 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %9
store i32 %11, i32* %10
%12 = load i32, i32* @ECHO
%13 = xor i32 %12, -1
%14 = and i32 %11, %13
%15 = load i32, i32* @ECHONL
%16 = or i32 %15, %14
store i32 %16, i32* %9
%17 = load i32, i32* @STDIN_FILENO
%18 = load i32, i32* @TCSAFLUSH
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %1)
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @tcgetattr(i32 %20, %struct.termios* %1)
%22 = load i32, i32* %9
%23 = load i32, i32* @ECHO
%24 = and i32 %23, %22
%25 = icmp eq i32 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %0
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @STDIN_FILENO
%30 = load i32, i32* @TCSANOW
%31 = call i32 @tcsetattr(i32 %29, i32 %30, %struct.termios* %2)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %0
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @stdout
%36 = call i32 @fflush(i32 %35)
%37 = load i32, i32* @stdin
%38 = call i32 @fgets(i8* %6, i32 1024, i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%40 = load i32, i32* @STDIN_FILENO
%41 = load i32, i32* @TCSANOW
%42 = call i32 @tcsetattr(i32 %40, i32 %41, %struct.termios* %2)
%43 = call i32 @exit(i32 0)
unreachable
}