#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*/ 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 tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int main() {
  int ret;
  char password[256 + 1];
  struct termios initial_setting;
  struct termios new_setting;
  ret = tcgetattr(fileno(stdin), &initial_setting);
  if (ret != 0) {
    fprintf(stderr, "tcgetattr initial setting error\n");
    return -1;
  }
  new_setting = initial_setting;
  new_setting.c_lflag &= ~ECHO;
  ret = tcsetattr(fileno(stdin), TCSANOW, &new_setting);
  if (ret != 0) {
    fprintf(stderr, "tcsetattr new setting error\n");
    return -1;
  }
  printf("please enter your password: ");
  fgets(password, 256, stdin);
  printf("\npassword is %s", password);
  tcsetattr(fileno(stdin), TCSANOW, &initial_setting);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
lea    -0x118(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11bc <main+0x5c>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <main+0x13c>
mov    -0x118(%rbp),%eax
mov    %eax,-0x120(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x120(%rbp),%eax
mov    %eax,-0x120(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    -0x120(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1233 <main+0xd3>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <main+0x13c>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
lea    -0x118(%rbp),%rdx
call   1080 <tcsetattr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2e73(%rip),%r15
mov    (%r15),%edi
call   1060 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <tcgetattr@plt>
test   %eax,%eax
je     119d <main+0x3d>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
jmp    11e2 <main+0x82>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    (%r15),%edi
call   1060 <fileno@plt>
mov    0x2e22(%rip),%r12
mov    (%r12),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
test   %eax,%eax
je     11fd <main+0x9d>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe3a(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
lea    0xe32(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%edi
call   1060 <fileno@plt>
mov    (%r12),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1080 <tcsetattr@plt>
jmp    11ec <main+0x8c>

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"tcgetattr initial setting error\0A\00"
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str.1 = [29 x i8] c"tcsetattr new setting error\0A\00"
@.str.2 = [29 x i8] c"please enter your password: \00"
@.str.3 = [16 x i8] c"\0Apassword is %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [257 x i8]
%4 = alloca %struct.termios
%5 = alloca %struct.termios
store i32 0, i32* %1
%6 = load i32, i32* @stdin
%7 = call i32 @fileno(i32 %6)
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %4)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
14: ; preds = %0
%15 = bitcast %struct.termios* %5 to i8*
%16 = bitcast %struct.termios* %4 to i8*
%17 = load i32, i32* @ECHO
%18 = xor i32 %17, -1
%19 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%20 = load i32, i32* %19
%21 = and i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* @stdin
%23 = call i32 @fileno(i32 %22)
%24 = load i32, i32* @TCSANOW
%25 = call i32 @tcsetattr(i32 %23, i32 %24, %struct.termios* %5)
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %14
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %42
31: ; preds = %14
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%33 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %33, i32 256, i32 %34)
%36 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @stdin
%39 = call i32 @fileno(i32 %38)
%40 = load i32, i32* @TCSANOW
%41 = call i32 @tcsetattr(i32 %39, i32 %40, %struct.termios* %4)
store i32 0, i32* %1
br label %42
42: ; preds = %31, %28, %11
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"tcgetattr initial setting error\0A\00"
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str.1 = [29 x i8] c"tcsetattr new setting error\0A\00"
@.str.2 = [29 x i8] c"please enter your password: \00"
@.str.3 = [16 x i8] c"\0Apassword is %s\00"
define i32 @main() {
%1 = alloca [257 x i8]
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = getelementptr inbounds [257 x i8], [257 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
%8 = tail call i32 @fileno(i32 %7)
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %38
14: ; preds = %0
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%17 = load i32, i32* %15
%18 = load i32, i32* @ECHO
%19 = xor i32 %18, -1
%20 = and i32 %17, %19
store i32 %20, i32* %16
%21 = load i32, i32* @stdin
%22 = call i32 @fileno(i32 %21)
%23 = load i32, i32* @TCSANOW
%24 = call i32 @tcsetattr(i32 %22, i32 %23, %struct.termios* %3)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %14
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %38
29: ; preds = %14
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %4, i32 256, i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%34 = load i32, i32* @stdin
%35 = call i32 @fileno(i32 %34)
%36 = load i32, i32* @TCSANOW
%37 = call i32 @tcsetattr(i32 %35, i32 %36, %struct.termios* %2)
br label %38
38: ; preds = %29, %26, %11
%39 = phi i32 [ -1, %11 ], [ -1, %26 ], [ 0, %29 ]
ret i32 %39
}