#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 */
char *input_line_and_echo_char(unsigned char, char, unsigned char);
int /*<<< orphan*/ memset(char **, char, unsigned char);
int /*<<< orphan*/ terminal_send(char *, int /*<<< orphan*/);
int /*<<< orphan*/ terminal_send_left();
char *prompt_password_line(unsigned char type, unsigned char size,
                           unsigned char echo) {
  char b, r, e, i;
  char prompt[66];
  switch (type) {
  case 0:
    b = 0;
    r = 0;
    e = 0;
    break;
  case 1:
    b = '[';
    r = '_';
    e = ']';
    break;
  case 2:
    b = '>';
    r = '_';
    e = '<';
  }
  memset(&prompt, 0x20, 66);
  memset(&prompt, r, size + 1);
  prompt[0] = b;
  prompt[size + 1] = e;
  prompt[size + 2] = '\0';
  terminal_send(prompt, 0);
  for (i = 0; i < size + 1; ++i) {
    terminal_send_left();
  }
  return input_line_and_echo_char(echo, r, size);
}


x86 assembly (clang, -O0):
<prompt_password_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movzbl -0x1(%rbp),%eax
mov    %eax,-0x54(%rbp)
test   %eax,%eax
je     118f <prompt_password_line+0x4f>
jmp    116d <prompt_password_line+0x2d>
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
je     11a0 <prompt_password_line+0x60>
jmp    117e <prompt_password_line+0x3e>
mov    -0x54(%rbp),%eax
sub    $0x2,%eax
je     11b1 <prompt_password_line+0x71>
jmp    11bd <prompt_password_line+0x7d>
movb   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movb   $0x0,-0x6(%rbp)
jmp    11bd <prompt_password_line+0x7d>
movb   $0x5b,-0x4(%rbp)
movb   $0x5f,-0x5(%rbp)
movb   $0x5d,-0x6(%rbp)
jmp    11bd <prompt_password_line+0x7d>
movb   $0x3e,-0x4(%rbp)
movb   $0x5f,-0x5(%rbp)
movb   $0x3c,-0x6(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x20,%esi
mov    $0x42,%edx
call   1060 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x5(%rbp),%cl
movzbl -0x2(%rbp),%eax
add    $0x1,%eax
movsbl %cl,%esi
movzbl %al,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%al
mov    %al,-0x50(%rbp)
mov    -0x6(%rbp),%cl
movzbl -0x2(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x50(%rbp,%rax,1)
movzbl -0x2(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
call   1040 <terminal_send@plt>
movb   $0x0,-0x7(%rbp)
movsbl -0x7(%rbp),%eax
movzbl -0x2(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1243 <prompt_password_line+0x103>
mov    $0x0,%al
call   1050 <terminal_send_left@plt>
mov    -0x7(%rbp),%al
add    $0x1,%al
mov    %al,-0x7(%rbp)
jmp    121c <prompt_password_line+0xdc>
mov    -0x3(%rbp),%cl
mov    -0x5(%rbp),%al
movzbl %cl,%edi
movsbl %al,%esi
movzbl -0x2(%rbp),%edx
call   1030 <input_line_and_echo_char@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_password_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
cmp    $0x2,%dil
je     116a <prompt_password_line+0x2a>
cmp    $0x1,%dil
jne    1175 <prompt_password_line+0x35>
mov    $0x5d,%r12b
mov    $0x5f,%r15b
mov    $0x5b,%r13b
jmp    117e <prompt_password_line+0x3e>
mov    $0x3c,%r12b
mov    $0x5f,%r15b
mov    $0x3e,%r13b
jmp    117e <prompt_password_line+0x3e>
xor    %r13d,%r13d
xor    %r15d,%r15d
xor    %r12d,%r12d
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x42,%edx
call   1060 <memset@plt>
movzbl %bpl,%ebp
lea    0x1(%rbp),%rax
movzbl %r15b,%r15d
movzbl %al,%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <memset@plt>
mov    %r13b,(%rsp)
mov    %r12b,0x1(%rsp,%rbp,1)
movb   $0x0,0x2(%rbp,%rbx,1)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <terminal_send@plt>
mov    $0x1,%bl
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <terminal_send_left@plt>
movsbl %bl,%eax
lea    0x1(%rax),%ebx
cmp    %eax,%ebp
jge    11d0 <prompt_password_line+0x90>
movzbl %r14b,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <input_line_and_echo_char@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @prompt_password_line(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca [66 x i8]
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
switch i32 %13, label %17 [
i32 0, label %14
i32 1, label %15
i32 2, label %16
]
14: ; preds = %3
store i8 0, i8* %7
store i8 0, i8* %8
store i8 0, i8* %9
br label %17
15: ; preds = %3
store i8 91, i8* %7
store i8 95, i8* %8
store i8 93, i8* %9
br label %17
16: ; preds = %3
store i8 62, i8* %7
store i8 95, i8* %8
store i8 60, i8* %9
br label %17
17: ; preds = %16, %3, %15, %14
%18 = bitcast [66 x i8]* %11 to i8**
%19 = call i32 @memset(i8** %18, i8 signext 32, i8 zeroext 66)
%20 = bitcast [66 x i8]* %11 to i8**
%21 = load i8, i8* %8
%22 = load i8, i8* %5
%23 = zext i8 %22 to i32
%24 = add nsw i32 %23, 1
%25 = trunc i32 %24 to i8
%26 = call i32 @memset(i8** %20, i8 signext %21, i8 zeroext %25)
%27 = load i8, i8* %7
%28 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 0
store i8 %27, i8* %28
%29 = load i8, i8* %9
%30 = load i8, i8* %5
%31 = zext i8 %30 to i32
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 %33
store i8 %29, i8* %34
%35 = load i8, i8* %5
%36 = zext i8 %35 to i32
%37 = add nsw i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 0
%41 = call i32 @terminal_send(i8* %40, i32 0)
store i8 0, i8* %10
br label %42
42: ; preds = %51, %17
%43 = load i8, i8* %10
%44 = sext i8 %43 to i32
%45 = load i8, i8* %5
%46 = zext i8 %45 to i32
%47 = add nsw i32 %46, 1
%48 = icmp slt i32 %44, %47
br i1 %48, label %49, label %54
49: ; preds = %42
%50 = call i32 (...) @terminal_send_left()
br label %51
51: ; preds = %49
%52 = load i8, i8* %10
%53 = add i8 %52, 1
store i8 %53, i8* %10
br label %42
54: ; preds = %42
%55 = load i8, i8* %6
%56 = load i8, i8* %8
%57 = load i8, i8* %5
%58 = call i8* @input_line_and_echo_char(i8 zeroext %55, i8 signext %56, i8 zeroext %57)
ret i8* %58
}

LLVM IR (-O2):
define i8* @prompt_password_line(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca [66 x i8]
%5 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 0
switch i8 %0, label %8 [
i8 2, label %7
i8 1, label %6
]
6: ; preds = %3
br label %8
7: ; preds = %3
br label %8
8: ; preds = %7, %3, %6
%9 = phi i8 [ 62, %7 ], [ 91, %6 ], [ 0, %3 ]
%10 = phi i8 [ 95, %7 ], [ 95, %6 ], [ 0, %3 ]
%11 = phi i8 [ 60, %7 ], [ 93, %6 ], [ 0, %3 ]
%12 = bitcast [66 x i8]* %4 to i8**
%13 = call i32 @memset(i8** %12, i8 signext 32, i8 zeroext 66)
%14 = zext i8 %1 to i32
%15 = add nuw nsw i32 %14, 1
%16 = trunc i32 %15 to i8
%17 = call i32 @memset(i8** %12, i8 signext %10, i8 zeroext %16)
store i8 %9, i8* %5
%18 = zext i32 %15 to i64
%19 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 %18
store i8 %11, i8* %19
%20 = add nuw nsw i32 %14, 2
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @terminal_send(i8* %5, i32 0)
br label %24
24: ; preds = %8, %24
%25 = phi i8 [ 0, %8 ], [ %27, %24 ]
%26 = call i32 (...) @terminal_send_left()
%27 = add i8 %25, 1
%28 = sext i8 %27 to i32
%29 = icmp slt i32 %14, %28
br i1 %29, label %30, label %24
30: ; preds = %24
%31 = call i8* @input_line_and_echo_char(i8 zeroext %2, i8 signext %10, i8 zeroext %1)
ret i8* %31
}