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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read_line(char *, size_t);
scalar_t__ set_echo(int);
int /*<<< orphan*/ stdout;
ssize_t read_pass(char *out, size_t outmax) {
  ssize_t ret;
  if (set_echo(0)) {
    return -1;
  }
  printf("Password: ");
  fflush(stdout);
  ret = read_line(out, outmax);
  printf("\n");
  if (set_echo(1)) {
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<read_pass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %edi,%edi
call   1030 <set_echo@plt>
cmp    $0x0,%rax
je     116d <read_pass+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <read_pass+0x89>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <read_line@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <set_echo@plt>
cmp    $0x0,%rax
je     11c3 <read_pass+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <read_pass+0x89>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pass>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <set_echo@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11b0 <read_pass+0x60>
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <read_line@plt>
mov    %eax,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1040 <set_echo@plt>
neg    %rax
sbb    %eax,%eax
or     %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Password: \00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @read_pass(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = call i64 @set_echo(i32 0)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %23
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = call i32 @read_line(i8* %14, i64 %15)
store i32 %16, i32* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i64 @set_echo(i32 1)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %10
store i32 -1, i32* %3
br label %23
21: ; preds = %10
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %23
23: ; preds = %21, %20, %9
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [11 x i8] c"Password: \00"
@stdout = global i32 0
define i32 @read_pass(i8* %0, i64 %1) {
%3 = tail call i64 @set_echo(i32 0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = tail call i32 @fflush(i32 %7)
%9 = tail call i32 @read_line(i8* %0, i64 %1)
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i64 @set_echo(i32 1)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i32 %9, i32 -1
br label %14
14: ; preds = %5, %2
%15 = phi i32 [ -1, %2 ], [ %13, %5 ]
ret i32 %15
}