#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*/ fprintf(int /*<<< orphan*/, char *);
char *getpass(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int ask_password(char *result) {
  char *passwd;
  char passwd_copy[9];
  while (1) {
    passwd = getpass("Password: ");
    if (!passwd) {
      fprintf(stderr, "Can't get password: not a tty?\n");
      return 0;
    }
    if (strlen(passwd) < 6) {
      fprintf(stderr, "Password too short\n");
      return 0;
    }
    if (strlen(passwd) > 8) {
      memset(passwd + 8, 0, strlen(passwd) - 8);
      fprintf(stderr, "Warning: password truncated to the length of 8.\n");
    }
    strcpy(passwd_copy, passwd);
    passwd = getpass("Verify:   ");
    if (strlen(passwd) > 8)
      memset(passwd + 8, 0, strlen(passwd) - 8);
    if (strcmp(passwd, passwd_copy) == 0)
      break;
    fprintf(stderr, "Passwords do not match. Please try again.\n\n");
  }
  strcpy(result, passwd);
  memset(passwd, 0, strlen(passwd));
  memset(passwd_copy, 0, strlen(passwd_copy));
  return 1;
}


x86 assembly (clang, -O0):
<ask_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
call   1080 <getpass@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <ask_password+0x48>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1301 <ask_password+0x1a1>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x6,%eax
jge    11db <ask_password+0x7b>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1301 <ask_password+0x1a1>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jle    1227 <ask_password+0xc7>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
sub    $0x8,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x21(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    0xe35(%rip),%rdi
call   1080 <getpass@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jle    127b <ask_password+0x11b>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
sub    $0x8,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x21(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1297 <ask_password+0x137>
jmp    12b1 <ask_password+0x151>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
call   1070 <fprintf@plt>
jmp    116c <ask_password+0xc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    -0x21(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x21(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_password>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,(%rsp)
lea    0xe87(%rip),%rdi
call   1080 <getpass@plt>
test   %rax,%rax
je     125c <ask_password+0xfc>
mov    %rax,%r14
mov    0x2e4f(%rip),%r15
lea    0xf(%rsp),%r13
lea    0xed3(%rip),%r12
nopl   (%rax)
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x5,%eax
jle    126e <ask_password+0x10e>
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jl     11e6 <ask_password+0x86>
lea    0x8(%r14),%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    -0x8(%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    (%r15),%edi
lea    0xe5e(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1080 <getpass@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jl     1225 <ask_password+0xc5>
mov    %rbx,%rbp
add    $0x8,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0x8(%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1281 <ask_password+0x121>
mov    (%r15),%edi
lea    0xe3c(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xdb5(%rip),%rdi
call   1080 <getpass@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11a0 <ask_password+0x40>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
jmp    1278 <ask_password+0x118>
mov    (%r15),%edi
lea    0xdb3(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
jmp    12bf <ask_password+0x15f>
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Password: \00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Can't get password: not a tty?\0A\00"
@.str.2 = [20 x i8] c"Password too short\0A\00"
@.str.3 = [49 x i8] c"Warning: password truncated to the length of 8.\0A\00"
@.str.4 = [11 x i8] c"Verify: \00"
@.str.5 = [44 x i8] c"Passwords do not match. Please try again.\0A\0A\00"
define i32 @ask_password(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [9 x i8]
store i8* %0, i8** %3
br label %6
6: ; preds = %1, %54
%7 = call i8* @getpass(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %69
13: ; preds = %6
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %15, 6
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %69
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 8
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 8
%27 = load i8*, i8** %4
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 8
%30 = call i32 @memset(i8* %26, i32 0, i32 %29)
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %24, %20
%34 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%35 = load i8*, i8** %4
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = call i8* @getpass(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8* %37, i8** %4
%38 = load i8*, i8** %4
%39 = call i32 @strlen(i8* %38)
%40 = icmp sgt i32 %39, 8
br i1 %40, label %41, label %48
41: ; preds = %33
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 8
%44 = load i8*, i8** %4
%45 = call i32 @strlen(i8* %44)
%46 = sub nsw i32 %45, 8
%47 = call i32 @memset(i8* %43, i32 0, i32 %46)
br label %48
48: ; preds = %41, %33
%49 = load i8*, i8** %4
%50 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%51 = call i64 @strcmp(i8* %49, i8* %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48
br label %57
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %6
57: ; preds = %53
%58 = load i8*, i8** %3
%59 = load i8*, i8** %4
%60 = call i32 @strcpy(i8* %58, i8* %59)
%61 = load i8*, i8** %4
%62 = load i8*, i8** %4
%63 = call i32 @strlen(i8* %62)
%64 = call i32 @memset(i8* %61, i32 0, i32 %63)
%65 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%66 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = call i32 @memset(i8* %65, i32 0, i32 %67)
store i32 1, i32* %2
br label %69
69: ; preds = %57, %17, %10
%70 = load i32, i32* %2
ret i32 %70
}

LLVM IR (-O2):
@.str = [11 x i8] c"Password: \00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Can't get password: not a tty?\0A\00"
@.str.2 = [20 x i8] c"Password too short\0A\00"
@.str.3 = [49 x i8] c"Warning: password truncated to the length of 8.\0A\00"
@.str.4 = [11 x i8] c"Verify: \00"
@.str.5 = [44 x i8] c"Passwords do not match. Please try again.\0A\0A\00"
define i32 @ask_password(i8* %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = call i8* @getpass(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %39, %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %50
9: ; preds = %1, %39
%10 = phi i8* [ %42, %39 ], [ %4, %1 ]
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %11, 6
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %50
16: ; preds = %9
%17 = call i32 @strlen(i8* %10)
%18 = icmp sgt i32 %17, 8
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %10, i64 8
%21 = call i32 @strlen(i8* %10)
%22 = add nsw i32 %21, -8
%23 = call i32 @memset(i8* %20, i32 0, i32 %22)
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %19, %16
%27 = call i32 @strcpy(i8* %3, i8* %10)
%28 = call i8* @getpass(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @strlen(i8* %28)
%30 = icmp sgt i32 %29, 8
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = getelementptr inbounds i8, i8* %28, i64 8
%33 = call i32 @strlen(i8* %28)
%34 = add nsw i32 %33, -8
%35 = call i32 @memset(i8* %32, i32 0, i32 %34)
br label %36
36: ; preds = %31, %26
%37 = call i64 @strcmp(i8* %28, i8* %3)
%38 = icmp eq i64 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%42 = call i8* @getpass(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%43 = icmp eq i8* %42, null
br i1 %43, label %6, label %9
44: ; preds = %36
%45 = call i32 @strcpy(i8* %0, i8* %28)
%46 = call i32 @strlen(i8* %28)
%47 = call i32 @memset(i8* %28, i32 0, i32 %46)
%48 = call i32 @strlen(i8* %3)
%49 = call i32 @memset(i8* %3, i32 0, i32 %48)
br label %50
50: ; preds = %44, %13, %6
%51 = phi i32 [ 0, %13 ], [ 1, %44 ], [ 0, %6 ]
ret i32 %51
}