#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_cc;
};
typedef int /*<<< orphan*/ old;
typedef int /*<<< orphan*/ c;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ TCSANOW;
size_t VERASE;
size_t VKILL;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ bcopy(struct termios *, struct termios *, int);
int read(int /*<<< orphan*/, char *, int);
int strlen(char *);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int /*<<< orphan*/ write(int, char *, int);
char *getpass(char *prompt) {
  struct termios old, new;
  char c;
  static char buf[64];
  int len = 0;
  tcgetattr(0, &old);
  bcopy(&old, &new, sizeof(old));
  new.c_lflag &= ~(ECHO | ICANON);
  new.c_cc[VMIN] = 1;
  new.c_cc[VTIME] = 0;
  tcsetattr(0, TCSANOW, &new);
  write(1, prompt, strlen(prompt));
  for (;;) {
    if (read(0, &c, sizeof(c)) != 1) {
      break;
    }
    if (c >= ' ') {
      if (len < (sizeof(buf) - 1)) {
        buf[len++] = c;
      }
      continue;
    }
    if (c == old.c_cc[VERASE]) {
      if (len > 0) {
        (void)write(1, "\b \b", 3);
        len -= 1;
      }
      continue;
    }
    if (c == old.c_cc[VKILL]) {
      while (len > 0) {
        (void)write(1, "\b \b", 3);
        len -= 1;
      }
      continue;
    }
    (void)write(1, "\7", 1);
  }
  buf[len] = '\0';
  tcsetattr(0, TCSANOW, &old);
  return (buf);
}


