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

/* Variables and functions */
int ECHO;
int ISIG;
int TCSAFLUSH;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int, struct termios *);
char *getpass(const char *prompt) {
  FILE *in, *out;
  struct termios s, t;
  int tty_changed;
  static char *buf;
  static size_t bufsize;
  ssize_t nread;
  in = fopen("/dev/tty", "w+");
  if (in == NULL) {
    in = stdin;
    out = stderr;
  } else
    out = in;
  if (tcgetattr(fileno(in), &t) == 0) {
    s = t;
    t.c_lflag &= ~(ECHO | ISIG);
    tty_changed = (tcsetattr(fileno(in), TCSAFLUSH | 0, &t) == 0);
  } else
    tty_changed = 0;
  fputs(prompt, out);
  fflush(out);
  nread = getline(&buf, &bufsize, in);
  if (buf != NULL) {
    if (nread < 0)
      buf[0] = '\0';
    else if (buf[nread - 1] == '\n') {
      buf[nread - 1] = '\0';
      if (tty_changed) {
        if (out == in)
          fseek(out, 0, 1);
        putc('\n', out);
      }
    }
  }
  if (tty_changed)
    (void)tcsetattr(fileno(in), TCSAFLUSH | 0, &s);
  if (in != stdin)
    fclose(in);
  return buf;
}


