#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int EOF;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ _login_error(char *, int);
int fgetc(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
size_t strlen(char *);
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
char const *_do_ask_password(void) {
  static char buf[256];
  struct termios t1;
  struct termios t2;
  size_t len;
  int c;
  char *p;
  fputs("password: ", stderr);
  if (tcgetattr(fileno(stdin), &t1) != 0) {
    fputc('\n', stderr);
    _login_error("tcgetattr", 1);
    return NULL;
  }
  t2 = t1;
  t2.c_lflag &= ~ECHO;
  if (tcsetattr(fileno(stdin), TCSAFLUSH, &t2) != 0) {
    fputc('\n', stderr);
    _login_error("tcsetattr", 1);
    return NULL;
  }
  p = fgets(buf, sizeof(buf), stdin);
  fputc('\n', stderr);
  if (tcsetattr(fileno(stdin), TCSAFLUSH, &t1) != 0)
    _login_error("tcsetattr", 1);
  if (p == NULL) {
    _login_error("fgets", 1);
    return NULL;
  }
  len = strlen(buf);
  if (len == 0)
    return NULL;
  if (buf[len - 1] == '\n') {
    buf[len - 1] = '\0';
    return buf;
  }
  while ((c = fgetc(stdin)) != EOF && c != '\n')
    ;
  return NULL;
}


x86 assembly (clang, -O0):
<_do_ask_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1080 <fileno@plt>
mov    %eax,%edi
lea    -0x10(%rbp),%rsi
call   1090 <tcgetattr@plt>
cmp    $0x0,%rax
je     1201 <_do_ask_password+0x71>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
lea    0xe21(%rip),%rdi
mov    $0x1,%esi
call   10b0 <_login_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <_do_ask_password+0x237>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1080 <fileno@plt>
mov    %eax,%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
je     1276 <_do_ask_password+0xe6>
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
lea    0xdb6(%rip),%rdi
mov    $0x1,%esi
call   10b0 <_login_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <_do_ask_password+0x237>
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
lea    0x2dfa(%rip),%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1080 <fileno@plt>
mov    %eax,%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
je     12e4 <_do_ask_password+0x154>
lea    0xd3b(%rip),%rdi
mov    $0x1,%esi
call   10b0 <_login_error@plt>
cmpq   $0x0,-0x30(%rbp)
jne    130d <_do_ask_password+0x17d>
lea    0xd29(%rip),%rdi
mov    $0x1,%esi
call   10b0 <_login_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <_do_ask_password+0x237>
lea    0x2d6c(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1335 <_do_ask_password+0x1a5>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <_do_ask_password+0x237>
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2d3c(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1374 <_do_ask_password+0x1e4>
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2d20(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2d15(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c7 <_do_ask_password+0x237>
jmp    1379 <_do_ask_password+0x1e9>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
mov    0x2c3b(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x31(%rbp)
je     13aa <_do_ask_password+0x21a>
cmpl   $0xa,-0x24(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    13ba <_do_ask_password+0x22a>
jmp    13bf <_do_ask_password+0x22f>
jmp    1379 <_do_ask_password+0x1e9>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_do_ask_password>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e1e(%rip),%rbx
mov    (%rbx),%esi
lea    0xe55(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e29(%rip),%r14
mov    (%r14),%edi
call   1080 <fileno@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1090 <tcgetattr@plt>
test   %rax,%rax
je     11e5 <_do_ask_password+0x55>
mov    (%rbx),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
lea    0xe28(%rip),%rdi
jmp    122f <_do_ask_password+0x9f>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    (%r14),%edi
call   1080 <fileno@plt>
mov    0x2de1(%rip),%r12
mov    (%r12),%esi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
call   10a0 <tcsetattr@plt>
test   %rax,%rax
je     124a <_do_ask_password+0xba>
mov    (%rbx),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
lea    0xde6(%rip),%rdi
mov    $0x1,%esi
call   10b0 <_login_error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r14),%edx
lea    0x2e2c(%rip),%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rax,%r15
mov    (%rbx),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    (%r14),%edi
call   1080 <fileno@plt>
mov    (%r12),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   10a0 <tcsetattr@plt>
test   %rax,%rax
je     129b <_do_ask_password+0x10b>
lea    0xd84(%rip),%rdi
mov    $0x1,%esi
call   10b0 <_login_error@plt>
test   %r15,%r15
je     12c5 <_do_ask_password+0x135>
lea    0x2dd9(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1239 <_do_ask_password+0xa9>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    12d1 <_do_ask_password+0x141>
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    123b <_do_ask_password+0xab>
lea    0xd53(%rip),%rdi
jmp    122f <_do_ask_password+0x9f>
mov    0x2cf8(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1050 <fgetc@plt>
cmp    $0xa,%eax
je     123b <_do_ask_password+0xab>
cmp    (%r15),%eax
jne    12e0 <_do_ask_password+0x150>
jmp    123b <_do_ask_password+0xab>

LLVM IR (-O0):
%struct.termios = type { i32 }
@_do_ask_password.buf = internal global [256 x i8] zeroinitializer
@.str = [11 x i8] c"password: \00"
@stderr = global i32 0
@stdin = global i32 0
@.str.1 = [10 x i8] c"tcgetattr\00"
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@.str.2 = [10 x i8] c"tcsetattr\00"
@.str.3 = [6 x i8] c"fgets\00"
@EOF = global i32 0
define i8* @_do_ask_password() {
%1 = alloca i8*
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = load i32, i32* @stderr
%8 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @stdin
%10 = call i32 @fileno(i32 %9)
%11 = call i64 @tcgetattr(i32 %10, %struct.termios* %2)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fputc(i8 signext 10, i32 %14)
%16 = call i32 @_login_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i8* null, i8** %1
br label %80
17: ; preds = %0
%18 = bitcast %struct.termios* %3 to i8*
%19 = bitcast %struct.termios* %2 to i8*
%20 = load i32, i32* @ECHO
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @stdin
%26 = call i32 @fileno(i32 %25)
%27 = load i32, i32* @TCSAFLUSH
%28 = call i64 @tcsetattr(i32 %26, i32 %27, %struct.termios* %3)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %17
%31 = load i32, i32* @stderr
%32 = call i32 @fputc(i8 signext 10, i32 %31)
%33 = call i32 @_login_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i8* null, i8** %1
br label %80
34: ; preds = %17
%35 = load i32, i32* @stdin
%36 = call i8* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 0), i32 256, i32 %35)
store i8* %36, i8** %6
%37 = load i32, i32* @stderr
%38 = call i32 @fputc(i8 signext 10, i32 %37)
%39 = load i32, i32* @stdin
%40 = call i32 @fileno(i32 %39)
%41 = load i32, i32* @TCSAFLUSH
%42 = call i64 @tcsetattr(i32 %40, i32 %41, %struct.termios* %2)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %34
%45 = call i32 @_login_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %46
46: ; preds = %44, %34
%47 = load i8*, i8** %6
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @_login_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i8* null, i8** %1
br label %80
51: ; preds = %46
%52 = call i64 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 0))
store i64 %52, i64* %4
%53 = load i64, i64* %4
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
store i8* null, i8** %1
br label %80
56: ; preds = %51
%57 = load i64, i64* %4
%58 = sub i64 %57, 1
%59 = getelementptr inbounds [256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 10
br i1 %62, label %63, label %67
63: ; preds = %56
%64 = load i64, i64* %4
%65 = sub i64 %64, 1
%66 = getelementptr inbounds [256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 %65
store i8 0, i8* %66
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 0), i8** %1
br label %80
67: ; preds = %56
br label %68
68: ; preds = %78, %67
%69 = load i32, i32* @stdin
%70 = call i32 @fgetc(i32 %69)
store i32 %70, i32* %5
%71 = load i32, i32* @EOF
%72 = icmp ne i32 %70, %71
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = load i32, i32* %5
%75 = icmp ne i32 %74, 10
br label %76
76: ; preds = %73, %68
%77 = phi i1 [ false, %68 ], [ %75, %73 ]
br i1 %77, label %78, label %79
78: ; preds = %76
br label %68
79: ; preds = %76
store i8* null, i8** %1
br label %80
80: ; preds = %79, %63, %55, %49, %30, %13
%81 = load i8*, i8** %1
ret i8* %81
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@_do_ask_password.buf = internal global [256 x i8] zeroinitializer
@.str = [11 x i8] c"password: \00"
@stderr = global i32 0
@stdin = global i32 0
@.str.1 = [10 x i8] c"tcgetattr\00"
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@.str.2 = [10 x i8] c"tcsetattr\00"
@.str.3 = [6 x i8] c"fgets\00"
@EOF = global i32 0
define i8* @_do_ask_password() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %1 to i8*
%4 = bitcast %struct.termios* %2 to i8*
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stdin
%8 = tail call i32 @fileno(i32 %7)
%9 = call i64 @tcgetattr(i32 %8, %struct.termios* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fputc(i8 signext 10, i32 %12)
%14 = call i32 @_login_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %63
15: ; preds = %0
%16 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%17 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%18 = load i32, i32* %16
%19 = load i32, i32* @ECHO
%20 = xor i32 %19, -1
%21 = and i32 %18, %20
store i32 %21, i32* %17
%22 = load i32, i32* @stdin
%23 = call i32 @fileno(i32 %22)
%24 = load i32, i32* @TCSAFLUSH
%25 = call i64 @tcsetattr(i32 %23, i32 %24, %struct.termios* %2)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = call i32 @fputc(i8 signext 10, i32 %28)
%30 = call i32 @_login_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %63
31: ; preds = %15
%32 = load i32, i32* @stdin
%33 = call i8* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 0), i32 256, i32 %32)
%34 = load i32, i32* @stderr
%35 = call i32 @fputc(i8 signext 10, i32 %34)
%36 = load i32, i32* @stdin
%37 = call i32 @fileno(i32 %36)
%38 = load i32, i32* @TCSAFLUSH
%39 = call i64 @tcsetattr(i32 %37, i32 %38, %struct.termios* %1)
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %31
%42 = call i32 @_login_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %43
43: ; preds = %41, %31
%44 = icmp eq i8* %33, null
br i1 %44, label %45, label %47
45: ; preds = %43
%46 = call i32 @_login_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 1)
br label %63
47: ; preds = %43
%48 = call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %63, label %50
50: ; preds = %47
%51 = add i64 %48, -1
%52 = getelementptr inbounds [256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = icmp eq i8 %53, 10
br i1 %54, label %55, label %56
55: ; preds = %50
store i8 0, i8* %52
br label %63
56: ; preds = %50, %56
%57 = load i32, i32* @stdin
%58 = call i32 @fgetc(i32 %57)
%59 = load i32, i32* @EOF
%60 = icmp ne i32 %58, %59
%61 = icmp ne i32 %58, 10
%62 = and i1 %61, %60
br i1 %62, label %56, label %63
63: ; preds = %56, %47, %55, %45, %27, %11
%64 = phi i8* [ null, %11 ], [ null, %27 ], [ null, %45 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_password.buf, i64 0, i64 0), %55 ], [ null, %47 ], [ null, %56 ]
ret i8* %64
}