x86 assembly (clang, -O0):
<getpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x30(%rbp)
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1070 <tcgetattr@plt>
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1060 <bcopy@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    0x2e10(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e12(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2ded(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x28(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
xor    %edi,%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
je     1228 <getpass+0xc8>
jmp    1317 <getpass+0x1b7>
movsbl -0x29(%rbp),%eax
cmp    $0x20,%eax
jl     1263 <getpass+0x103>
movslq -0x30(%rbp),%rax
cmp    $0x3f,%rax
jae    125e <getpass+0xfe>
mov    -0x29(%rbp),%dl
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp)
movslq %eax,%rcx
lea    0x2e05(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    120a <getpass+0xaa>
movsbl -0x29(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    0x2d6e(%rip),%rdx
mov    (%rdx),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    12ac <getpass+0x14c>
cmpl   $0x0,-0x30(%rbp)
jle    12a7 <getpass+0x147>
mov    $0x1,%edi
lea    0xd6c(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    120a <getpass+0xaa>
movsbl -0x29(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    0x2d2d(%rip),%rdx
mov    (%rdx),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    12ff <getpass+0x19f>
jmp    12cc <getpass+0x16c>
cmpl   $0x0,-0x30(%rbp)
jle    12fa <getpass+0x19a>
mov    $0x1,%edi
lea    0xd1e(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12cc <getpass+0x16c>
jmp    120a <getpass+0xaa>
mov    $0x1,%edx
lea    0xcf9(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    120a <getpass+0xaa>
movslq -0x30(%rbp),%rcx
lea    0x2d3e(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    0x2cab(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1080 <tcsetattr@plt>
lea    0x2d1f(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpass>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0x28(%rsp),%rsi
xor    %edi,%edi
call   1060 <tcgetattr@plt>
movups 0x28(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2e50(%rip),%rax
mov    0x2e29(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    %ecx,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e0a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
xor    %edi,%edi
call   1070 <tcsetattr@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    12de <getpass+0x18e>
xor    %ebp,%ebp
lea    0xf(%rsp),%rbx
mov    0x2dd4(%rip),%r13
lea    0xded(%rip),%r14
mov    0x2dce(%rip),%r12
lea    0xde3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0xf(%rsp),%eax
cmp    $0x20,%eax
jge    1279 <getpass+0x129>
mov    0x30(%rsp),%rcx
mov    0x0(%r13),%rdx
cmp    %eax,(%rcx,%rdx,4)
je     128f <getpass+0x13f>
mov    (%r12),%rdx
cmp    %eax,(%rcx,%rdx,4)
je     12aa <getpass+0x15a>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
je     1230 <getpass+0xe0>
jmp    12de <getpass+0x18e>
cmp    $0x3e,%ebp
ja     1263 <getpass+0x113>
mov    %ebp,%ecx
add    $0x1,%ebp
lea    0x2dd6(%rip),%rdx
mov    %al,(%rcx,%rdx,1)
jmp    1263 <getpass+0x113>
test   %ebp,%ebp
jle    1263 <getpass+0x113>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jmp    1263 <getpass+0x113>
test   %ebp,%ebp
jle    1263 <getpass+0x113>
add    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     12c0 <getpass+0x170>
xor    %ebp,%ebp
jmp    1263 <getpass+0x113>
movslq %ebp,%rax
lea    0x2d78(%rip),%rbx
movb   $0x0,(%rax,%rbx,1)
mov    0x2ce5(%rip),%rax
mov    (%rax),%esi
lea    0x28(%rsp),%rdx
xor    %edi,%edi
call   1070 <tcsetattr@plt>
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@getpass.buf = internal global [64 x i8] zeroinitializer
@ECHO = global i32 0
@ICANON = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@VERASE = global i64 0
@.str = [4 x i8] c"\08 \08\00"
@VKILL = global i64 0
@.str.1 = [2 x i8] c"\07\00"
define i8* @getpass(i8* %0) {
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = alloca i8
%5 = bitcast %struct.termios* %2 to i8*
%6 = bitcast %struct.termios* %3 to i8*
%7 = call i32 @tcgetattr(i32 0, %struct.termios* %2)
%8 = load i32, i32* @ECHO
%9 = load i32, i32* @ICANON
%10 = or i32 %9, %8
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%16 = load i32*, i32** %15
%17 = load i64, i64* @VMIN
%18 = getelementptr inbounds i32, i32* %16, i64 %17
store i32 1, i32* %18
%19 = load i64, i64* @VTIME
%20 = getelementptr inbounds i32, i32* %16, i64 %19
store i32 0, i32* %20
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 0, i32 %21, %struct.termios* %3)
%23 = call i32 @strlen(i8* %0)
%24 = call i32 @write(i32 1, i8* %0, i32 %23)
%25 = call i32 @read(i32 0, i8* %4, i32 1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %72
27: ; preds = %1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
br label %29
29: ; preds = %27, %41
%30 = phi i32 [ 0, %27 ], [ %42, %41 ]
br label %31
31: ; preds = %29, %68
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = icmp sgt i8 %32, 31
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = icmp ult i32 %30, 63
br i1 %36, label %37, label %41
37: ; preds = %35
%38 = zext i32 %30 to i64
%39 = add nuw nsw i32 %30, 1
%40 = getelementptr inbounds [64 x i8], [64 x i8]* @getpass.buf, i64 0, i64 %38
store i8 %32, i8* %40
br label %41
41: ; preds = %63, %51, %53, %35, %37, %61
%42 = phi i32 [ %30, %61 ], [ %39, %37 ], [ %30, %35 ], [ %55, %53 ], [ %30, %51 ], [ 0, %63 ]
%43 = call i32 @read(i32 0, i8* %4, i32 1)
%44 = icmp eq i32 %43, 1
br i1 %44, label %29, label %72
45: ; preds = %31
%46 = load i32*, i32** %28
%47 = load i64, i64* @VERASE
%48 = getelementptr inbounds i32, i32* %46, i64 %47
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, %33
br i1 %50, label %51, label %56
51: ; preds = %45
%52 = icmp sgt i32 %30, 0
br i1 %52, label %53, label %41
53: ; preds = %51
%54 = call i32 @write(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%55 = add nsw i32 %30, -1
br label %41
56: ; preds = %45
%57 = load i64, i64* @VKILL
%58 = getelementptr inbounds i32, i32* %46, i64 %57
%59 = load i32, i32* %58
%60 = icmp eq i32 %59, %33
br i1 %60, label %61, label %68
61: ; preds = %56
%62 = icmp sgt i32 %30, 0
br i1 %62, label %63, label %41
63: ; preds = %61, %63
%64 = phi i32 [ %66, %63 ], [ %30, %61 ]
%65 = call i32 @write(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%66 = add nsw i32 %64, -1
%67 = icmp ugt i32 %64, 1
br i1 %67, label %63, label %41
68: ; preds = %56
%69 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%70 = call i32 @read(i32 0, i8* %4, i32 1)
%71 = icmp eq i32 %70, 1
br i1 %71, label %31, label %72
72: ; preds = %41, %68, %1
%73 = phi i32 [ 0, %1 ], [ %30, %68 ], [ %42, %41 ]
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [64 x i8], [64 x i8]* @getpass.buf, i64 0, i64 %74
store i8 0, i8* %75
%76 = load i32, i32* @TCSANOW
%77 = call i32 @tcsetattr(i32 0, i32 %76, %struct.termios* %2)
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getpass.buf, i64 0, i64 0)
}