#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 */
scalar_t__ accept(char *);
char getch();
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ slowprint(char *, int);
int passwd(void) {
  char a[20], b;
  int i = 0;
  slowprint("\e[39mLogin Password: ", 20);
  while (((b = getch()) != 13) && (i < 20)) {
    if (b != 127) {
      putchar('*');
      a[i] = b;
      i++;
    } else {
      if (i > 0) {
        i--;
        putchar('\b');
        putchar(' ');
        putchar('\b');
      }
    }
  }
  a[i] = '\0';
  putchar('\n');
  if (accept(a)) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x28(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x14,%esi
call   1050 <slowprint@plt>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0x29(%rbp)
je     1185 <passwd+0x45>
cmpl   $0x14,-0x28(%rbp)
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1195 <passwd+0x55>
jmp    1200 <passwd+0xc0>
movsbl -0x21(%rbp),%eax
cmp    $0x7f,%eax
je     11c5 <passwd+0x85>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    -0x21(%rbp),%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11fb <passwd+0xbb>
cmpl   $0x0,-0x28(%rbp)
jle    11f6 <passwd+0xb6>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    11fb <passwd+0xbb>
jmp    1160 <passwd+0x20>
movslq -0x28(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x20(%rbp),%rdi
call   1060 <accept@plt>
cmp    $0x0,%rax
je     1232 <passwd+0xf2>
movl   $0x1,-0x4(%rbp)
jmp    1239 <passwd+0xf9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passwd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb2(%rip),%rdi
mov    $0x14,%esi
call   1050 <slowprint@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getch@plt>
cmp    $0xd,%al
je     11c8 <passwd+0x88>
mov    %eax,%ebx
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
cmp    $0x7f,%bl
jne    11a0 <passwd+0x60>
test   %r14d,%r14d
jle    11b5 <passwd+0x75>
add    $0xffffffff,%r14d
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    11b5 <passwd+0x75>
xchg   %ax,%ax
mov    $0x2a,%edi
call   1030 <putchar@plt>
movslq %r14d,%r14
mov    %bl,(%rsp,%r14,1)
add    $0x1,%r14d
xor    %eax,%eax
call   1040 <getch@plt>
cmp    $0xd,%al
je     11c8 <passwd+0x88>
mov    %eax,%ebx
cmp    $0x14,%r14d
jl     1170 <passwd+0x30>
movslq %r14d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%rdi
call   1060 <accept@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\1B[39mLogin Password: \00"
define i32 @passwd() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %4
%5 = call i32 @slowprint(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 20)
br label %6
6: ; preds = %37, %0
%7 = call signext i8 (...) @getch()
store i8 %7, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 13
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 20
br label %13
13: ; preds = %10, %6
%14 = phi i1 [ false, %6 ], [ %12, %10 ]
br i1 %14, label %15, label %38
15: ; preds = %13
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 127
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = call i32 @putchar(i8 signext 42)
%21 = load i8, i8* %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %23
store i8 %21, i8* %24
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %37
27: ; preds = %15
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* %4
%32 = add nsw i32 %31, -1
store i32 %32, i32* %4
%33 = call i32 @putchar(i8 signext 8)
%34 = call i32 @putchar(i8 signext 32)
%35 = call i32 @putchar(i8 signext 8)
br label %36
36: ; preds = %30, %27
br label %37
37: ; preds = %36, %19
br label %6
38: ; preds = %13
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @putchar(i8 signext 10)
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%44 = call i64 @accept(i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %38
store i32 1, i32* %1
br label %48
47: ; preds = %38
store i32 0, i32* %1
br label %48
48: ; preds = %47, %46
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [22 x i8] c"\1B[39mLogin Password: \00"
define i32 @passwd() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @slowprint(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 20)
%4 = tail call signext i8 (...) @getch()
%5 = icmp eq i8 %4, 13
br i1 %5, label %28, label %6
6: ; preds = %0, %22
%7 = phi i8 [ %24, %22 ], [ %4, %0 ]
%8 = phi i32 [ %23, %22 ], [ 0, %0 ]
%9 = icmp eq i8 %7, 127
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = tail call i32 @putchar(i8 signext 42)
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %12
store i8 %7, i8* %13
%14 = add nsw i32 %8, 1
br label %22
15: ; preds = %6
%16 = icmp sgt i32 %8, 0
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = add nsw i32 %8, -1
%19 = tail call i32 @putchar(i8 signext 8)
%20 = tail call i32 @putchar(i8 signext 32)
%21 = tail call i32 @putchar(i8 signext 8)
br label %22
22: ; preds = %15, %17, %10
%23 = phi i32 [ %14, %10 ], [ %18, %17 ], [ %8, %15 ]
%24 = tail call signext i8 (...) @getch()
%25 = icmp ne i8 %24, 13
%26 = icmp slt i32 %23, 20
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %6, label %28
28: ; preds = %22, %0
%29 = phi i32 [ 0, %0 ], [ %23, %22 ]
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %30
store i8 0, i8* %31
%32 = tail call i32 @putchar(i8 signext 10)
%33 = call i64 @accept(i8* %2)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i32
ret i32 %35
}