#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;
  int c_iflag;
};
typedef int ssize_t;

/* Variables and functions */
int ECHO;
int ICANON;
int ICRNL;
int IGNCR;
int INLCR;
int ISIG;
int O_CLOEXEC;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int, char *, ...);
int open(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ tcdrain(int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
char *getpass(const char *prompt) {
  int fd;
  struct termios s, t;
  ssize_t l;
  static char password[128];
  if ((fd = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC)) < 0)
    return 0;
  tcgetattr(fd, &t);
  s = t;
  t.c_lflag &= ~(ECHO | ISIG);
  t.c_lflag |= ICANON;
  t.c_iflag &= ~(INLCR | IGNCR);
  t.c_iflag |= ICRNL;
  tcsetattr(fd, TCSAFLUSH, &t);
  tcdrain(fd);
  dprintf(fd, "%s", prompt);
  l = read(fd, password, sizeof password);
  if (l >= 0) {
    if (l > 0 && password[l - 1] == '\n' || l == sizeof password)
      l--;
    password[l] = 0;
  }
  tcsetattr(fd, TCSAFLUSH, &s);
  dprintf(fd, "\n");
  close(fd);
  return l < 0 ? 0 : password;
}


x86 assembly (clang, -O0):
<getpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    0x2e1c(%rip),%rax
or     (%rax),%esi
mov    0x2dfb(%rip),%rax
or     (%rax),%esi
lea    0xe62(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11bc <getpass+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    130b <getpass+0x19b>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    0x2dd8(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    0x2dbe(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
call   1030 <tcdrain@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1050 <dprintf@plt>
mov    -0x14(%rbp),%edi
lea    0x2e10(%rip),%rsi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     12c6 <getpass+0x156>
cmpl   $0x0,-0x2c(%rbp)
jle    129e <getpass+0x12e>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ddf(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     12ae <getpass+0x13e>
movslq -0x2c(%rbp),%rax
cmp    $0x80,%rax
jne    12b7 <getpass+0x147>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rcx
lea    0x2dae(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%edi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1050 <dprintf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x2c(%rbp),%edx
lea    0x2d72(%rip),%rax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpass>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e65(%rip),%rax
mov    0x2e1e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%r14
mov    0x2df8(%rip),%rax
or     (%rax),%esi
lea    0xe5f(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     127a <getpass+0x10a>
mov    %eax,%ebx
mov    %rsp,%r15
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <tcgetattr@plt>
mov    (%rsp),%rax
mov    0x2df8(%rip),%rcx
mov    0x2de9(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
not    %edx
and    %eax,%edx
mov    0x2dc2(%rip),%rcx
or     (%rcx),%edx
mov    0x2df1(%rip),%rcx
mov    0x2dda(%rip),%rsi
mov    (%rsi),%esi
or     (%rcx),%esi
mov    %rax,0x8(%rsp)
not    %esi
shr    $0x20,%rax
and    %esi,%eax
mov    0x2dda(%rip),%rcx
or     (%rcx),%eax
mov    %edx,(%rsp)
mov    %eax,0x4(%rsp)
mov    0x2dba(%rip),%r12
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1080 <tcsetattr@plt>
mov    %ebx,%edi
call   1030 <tcdrain@plt>
lea    0xdd7(%rip),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <dprintf@plt>
lea    0x2e29(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
test   %eax,%eax
js     127f <getpass+0x10f>
je     1271 <getpass+0x101>
lea    -0x1(%rax),%ecx
cmpb   $0xa,(%rcx,%r14,1)
mov    %eax,%ebp
cmove  %ecx,%ebp
cmp    $0x80,%eax
cmove  %ecx,%ebp
mov    %ebp,%eax
movb   $0x0,(%rax,%r14,1)
jmp    1281 <getpass+0x111>
xor    %r14d,%r14d
jmp    12b1 <getpass+0x141>
mov    %eax,%ebp
mov    (%r12),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1080 <tcsetattr@plt>
lea    0xd74(%rip),%rsi
xor    %r15d,%r15d
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <dprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
test   %ebp,%ebp
cmovs  %r15,%r14
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@getpass.password = internal global [128 x i8] zeroinitializer
@.str = [9 x i8] c"/dev/tty\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_CLOEXEC = global i32 0
@ECHO = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@TCSAFLUSH = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define i8* @getpass(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.termios
%6 = alloca %struct.termios
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %8, %9
%11 = load i32, i32* @O_CLOEXEC
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i8* null, i8** %2
br label %89
16: ; preds = %1
%17 = load i32, i32* %4
%18 = call i32 @tcgetattr(i32 %17, %struct.termios* %6)
%19 = bitcast %struct.termios* %5 to i8*
%20 = bitcast %struct.termios* %6 to i8*
%21 = load i32, i32* @ECHO
%22 = load i32, i32* @ISIG
%23 = or i32 %21, %22
%24 = xor i32 %23, -1
%25 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = and i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* @ICANON
%29 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @INLCR
%33 = load i32, i32* @IGNCR
%34 = or i32 %32, %33
%35 = xor i32 %34, -1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%37 = load i32, i32* %36
%38 = and i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @ICRNL
%40 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%41 = load i32, i32* %40
%42 = or i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* %4
%44 = load i32, i32* @TCSAFLUSH
%45 = call i32 @tcsetattr(i32 %43, i32 %44, %struct.termios* %6)
%46 = load i32, i32* %4
%47 = call i32 @tcdrain(i32 %46)
%48 = load i32, i32* %4
%49 = load i8*, i8** %3
%50 = call i32 (i32, i8*, ...) @dprintf(i32 %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = load i32, i32* %4
%52 = call i32 @read(i32 %51, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getpass.password, i64 0, i64 0), i32 128)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp sge i32 %53, 0
br i1 %54, label %55, label %77
55: ; preds = %16
%56 = load i32, i32* %7
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %55
%59 = load i32, i32* %7
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [128 x i8], [128 x i8]* @getpass.password, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 10
br i1 %65, label %70, label %66
66: ; preds = %58, %55
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = icmp eq i64 %68, 128
br i1 %69, label %70, label %73
70: ; preds = %66, %58
%71 = load i32, i32* %7
%72 = add nsw i32 %71, -1
store i32 %72, i32* %7
br label %73
73: ; preds = %70, %66
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [128 x i8], [128 x i8]* @getpass.password, i64 0, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %73, %16
%78 = load i32, i32* %4
%79 = load i32, i32* @TCSAFLUSH
%80 = call i32 @tcsetattr(i32 %78, i32 %79, %struct.termios* %5)
%81 = load i32, i32* %4
%82 = call i32 (i32, i8*, ...) @dprintf(i32 %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%83 = load i32, i32* %4
%84 = call i32 @close(i32 %83)
%85 = load i32, i32* %7
%86 = icmp slt i32 %85, 0
%87 = zext i1 %86 to i64
%88 = select i1 %86, i8* null, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getpass.password, i64 0, i64 0)
store i8* %88, i8** %2
br label %89
89: ; preds = %77, %15
%90 = load i8*, i8** %2
ret i8* %90
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@getpass.password = internal global [128 x i8] zeroinitializer
@.str = [9 x i8] c"/dev/tty\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_CLOEXEC = global i32 0
@ECHO = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@TCSAFLUSH = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define i8* @getpass(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.termios*
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.termios*
%6 = bitcast i64* %2 to i8*
%7 = bitcast i64* %4 to i8*
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %9, %8
%11 = load i32, i32* @O_CLOEXEC
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %66, label %15
15: ; preds = %1
%16 = call i32 @tcgetattr(i32 %13, %struct.termios* %5)
%17 = load i64, i64* %4
store i64 %17, i64* %2
%18 = load i32, i32* @ECHO
%19 = load i32, i32* @ISIG
%20 = or i32 %19, %18
%21 = xor i32 %20, -1
%22 = bitcast i64* %4 to i32*
%23 = trunc i64 %17 to i32
%24 = and i32 %23, %21
%25 = load i32, i32* @ICANON
%26 = or i32 %25, %24
store i32 %26, i32* %22
%27 = load i32, i32* @INLCR
%28 = load i32, i32* @IGNCR
%29 = or i32 %28, %27
%30 = xor i32 %29, -1
%31 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 1
%32 = lshr i64 %17, 32
%33 = trunc i64 %32 to i32
%34 = and i32 %33, %30
%35 = load i32, i32* @ICRNL
%36 = or i32 %35, %34
store i32 %36, i32* %31
%37 = load i32, i32* @TCSAFLUSH
%38 = call i32 @tcsetattr(i32 %13, i32 %37, %struct.termios* %5)
%39 = call i32 @tcdrain(i32 %13)
%40 = call i32 (i32, i8*, ...) @dprintf(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%41 = call i32 @read(i32 %13, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getpass.password, i64 0, i64 0), i32 128)
%42 = icmp sgt i32 %41, -1
br i1 %42, label %43, label %58
43: ; preds = %15
%44 = icmp eq i32 %41, 0
br i1 %44, label %54, label %45
45: ; preds = %43
%46 = add nsw i32 %41, -1
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds [128 x i8], [128 x i8]* @getpass.password, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 10
%51 = icmp eq i32 %41, 128
%52 = or i1 %51, %50
%53 = select i1 %52, i32 %46, i32 %41
br label %54
54: ; preds = %45, %43
%55 = phi i32 [ 0, %43 ], [ %53, %45 ]
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds [128 x i8], [128 x i8]* @getpass.password, i64 0, i64 %56
store i8 0, i8* %57
br label %58
58: ; preds = %54, %15
%59 = phi i32 [ %55, %54 ], [ %41, %15 ]
%60 = load i32, i32* @TCSAFLUSH
%61 = call i32 @tcsetattr(i32 %13, i32 %60, %struct.termios* %3)
%62 = call i32 (i32, i8*, ...) @dprintf(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%63 = call i32 @close(i32 %13)
%64 = icmp slt i32 %59, 0
%65 = select i1 %64, i8* null, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getpass.password, i64 0, i64 0)
br label %66
66: ; preds = %1, %58
%67 = phi i8* [ %65, %58 ], [ null, %1 ]
ret i8* %67
}