#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 getch();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char password[500];
  char p;
  int i = 0;
  printf("Enter the password:");
  while ((p = getch()) != 13) {
    password[i++] = p;
    printf("*");
  }
  password[i] = '\0';
  if (i < 6)
    printf("\nWeak password");
  printf("\nYou have entered: %s", password);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x208(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0x201(%rbp)
movsbl %al,%eax
cmp    $0xd,%eax
je     1196 <main+0x76>
mov    -0x201(%rbp),%cl
mov    -0x208(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x208(%rbp)
cltq
mov    %cl,-0x200(%rbp,%rax,1)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114a <main+0x2a>
movslq -0x208(%rbp),%rax
movb   $0x0,-0x200(%rbp,%rax,1)
cmpl   $0x6,-0x208(%rbp)
jge    11c0 <main+0xa0>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x200(%rbp),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    $0xd,%al
jne    1157 <main+0x27>
movb   $0x0,(%rsp)
jmp    1187 <main+0x57>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
mov    $0x2a,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    $0xd,%al
jne    1160 <main+0x30>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
cmp    $0x5,%ebx
ja     1195 <main+0x65>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter the password:\00"
@.str.1 = [2 x i8] c"*\00"
@.str.2 = [15 x i8] c"\0AWeak password\00"
@.str.3 = [22 x i8] c"\0AYou have entered: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500 x i8]
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %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 %17
10: ; preds = %6
%11 = load i8, i8* %3
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %14
store i8 %11, i8* %15
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %6
17: ; preds = %6
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 6
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %17
%26 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter the password:\00"
@.str.2 = [15 x i8] c"\0AWeak password\00"
@.str.3 = [22 x i8] c"\0AYou have entered: %s\00"
define i32 @main() {
%1 = alloca [500 x i8]
%2 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getch()
%5 = icmp eq i8 %4, 13
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 0
store i8 0, i8* %7
br label %21
8: ; preds = %0, %8
%9 = phi i64 [ %11, %8 ], [ 0, %0 ]
%10 = phi i8 [ %14, %8 ], [ %4, %0 ]
%11 = add nuw i64 %9, 1
%12 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 %9
store i8 %10, i8* %12
%13 = tail call i32 @putchar(i32 42)
%14 = tail call signext i8 (...) @getch()
%15 = icmp eq i8 %14, 13
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = trunc i64 %11 to i32
%18 = and i64 %11, 4294967295
%19 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 %18
store i8 0, i8* %19
%20 = icmp ult i32 %17, 6
br i1 %20, label %21, label %23
21: ; preds = %6, %16
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %2)
ret i32 0
}