#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;
};
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
char *encrypt_passwd(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
char *get_passwd() {
  char buff[20];
  char pass[20];
  char *encrypted;
  struct termios attr;
  static char passwd[20];
  printf("Password:  ");
  fflush(stdout);
  tcgetattr(STDIN_FILENO, &attr);
  attr.c_lflag &= ~ECHO;
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr);
  fgets(buff, sizeof(buff), stdin);
  sscanf(buff, "%s", pass);
  attr.c_lflag |= ECHO;
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr);
  printf("\n");
  encrypted = encrypt_passwd(pass);
  encrypted[14] = '\0';
  strcpy(passwd, encrypted);
  return (passwd);
}


x86 assembly (clang, -O0):
<get_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1090 <tcgetattr@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   10a0 <tcsetattr@plt>
lea    -0x20(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1050 <fgets@plt>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe05(%rip),%rsi
call   1080 <sscanf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
or     -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   10a0 <tcsetattr@plt>
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1060 <encrypt_passwd@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movb   $0x0,0xe(%rax)
mov    -0x48(%rbp),%rsi
lea    0x2e0e(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e02(%rip),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_passwd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe5b(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2e01(%rip),%r12
mov    (%r12),%edi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   10a0 <tcgetattr@plt>
mov    0x2e01(%rip),%r13
mov    0x0(%r13),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    (%r12),%edi
mov    0x2dfc(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r14,%rdx
call   10b0 <tcsetattr@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    0xdf3(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rdx
call   1090 <sscanf@plt>
mov    0x0(%r13),%eax
or     %eax,0x8(%rsp)
mov    (%r12),%edi
mov    0x0(%rbp),%esi
mov    %r14,%rdx
call   10b0 <tcsetattr@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1070 <encrypt_passwd@plt>
movb   $0x0,0xe(%rax)
lea    0x2e23(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@get_passwd.passwd = internal global [20 x i8] zeroinitializer
@.str = [12 x i8] c"Password: \00"
@stdout = global i32 0
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define i8* @get_passwd() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca i8*
%4 = alloca %struct.termios
%5 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = load i32, i32* @STDIN_FILENO
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %4)
%10 = load i32, i32* @ECHO
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @STDIN_FILENO
%16 = load i32, i32* @TCSAFLUSH
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %4)
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 20, i32 %19)
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @ECHO
%25 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%26 = load i32, i32* %25
%27 = or i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* @STDIN_FILENO
%29 = load i32, i32* @TCSAFLUSH
%30 = call i32 @tcsetattr(i32 %28, i32 %29, %struct.termios* %4)
%31 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%33 = call i8* @encrypt_passwd(i8* %32)
store i8* %33, i8** %3
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 14
store i8 0, i8* %35
%36 = load i8*, i8** %3
%37 = call i32 @strcpy(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @get_passwd.passwd, i64 0, i64 0), i8* %36)
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @get_passwd.passwd, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@get_passwd.passwd = internal global [20 x i8] zeroinitializer
@.str = [12 x i8] c"Password: \00"
@stdout = global i32 0
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i8* @get_passwd() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca %struct.termios
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.termios* %3 to i8*
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdout
%9 = tail call i32 @fflush(i32 %8)
%10 = load i32, i32* @STDIN_FILENO
%11 = call i32 @tcgetattr(i32 %10, %struct.termios* %3)
%12 = load i32, i32* @ECHO
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, %13
store i32 %16, i32* %14
%17 = load i32, i32* @STDIN_FILENO
%18 = load i32, i32* @TCSAFLUSH
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %3)
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %4, i32 20, i32 %20)
%22 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%23 = load i32, i32* @ECHO
%24 = load i32, i32* %14
%25 = or i32 %24, %23
store i32 %25, i32* %14
%26 = load i32, i32* @STDIN_FILENO
%27 = load i32, i32* @TCSAFLUSH
%28 = call i32 @tcsetattr(i32 %26, i32 %27, %struct.termios* %3)
%29 = call i32 @putchar(i32 10)
%30 = call i8* @encrypt_passwd(i8* %5)
%31 = getelementptr inbounds i8, i8* %30, i64 14
store i8 0, i8* %31
%32 = call i32 @strcpy(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @get_passwd.passwd, i64 0, i64 0), i8* %30)
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @get_passwd.passwd, i64 0, i64 0)
}