#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 */

/* Variables and functions */
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ clear();
int /*<<< orphan*/ endwin();
int getch();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ mvaddstr(int, int, char const *);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ raw();
int /*<<< orphan*/ refresh();
void gui_main_get_password(const char **prompt, char *password, int size) {
  int line, i, ch;
  initscr();
  cbreak();
  noecho();
  raw();
  clear();
  line = 0;
  while (prompt[line]) {
    mvaddstr(line, 0, prompt[line]);
    line++;
  }
  mvaddstr(line, 0, "=> ");
  refresh();
  memset(password, '\0', size);
  i = 0;
  while (i < size - 1) {
    ch = getch();
    if (ch == '\n')
      break;
    if (ch == 3) {
      password[0] = 3;
      i = 1;
      break;
    }
    if (ch == 127) {
      if (i > 0) {
        i--;
        password[i] = '\0';
        mvaddstr(line, 3 + i, " ");
        move(line, 3 + i);
      }
    } else {
      password[i] = ch;
      mvaddstr(line, 3 + i, "*");
      i++;
    }
    refresh();
  }
  password[i] = '\0';
  refresh();
  endwin();
}


x86 assembly (clang, -O0):
<gui_main_get_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    $0x0,%al
call   10a0 <noecho@plt>
mov    $0x0,%al
call   1050 <raw@plt>
mov    $0x0,%al
call   10c0 <clear@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1224 <gui_main_get_password+0x74>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
xor    %esi,%esi
call   10b0 <mvaddstr@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ed <gui_main_get_password+0x3d>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
lea    0xdd0(%rip),%rdx
call   10b0 <mvaddstr@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1323 <gui_main_get_password+0x173>
mov    $0x0,%al
call   1080 <getch@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jne    127b <gui_main_get_password+0xcb>
jmp    1323 <gui_main_get_password+0x173>
cmpl   $0x3,-0x20(%rbp)
jne    1298 <gui_main_get_password+0xe8>
mov    -0x10(%rbp),%rax
movb   $0x3,(%rax)
movl   $0x1,-0x1c(%rbp)
jmp    1323 <gui_main_get_password+0x173>
cmpl   $0x7f,-0x20(%rbp)
jne    12e9 <gui_main_get_password+0x139>
cmpl   $0x0,-0x1c(%rbp)
jle    12e4 <gui_main_get_password+0x134>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
add    $0x3,%esi
lea    0xd31(%rip),%rdx
call   10b0 <mvaddstr@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
add    $0x3,%esi
call   10d0 <move@plt>
jmp    1317 <gui_main_get_password+0x167>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
add    $0x3,%esi
lea    0xcfb(%rip),%rdx
call   10b0 <mvaddstr@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <refresh@plt>
jmp    1251 <gui_main_get_password+0xa1>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1070 <refresh@plt>
mov    $0x0,%al
call   1090 <endwin@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_main_get_password>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <initscr@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
xor    %eax,%eax
call   10a0 <noecho@plt>
xor    %eax,%eax
call   1050 <raw@plt>
xor    %eax,%eax
call   10c0 <clear@plt>
mov    (%rbx),%rdx
mov    $0x0,%ebp
test   %rdx,%rdx
je     1217 <gui_main_get_password+0x67>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
xor    %esi,%esi
call   10b0 <mvaddstr@plt>
mov    0x8(%rbx,%rbp,8),%rdx
add    $0x1,%rbp
test   %rdx,%rdx
jne    1200 <gui_main_get_password+0x50>
lea    0xde2(%rip),%rdx
mov    %ebp,%edi
xor    %esi,%esi
call   10b0 <mvaddstr@plt>
xor    %eax,%eax
call   1070 <refresh@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
cmp    $0x2,%r15d
jl     12dd <gui_main_get_password+0x12d>
add    $0xffffffff,%r15d
lea    0xdb4(%rip),%r13
xor    %r12d,%r12d
jmp    126c <gui_main_get_password+0xbc>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1070 <refresh@plt>
cmp    %r15d,%r12d
jge    12dd <gui_main_get_password+0x12d>
xor    %eax,%eax
call   1080 <getch@plt>
cmp    $0x7f,%eax
je     12a0 <gui_main_get_password+0xf0>
cmp    $0xa,%eax
je     12dd <gui_main_get_password+0x12d>
cmp    $0x3,%eax
je     12d3 <gui_main_get_password+0x123>
movslq %r12d,%rcx
mov    %al,(%r14,%rcx,1)
lea    0x3(%r12),%esi
mov    %ebp,%edi
mov    %r13,%rdx
call   10b0 <mvaddstr@plt>
add    $0x1,%r12d
jmp    1260 <gui_main_get_password+0xb0>
xchg   %ax,%ax
test   %r12d,%r12d
jle    1260 <gui_main_get_password+0xb0>
lea    -0x1(%r12),%ebx
movb   $0x0,(%r14,%rbx,1)
add    $0x2,%r12d
mov    %ebp,%edi
mov    %r12d,%esi
lea    0xd43(%rip),%rdx
call   10b0 <mvaddstr@plt>
mov    %ebp,%edi
mov    %r12d,%esi
call   10d0 <move@plt>
mov    %ebx,%r12d
jmp    1260 <gui_main_get_password+0xb0>
movb   $0x3,(%r14)
mov    $0x1,%r12d
movslq %r12d,%rax
movb   $0x0,(%r14,%rax,1)
xor    %eax,%eax
call   1070 <refresh@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <endwin@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"=> \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"*\00"
define void @gui_main_get_password(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = call i32 (...) @initscr()
%11 = call i32 (...) @cbreak()
%12 = call i32 (...) @noecho()
%13 = call i32 (...) @raw()
%14 = call i32 (...) @clear()
store i32 0, i32* %7
br label %15
15: ; preds = %22, %3
%16 = load i8**, i8*** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %15
%23 = load i32, i32* %7
%24 = load i8**, i8*** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @mvaddstr(i32 %23, i32 0, i8* %28)
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %15
32: ; preds = %15
%33 = load i32, i32* %7
%34 = call i32 @mvaddstr(i32 %33, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%35 = call i32 (...) @refresh()
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = call i32 @memset(i8* %36, i8 signext 0, i32 %37)
store i32 0, i32* %8
br label %39
39: ; preds = %90, %32
%40 = load i32, i32* %8
%41 = load i32, i32* %6
%42 = sub nsw i32 %41, 1
%43 = icmp slt i32 %40, %42
br i1 %43, label %44, label %92
44: ; preds = %39
%45 = call i32 (...) @getch()
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %49
48: ; preds = %44
br label %92
49: ; preds = %44
%50 = load i32, i32* %9
%51 = icmp eq i32 %50, 3
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 0
store i8 3, i8* %54
store i32 1, i32* %8
br label %92
55: ; preds = %49
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, 127
br i1 %57, label %58, label %77
58: ; preds = %55
%59 = load i32, i32* %8
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %76
61: ; preds = %58
%62 = load i32, i32* %8
%63 = add nsw i32 %62, -1
store i32 %63, i32* %8
%64 = load i8*, i8** %5
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8 0, i8* %67
%68 = load i32, i32* %7
%69 = load i32, i32* %8
%70 = add nsw i32 3, %69
%71 = call i32 @mvaddstr(i32 %68, i32 %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%72 = load i32, i32* %7
%73 = load i32, i32* %8
%74 = add nsw i32 3, %73
%75 = call i32 @move(i32 %72, i32 %74)
br label %76
76: ; preds = %61, %58
br label %90
77: ; preds = %55
%78 = load i32, i32* %9
%79 = trunc i32 %78 to i8
%80 = load i8*, i8** %5
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 %79, i8* %83
%84 = load i32, i32* %7
%85 = load i32, i32* %8
%86 = add nsw i32 3, %85
%87 = call i32 @mvaddstr(i32 %84, i32 %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%88 = load i32, i32* %8
%89 = add nsw i32 %88, 1
store i32 %89, i32* %8
br label %90
90: ; preds = %77, %76
%91 = call i32 (...) @refresh()
br label %39
92: ; preds = %52, %48, %39
%93 = load i8*, i8** %5
%94 = load i32, i32* %8
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
store i8 0, i8* %96
%97 = call i32 (...) @refresh()
%98 = call i32 (...) @endwin()
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"=> \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"*\00"
define void @gui_main_get_password(i8** nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 (...) @initscr()
%5 = tail call i32 (...) @cbreak()
%6 = tail call i32 (...) @noecho()
%7 = tail call i32 (...) @raw()
%8 = tail call i32 (...) @clear()
%9 = load i8*, i8** %0
%10 = icmp eq i8* %9, null
br i1 %10, label %22, label %11
11: ; preds = %3, %11
%12 = phi i64 [ %16, %11 ], [ 0, %3 ]
%13 = phi i8* [ %18, %11 ], [ %9, %3 ]
%14 = trunc i64 %12 to i32
%15 = tail call i32 @mvaddstr(i32 %14, i32 0, i8* %13)
%16 = add nuw i64 %12, 1
%17 = getelementptr inbounds i8*, i8** %0, i64 %16
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %11
20: ; preds = %11
%21 = trunc i64 %16 to i32
br label %22
22: ; preds = %20, %3
%23 = phi i32 [ 0, %3 ], [ %21, %20 ]
%24 = tail call i32 @mvaddstr(i32 %23, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 (...) @refresh()
%26 = tail call i32 @memset(i8* %1, i8 signext 0, i32 %2)
%27 = add nsw i32 %2, -1
%28 = icmp sgt i32 %2, 1
br i1 %28, label %29, label %53
29: ; preds = %22, %49
%30 = phi i32 [ %50, %49 ], [ 0, %22 ]
%31 = tail call i32 (...) @getch()
switch i32 %31, label %42 [
i32 10, label %53
i32 3, label %32
i32 127, label %33
]
32: ; preds = %29
store i8 3, i8* %1
br label %53
33: ; preds = %29
%34 = icmp sgt i32 %30, 0
br i1 %34, label %35, label %49
35: ; preds = %33
%36 = add nsw i32 %30, -1
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %1, i64 %37
store i8 0, i8* %38
%39 = add nuw nsw i32 %30, 2
%40 = tail call i32 @mvaddstr(i32 %23, i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%41 = tail call i32 @move(i32 %23, i32 %39)
br label %49
42: ; preds = %29
%43 = trunc i32 %31 to i8
%44 = sext i32 %30 to i64
%45 = getelementptr inbounds i8, i8* %1, i64 %44
store i8 %43, i8* %45
%46 = add nsw i32 %30, 3
%47 = tail call i32 @mvaddstr(i32 %23, i32 %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%48 = add nsw i32 %30, 1
br label %49
49: ; preds = %33, %35, %42
%50 = phi i32 [ %36, %35 ], [ %30, %33 ], [ %48, %42 ]
%51 = tail call i32 (...) @refresh()
%52 = icmp slt i32 %50, %27
br i1 %52, label %29, label %53
53: ; preds = %49, %29, %22, %32
%54 = phi i32 [ 1, %32 ], [ 0, %22 ], [ %50, %49 ], [ %30, %29 ]
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %1, i64 %55
store i8 0, i8* %56
%57 = tail call i32 (...) @refresh()
%58 = tail call i32 (...) @endwin()
ret void
}