x86 assembly (clang, -O0):
<getpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe4d(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ef <getpass+0x4f>
mov    0x2e0b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11f7 <getpass+0x57>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fileno@plt>
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1090 <tcgetattr@plt>
cmp    $0x0,%rax
jne    126a <getpass+0xca>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    0x2da5(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
lea    -0x28(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    1271 <getpass+0xd1>
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdx
lea    0x2de6(%rip),%rdi
lea    0x2de7(%rip),%rsi
call   10c0 <getline@plt>
mov    %eax,-0x30(%rbp)
cmpq   $0x0,0x2dcf(%rip)
je     133e <getpass+0x19e>
cmpl   $0x0,-0x30(%rbp)
jge    12c8 <getpass+0x128>
mov    0x2db8(%rip),%rax
movb   $0x0,(%rax)
jmp    1339 <getpass+0x199>
mov    0x2da9(%rip),%rax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1334 <getpass+0x194>
mov    0x2d8c(%rip),%rax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x2c(%rbp)
je     132f <getpass+0x18f>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1321 <getpass+0x181>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1050 <putc@plt>
jmp    1334 <getpass+0x194>
jmp    1339 <getpass+0x199>
jmp    133e <getpass+0x19e>
cmpl   $0x0,-0x2c(%rbp)
je     1368 <getpass+0x1c8>
mov    -0x10(%rbp),%rdi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
lea    -0x20(%rbp),%rdx
call   10a0 <tcsetattr@plt>
mov    -0x10(%rbp),%rax
mov    0x2c6d(%rip),%rcx
cmp    (%rcx),%rax
je     1385 <getpass+0x1e5>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2cec(%rip),%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    %rdi,%r15
lea    0xe4a(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    0x2e14(%rip),%r12
mov    %rax,%r14
test   %rax,%rax
jne    11e2 <getpass+0x42>
mov    0x2de5(%rip),%rax
mov    (%rax),%rbx
mov    (%r12),%r14
mov    %r14,%rdi
call   1060 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1090 <tcgetattr@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    123f <getpass+0x9f>
mov    (%rsp),%eax
mov    0x2dd3(%rip),%rcx
mov    0x2dc4(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,0x8(%rsp)
not    %edx
and    %eax,%edx
mov    %edx,(%rsp)
mov    %r14,%rdi
call   1060 <fileno@plt>
mov    0x2dbe(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   10a0 <tcsetattr@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
lea    0x2e1f(%rip),%rdi
lea    0x2e20(%rip),%rsi
mov    %r14,%rdx
call   10c0 <getline@plt>
mov    0x2e09(%rip),%rcx
test   %rcx,%rcx
je     12b0 <getpass+0x110>
test   %eax,%eax
js     12ad <getpass+0x10d>
cltq
cmpb   $0xa,-0x1(%rax,%rcx,1)
jne    12b0 <getpass+0x110>
movb   $0x0,-0x1(%rcx,%rax,1)
test   %ebp,%ebp
je     12d1 <getpass+0x131>
cmp    %r14,%rbx
jne    129e <getpass+0xfe>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <fseek@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
jmp    12b4 <getpass+0x114>
movb   $0x0,(%rcx)
test   %ebp,%ebp
je     12d1 <getpass+0x131>
mov    %r14,%rdi
call   1060 <fileno@plt>
mov    0x2d25(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   10a0 <tcsetattr@plt>
cmp    (%r12),%r14
je     12df <getpass+0x13f>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2d92(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@getpass.buf = internal global i8* null
@getpass.bufsize = internal global i64 0
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"w+\00"
@stdin = global i32* null
@stderr = global i32* null
@ECHO = global i32 0
@ISIG = global i32 0
@TCSAFLUSH = global i32 0
define i8* @getpass(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.termios
%6 = alloca %struct.termios
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32*, i32** @stdin
store i32* %13, i32** %3
%14 = load i32*, i32** @stderr
store i32* %14, i32** %4
br label %17
15: ; preds = %1
%16 = load i32*, i32** %3
store i32* %16, i32** %4
br label %17
17: ; preds = %15, %12
%18 = load i32*, i32** %3
%19 = call i32 @fileno(i32* %18)
%20 = call i64 @tcgetattr(i32 %19, %struct.termios* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %39
22: ; preds = %17
%23 = bitcast %struct.termios* %5 to i8*
%24 = bitcast %struct.termios* %6 to i8*
%25 = load i32, i32* @ECHO
%26 = load i32, i32* @ISIG
%27 = or i32 %25, %26
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32*, i32** %3
%33 = call i32 @fileno(i32* %32)
%34 = load i32, i32* @TCSAFLUSH
%35 = or i32 %34, 0
%36 = call i64 @tcsetattr(i32 %33, i32 %35, %struct.termios* %6)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
store i32 %38, i32* %7
br label %40
39: ; preds = %17
store i32 0, i32* %7
br label %40
40: ; preds = %39, %22
%41 = load i8*, i8** %2
%42 = load i32*, i32** %4
%43 = call i32 @fputs(i8* %41, i32* %42)
%44 = load i32*, i32** %4
%45 = call i32 @fflush(i32* %44)
%46 = load i32*, i32** %3
%47 = call i32 @getline(i8** @getpass.buf, i64* @getpass.bufsize, i32* %46)
store i32 %47, i32* %8
%48 = load i8*, i8** @getpass.buf
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %86
50: ; preds = %40
%51 = load i32, i32* %8
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i8*, i8** @getpass.buf
%55 = getelementptr inbounds i8, i8* %54, i64 0
store i8 0, i8* %55
br label %85
56: ; preds = %50
%57 = load i8*, i8** @getpass.buf
%58 = load i32, i32* %8
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 10
br i1 %64, label %65, label %84
65: ; preds = %56
%66 = load i8*, i8** @getpass.buf
%67 = load i32, i32* %8
%68 = sub nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %66, i64 %69
store i8 0, i8* %70
%71 = load i32, i32* %7
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %83
73: ; preds = %65
%74 = load i32*, i32** %4
%75 = load i32*, i32** %3
%76 = icmp eq i32* %74, %75
br i1 %76, label %77, label %80
77: ; preds = %73
%78 = load i32*, i32** %4
%79 = call i32 @fseek(i32* %78, i32 0, i32 1)
br label %80
80: ; preds = %77, %73
%81 = load i32*, i32** %4
%82 = call i32 @putc(i8 signext 10, i32* %81)
br label %83
83: ; preds = %80, %65
br label %84
84: ; preds = %83, %56
br label %85
85: ; preds = %84, %53
br label %86
86: ; preds = %85, %40
%87 = load i32, i32* %7
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %95
89: ; preds = %86
%90 = load i32*, i32** %3
%91 = call i32 @fileno(i32* %90)
%92 = load i32, i32* @TCSAFLUSH
%93 = or i32 %92, 0
%94 = call i64 @tcsetattr(i32 %91, i32 %93, %struct.termios* %5)
br label %95
95: ; preds = %89, %86
%96 = load i32*, i32** %3
%97 = load i32*, i32** @stdin
%98 = icmp ne i32* %96, %97
br i1 %98, label %99, label %102
99: ; preds = %95
%100 = load i32*, i32** %3
%101 = call i32 @fclose(i32* %100)
br label %102
102: ; preds = %99, %95
%103 = load i8*, i8** @getpass.buf
ret i8* %103
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@getpass.buf = internal global i8* null
@getpass.bufsize = internal global i64 0
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"w+\00"
@stdin = global i32* null
@stderr = global i32* null
@ECHO = global i32 0
@ISIG = global i32 0
@TCSAFLUSH = global i32 0
define i8* @getpass(i8* nocapture %0) {
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %2 to i8*
%5 = bitcast %struct.termios* %3 to i8*
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
%8 = load i32*, i32** @stdin
%9 = load i32*, i32** @stderr
%10 = select i1 %7, i32* %9, i32* %6
%11 = select i1 %7, i32* %8, i32* %6
%12 = tail call i32 @fileno(i32* %11)
%13 = call i64 @tcgetattr(i32 %12, %struct.termios* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%17 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%18 = load i32, i32* %16
store i32 %18, i32* %17
%19 = load i32, i32* @ECHO
%20 = load i32, i32* @ISIG
%21 = or i32 %20, %19
%22 = xor i32 %21, -1
%23 = and i32 %18, %22
store i32 %23, i32* %16
%24 = call i32 @fileno(i32* %11)
%25 = load i32, i32* @TCSAFLUSH
%26 = call i64 @tcsetattr(i32 %24, i32 %25, %struct.termios* %3)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %1, %15
%30 = phi i32 [ %28, %15 ], [ 0, %1 ]
%31 = call i32 @fputs(i8* %0, i32* %10)
%32 = call i32 @fflush(i32* %10)
%33 = call i32 @getline(i8** @getpass.buf, i64* @getpass.bufsize, i32* %11)
%34 = load i8*, i8** @getpass.buf
%35 = icmp eq i8* %34, null
br i1 %35, label %53, label %36
36: ; preds = %29
%37 = icmp slt i32 %33, 0
br i1 %37, label %38, label %39
38: ; preds = %36
store i8 0, i8* %34
br label %53
39: ; preds = %36
%40 = add nsw i32 %33, -1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %34, i64 %41
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 10
br i1 %44, label %45, label %53
45: ; preds = %39
store i8 0, i8* %42
%46 = icmp eq i32 %30, 0
br i1 %46, label %59, label %47
47: ; preds = %45
%48 = icmp eq i32* %10, %11
br i1 %48, label %49, label %51
49: ; preds = %47
%50 = call i32 @fseek(i32* %10, i32 0, i32 1)
br label %51
51: ; preds = %47, %49
%52 = call i32 @putc(i8 signext 10, i32* %10)
br label %55
53: ; preds = %38, %39, %29
%54 = icmp eq i32 %30, 0
br i1 %54, label %59, label %55
55: ; preds = %51, %53
%56 = call i32 @fileno(i32* %11)
%57 = load i32, i32* @TCSAFLUSH
%58 = call i64 @tcsetattr(i32 %56, i32 %57, %struct.termios* %2)
br label %59
59: ; preds = %45, %55, %53
%60 = load i32*, i32** @stdin
%61 = icmp eq i32* %11, %60
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = call i32 @fclose(i32* %11)
br label %64
64: ; preds = %62, %59
%65 = load i8*, i8** @getpass.buf
ret i8* %65
}