#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*/ refresh();
void gui_main_get_password(const char *prompt1, const char *prompt2,
                           const char *prompt3, char *password, int size) {
  int i, ch;
  initscr();
  cbreak();
  noecho();
  clear();
  mvaddstr(0, 0, prompt1);
  mvaddstr(1, 0, prompt2);
  mvaddstr(2, 0, prompt3);
  mvaddstr(3, 0, "=> ");
  refresh();
  memset(password, '\0', size);
  i = 0;
  while (i < size - 1) {
    ch = getch();
    if (ch == '\n')
      break;
    if (ch == 127) {
      if (i > 0) {
        i--;
        password[i] = '\0';
        mvaddstr(3, 3 + i, " ");
        move(3, 3 + i);
      }
    } else {
      password[i] = ch;
      mvaddstr(3, 3 + i, "*");
      i++;
    }
    refresh();
  }
  password[i] = '\0';
  refresh();
  endwin();
}


x86 assembly (clang, -O0):
<gui_main_get_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    $0x0,%al
call   1090 <noecho@plt>
mov    $0x0,%al
call   10b0 <clear@plt>
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
mov    %esi,%edi
call   10a0 <mvaddstr@plt>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   10a0 <mvaddstr@plt>
mov    -0x18(%rbp),%rdx
mov    $0x2,%edi
xor    %esi,%esi
call   10a0 <mvaddstr@plt>
mov    $0x3,%edi
xor    %esi,%esi
lea    0xded(%rip),%rdx
call   10a0 <mvaddstr@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12ef <gui_main_get_password+0x14f>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jne    125e <gui_main_get_password+0xbe>
jmp    12ef <gui_main_get_password+0x14f>
cmpl   $0x7f,-0x2c(%rbp)
jne    12b3 <gui_main_get_password+0x113>
cmpl   $0x0,-0x28(%rbp)
jle    12ae <gui_main_get_password+0x10e>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%esi
add    $0x3,%esi
mov    $0x3,%edi
lea    0xd69(%rip),%rdx
call   10a0 <mvaddstr@plt>
mov    -0x28(%rbp),%esi
add    $0x3,%esi
mov    $0x3,%edi
call   10c0 <move@plt>
jmp    12e3 <gui_main_get_password+0x143>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%esi
add    $0x3,%esi
mov    $0x3,%edi
lea    0xd2f(%rip),%rdx
call   10a0 <mvaddstr@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    1234 <gui_main_get_password+0x94>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1060 <refresh@plt>
mov    $0x0,%al
call   1080 <endwin@plt>
add    $0x30,%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    %r8d,%r15d
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <initscr@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
xor    %eax,%eax
call   1090 <noecho@plt>
xor    %eax,%eax
call   10b0 <clear@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r13,%rdx
call   10a0 <mvaddstr@plt>
mov    $0x1,%edi
xor    %esi,%esi
mov    %r12,%rdx
call   10a0 <mvaddstr@plt>
mov    $0x2,%edi
xor    %esi,%esi
mov    %rbp,%rdx
call   10a0 <mvaddstr@plt>
lea    0xdf7(%rip),%rdx
mov    $0x3,%edi
xor    %esi,%esi
call   10a0 <mvaddstr@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1050 <memset@plt>
cmp    $0x2,%r15d
jl     12be <gui_main_get_password+0x11e>
add    $0xffffffff,%r15d
lea    0xdc4(%rip),%r13
lea    0xdbf(%rip),%r12
xor    %ebx,%ebx
jmp    125c <gui_main_get_password+0xbc>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <refresh@plt>
cmp    %r15d,%ebx
jge    12be <gui_main_get_password+0x11e>
xor    %eax,%eax
call   1070 <getch@plt>
cmp    $0x7f,%eax
je     1290 <gui_main_get_password+0xf0>
cmp    $0xa,%eax
je     12be <gui_main_get_password+0x11e>
movslq %ebx,%rcx
mov    %al,(%r14,%rcx,1)
lea    0x3(%rbx),%esi
mov    $0x3,%edi
mov    %r12,%rdx
call   10a0 <mvaddstr@plt>
add    $0x1,%ebx
jmp    1250 <gui_main_get_password+0xb0>
nopl   0x0(%rax)
test   %ebx,%ebx
jle    1250 <gui_main_get_password+0xb0>
lea    -0x1(%rbx),%ebp
movb   $0x0,(%r14,%rbp,1)
add    $0x2,%ebx
mov    $0x3,%edi
mov    %ebx,%esi
mov    %r13,%rdx
call   10a0 <mvaddstr@plt>
mov    $0x3,%edi
mov    %ebx,%esi
call   10c0 <move@plt>
mov    %ebp,%ebx
jmp    1250 <gui_main_get_password+0xb0>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
xor    %eax,%eax
call   1060 <refresh@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <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, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%13 = call i32 (...) @initscr()
%14 = call i32 (...) @cbreak()
%15 = call i32 (...) @noecho()
%16 = call i32 (...) @clear()
%17 = load i8*, i8** %6
%18 = call i32 @mvaddstr(i32 0, i32 0, i8* %17)
%19 = load i8*, i8** %7
%20 = call i32 @mvaddstr(i32 1, i32 0, i8* %19)
%21 = load i8*, i8** %8
%22 = call i32 @mvaddstr(i32 2, i32 0, i8* %21)
%23 = call i32 @mvaddstr(i32 3, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%24 = call i32 (...) @refresh()
%25 = load i8*, i8** %9
%26 = load i32, i32* %10
%27 = call i32 @memset(i8* %25, i8 signext 0, i32 %26)
store i32 0, i32* %11
br label %28
28: ; preds = %70, %5
%29 = load i32, i32* %11
%30 = load i32, i32* %10
%31 = sub nsw i32 %30, 1
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %72
33: ; preds = %28
%34 = call i32 (...) @getch()
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %38
37: ; preds = %33
br label %72
38: ; preds = %33
%39 = load i32, i32* %12
%40 = icmp eq i32 %39, 127
br i1 %40, label %41, label %58
41: ; preds = %38
%42 = load i32, i32* %11
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %57
44: ; preds = %41
%45 = load i32, i32* %11
%46 = add nsw i32 %45, -1
store i32 %46, i32* %11
%47 = load i8*, i8** %9
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i32, i32* %11
%52 = add nsw i32 3, %51
%53 = call i32 @mvaddstr(i32 3, i32 %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%54 = load i32, i32* %11
%55 = add nsw i32 3, %54
%56 = call i32 @move(i32 3, i32 %55)
br label %57
57: ; preds = %44, %41
br label %70
58: ; preds = %38
%59 = load i32, i32* %12
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %9
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 %60, i8* %64
%65 = load i32, i32* %11
%66 = add nsw i32 3, %65
%67 = call i32 @mvaddstr(i32 3, i32 %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %70
70: ; preds = %58, %57
%71 = call i32 (...) @refresh()
br label %28
72: ; preds = %37, %28
%73 = load i8*, i8** %9
%74 = load i32, i32* %11
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
store i8 0, i8* %76
%77 = call i32 (...) @refresh()
%78 = 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* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = tail call i32 (...) @initscr()
%7 = tail call i32 (...) @cbreak()
%8 = tail call i32 (...) @noecho()
%9 = tail call i32 (...) @clear()
%10 = tail call i32 @mvaddstr(i32 0, i32 0, i8* %0)
%11 = tail call i32 @mvaddstr(i32 1, i32 0, i8* %1)
%12 = tail call i32 @mvaddstr(i32 2, i32 0, i8* %2)
%13 = tail call i32 @mvaddstr(i32 3, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (...) @refresh()
%15 = tail call i32 @memset(i8* %3, i8 signext 0, i32 %4)
%16 = add nsw i32 %4, -1
%17 = icmp sgt i32 %4, 1
br i1 %17, label %18, label %41
18: ; preds = %5, %37
%19 = phi i32 [ %38, %37 ], [ 0, %5 ]
%20 = tail call i32 (...) @getch()
switch i32 %20, label %30 [
i32 10, label %41
i32 127, label %21
]
21: ; preds = %18
%22 = icmp sgt i32 %19, 0
br i1 %22, label %23, label %37
23: ; preds = %21
%24 = add nsw i32 %19, -1
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %3, i64 %25
store i8 0, i8* %26
%27 = add nuw nsw i32 %19, 2
%28 = tail call i32 @mvaddstr(i32 3, i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @move(i32 3, i32 %27)
br label %37
30: ; preds = %18
%31 = trunc i32 %20 to i8
%32 = sext i32 %19 to i64
%33 = getelementptr inbounds i8, i8* %3, i64 %32
store i8 %31, i8* %33
%34 = add nsw i32 %19, 3
%35 = tail call i32 @mvaddstr(i32 3, i32 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = add nsw i32 %19, 1
br label %37
37: ; preds = %21, %23, %30
%38 = phi i32 [ %24, %23 ], [ %19, %21 ], [ %36, %30 ]
%39 = tail call i32 (...) @refresh()
%40 = icmp slt i32 %38, %16
br i1 %40, label %18, label %41
41: ; preds = %37, %18, %5
%42 = phi i32 [ 0, %5 ], [ %19, %18 ], [ %38, %37 ]
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %3, i64 %43
store i8 0, i8* %44
%45 = tail call i32 (...) @refresh()
%46 = tail call i32 (...) @endwin()
ret void
}