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

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
ssize_t my_getpass(char **lineptr, size_t *n, FILE *stream) {
  struct termios old, new;
  int nread;
  if (tcgetattr(fileno(stream), &old) != 0)
    return -1;
  new = old;
  new.c_lflag &= ~ECHO;
  if (tcsetattr(fileno(stream), TCSAFLUSH, &new) != 0)
    return -1;
  nread = getline(lineptr, n, stream);
  (void)tcsetattr(fileno(stream), TCSAFLUSH, &old);
  return nread;
}


x86 assembly (clang, -O0):
<my_getpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fileno@plt>
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
je     117e <my_getpass+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <my_getpass+0xc0>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fileno@plt>
mov    %eax,%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
je     11c9 <my_getpass+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <my_getpass+0xc0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <getline@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fileno@plt>
mov    %eax,%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getpass>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1040 <tcgetattr@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11cd <my_getpass+0x8d>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <fileno@plt>
mov    0x2e56(%rip),%r12
mov    (%r12),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1050 <tcsetattr@plt>
test   %rax,%rax
jne    11cd <my_getpass+0x8d>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fileno@plt>
mov    (%r12),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1050 <tcsetattr@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
define i32 @my_getpass(i8** %0, i64* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca %struct.termios
%9 = alloca %struct.termios
%10 = alloca i32
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
%11 = load i32*, i32** %7
%12 = call i32 @fileno(i32* %11)
%13 = call i64 @tcgetattr(i32 %12, %struct.termios* %8)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %40
16: ; preds = %3
%17 = bitcast %struct.termios* %9 to i8*
%18 = bitcast %struct.termios* %8 to i8*
%19 = load i32, i32* @ECHO
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = load i32*, i32** %7
%25 = call i32 @fileno(i32* %24)
%26 = load i32, i32* @TCSAFLUSH
%27 = call i64 @tcsetattr(i32 %25, i32 %26, %struct.termios* %9)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %16
store i32 -1, i32* %4
br label %40
30: ; preds = %16
%31 = load i8**, i8*** %5
%32 = load i64*, i64** %6
%33 = load i32*, i32** %7
%34 = call i32 @getline(i8** %31, i64* %32, i32* %33)
store i32 %34, i32* %10
%35 = load i32*, i32** %7
%36 = call i32 @fileno(i32* %35)
%37 = load i32, i32* @TCSAFLUSH
%38 = call i64 @tcsetattr(i32 %36, i32 %37, %struct.termios* %8)
%39 = load i32, i32* %10
store i32 %39, i32* %4
br label %40
40: ; preds = %30, %29, %15
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
define i32 @my_getpass(i8** %0, i64* %1, i32* %2) {
%4 = alloca %struct.termios
%5 = alloca %struct.termios
%6 = bitcast %struct.termios* %4 to i8*
%7 = bitcast %struct.termios* %5 to i8*
%8 = tail call i32 @fileno(i32* %2)
%9 = call i64 @tcgetattr(i32 %8, %struct.termios* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %3
%12 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%13 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%14 = load i32, i32* %12
%15 = load i32, i32* @ECHO
%16 = xor i32 %15, -1
%17 = and i32 %14, %16
store i32 %17, i32* %13
%18 = call i32 @fileno(i32* %2)
%19 = load i32, i32* @TCSAFLUSH
%20 = call i64 @tcsetattr(i32 %18, i32 %19, %struct.termios* %5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %11
%23 = call i32 @getline(i8** %0, i64* %1, i32* %2)
%24 = call i32 @fileno(i32* %2)
%25 = load i32, i32* @TCSAFLUSH
%26 = call i64 @tcsetattr(i32 %24, i32 %25, %struct.termios* %4)
br label %27
27: ; preds = %11, %3, %22
%28 = phi i32 [ %23, %22 ], [ -1, %3 ], [ -1, %11 ]
ret i32 %28
}