#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
ssize_t getpass4(const char *prompt, char **lineptr, size_t *n, FILE *stream) {
  struct termios old, new;
  int nread;
  if (tcgetattr(fileno(stream), &old))
    return -1;
  new = old;
  new.c_lflag &= ~ECHO;
  if (tcsetattr(fileno(stream), TCSAFLUSH, &new))
    return -1;
  if (prompt)
    fprintf(stderr, "%s: ", prompt);
  nread = getline(lineptr, n, stream);
  if (prompt)
    fprintf(stderr, "\n");
  tcsetattr(fileno(stream), TCSAFLUSH, &old);
  return nread;
}


x86 assembly (clang, -O0):
<getpass4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
je     1192 <getpass4+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <getpass4+0x10c>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     11dd <getpass4+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <getpass4+0x10c>
cmpq   $0x0,-0x10(%rbp)
je     1203 <getpass4+0xb3>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1239 <getpass4+0xe9>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpass4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rcx,%rdi
call   1040 <fileno@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1050 <tcgetattr@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1233 <getpass4+0xe3>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    %rbx,%rdi
call   1040 <fileno@plt>
mov    0x2e3a(%rip),%r13
mov    0x0(%r13),%esi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
call   1060 <tcsetattr@plt>
test   %rax,%rax
jne    1233 <getpass4+0xe3>
test   %r12,%r12
je     120b <getpass4+0xbb>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
mov    %eax,%ebp
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    121b <getpass4+0xcb>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fileno@plt>
mov    0x0(%r13),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1060 <tcsetattr@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c"%s: \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @getpass4(i8* %0, i8** %1, i64* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64*
%9 = alloca i32*
%10 = alloca %struct.termios
%11 = alloca %struct.termios
%12 = alloca i32
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i64* %2, i64** %8
store i32* %3, i32** %9
%13 = load i32*, i32** %9
%14 = call i32 @fileno(i32* %13)
%15 = call i64 @tcgetattr(i32 %14, %struct.termios* %10)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %55
18: ; preds = %4
%19 = bitcast %struct.termios* %11 to i8*
%20 = bitcast %struct.termios* %10 to i8*
%21 = load i32, i32* @ECHO
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32*, i32** %9
%27 = call i32 @fileno(i32* %26)
%28 = load i32, i32* @TCSAFLUSH
%29 = call i64 @tcsetattr(i32 %27, i32 %28, %struct.termios* %11)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %18
store i32 -1, i32* %5
br label %55
32: ; preds = %18
%33 = load i8*, i8** %6
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %6
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %35, %32
%40 = load i8**, i8*** %7
%41 = load i64*, i64** %8
%42 = load i32*, i32** %9
%43 = call i32 @getline(i8** %40, i64* %41, i32* %42)
store i32 %43, i32* %12
%44 = load i8*, i8** %6
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %46, %39
%50 = load i32*, i32** %9
%51 = call i32 @fileno(i32* %50)
%52 = load i32, i32* @TCSAFLUSH
%53 = call i64 @tcsetattr(i32 %51, i32 %52, %struct.termios* %10)
%54 = load i32, i32* %12
store i32 %54, i32* %5
br label %55
55: ; preds = %49, %31, %17
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c"%s: \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @getpass4(i8* %0, i8** %1, i64* %2, i32* %3) {
%5 = alloca %struct.termios
%6 = alloca %struct.termios
%7 = bitcast %struct.termios* %5 to i8*
%8 = bitcast %struct.termios* %6 to i8*
%9 = tail call i32 @fileno(i32* %3)
%10 = call i64 @tcgetattr(i32 %9, %struct.termios* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %38
12: ; preds = %4
%13 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%14 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 0
%15 = load i32, i32* %13
%16 = load i32, i32* @ECHO
%17 = xor i32 %16, -1
%18 = and i32 %15, %17
store i32 %18, i32* %14
%19 = call i32 @fileno(i32* %3)
%20 = load i32, i32* @TCSAFLUSH
%21 = call i64 @tcsetattr(i32 %19, i32 %20, %struct.termios* %6)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %38
23: ; preds = %12
%24 = icmp eq i8* %0, null
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = call i32 @getline(i8** %1, i64* %2, i32* %3)
br label %33
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%30 = call i32 @getline(i8** %1, i64* %2, i32* %3)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %25, %27
%34 = phi i32 [ %26, %25 ], [ %30, %27 ]
%35 = call i32 @fileno(i32* %3)
%36 = load i32, i32* @TCSAFLUSH
%37 = call i64 @tcsetattr(i32 %35, i32 %36, %struct.termios* %5)
br label %38
38: ; preds = %12, %4, %33
%39 = phi i32 [ %34, %33 ], [ -1, %4 ], [ -1, %12 ]
ret i32 %39
}