#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 */
typedef int /*<<< orphan*/ username;
typedef int /*<<< orphan*/ readbuff;
typedef int /*<<< orphan*/ password;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ hash_pass(char *, char *);
int /*<<< orphan*/ login();
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncpy(char *, char *, int);
int login_prompt(int pwsize, char *secretpw) {
  char password[32];
  char username[32];
  char readbuff[128];
  int attempts = -3;
  int result = -1;
  while (attempts++) {
    memset(password, 0, sizeof(password));
    memset(username, 0, sizeof(username));
    memset(readbuff, 0, sizeof(readbuff));
    printf("Enter your username: ");
    fgets(readbuff, sizeof(readbuff), stdin);
    strncpy(username, readbuff, sizeof(username));
    printf("Enter your password: ");
    fgets(readbuff, sizeof(readbuff), stdin);
    strncpy(password, readbuff, sizeof(password));
    hash_pass(password, username);
    if (pwsize > 16 && memcmp(password, secretpw, pwsize) == 0) {
      login();
      result = 0;
      break;
    }
    printf("Authentication failed for user %s\n", username);
  }
  return result;
}


x86 assembly (clang, -O0):
<login_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xfffffffd,-0xd4(%rbp)
ff ff ff
movl   $0xffffffff,-0xd8(%rbp)
ff ff ff
mov    -0xd4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xd4(%rbp)
cmp    $0x0,%eax
je     12bb <login_prompt+0x14b>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1070 <fgets@plt>
lea    -0x50(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1070 <fgets@plt>
lea    -0x30(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1090 <hash_pass@plt>
cmpl   $0x10,-0x4(%rbp)
jle    12a4 <login_prompt+0x134>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    12a4 <login_prompt+0x134>
mov    $0x0,%al
call   1080 <login@plt>
movl   $0x0,-0xd8(%rbp)
jmp    12bb <login_prompt+0x14b>
lea    -0x50(%rbp),%rsi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1196 <login_prompt+0x26>
mov    -0xd8(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<login_prompt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e12(%rip),%r13
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1090 <hash_pass@plt>
cmp    $0x11,%r15d
jl     124e <login_prompt+0xde>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     1406 <login_prompt+0x296>
lea    0xdd7(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xd60(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
lea    0xd47(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <hash_pass@plt>
cmp    $0x11,%r15d
jl     131f <login_prompt+0x1af>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     1406 <login_prompt+0x296>
lea    0xd06(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xc8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
lea    0xc76(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <hash_pass@plt>
cmp    $0x11,%r15d
jl     13ec <login_prompt+0x27c>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     1406 <login_prompt+0x296>
lea    0xc39(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    140f <login_prompt+0x29f>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <login@plt>
mov    %ebx,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter your username: \00"
@stdin = global i32 0
@.str.1 = [22 x i8] c"Enter your password: \00"
@.str.2 = [35 x i8] c"Authentication failed for user %s\0A\00"
define i32 @login_prompt(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 -3, i32* %8
store i32 -1, i32* %9
br label %10
10: ; preds = %48, %2
%11 = load i32, i32* %8
%12 = add nsw i32 %11, 1
store i32 %12, i32* %8
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %51
14: ; preds = %10
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 32)
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 32)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 128)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %22, i32 128, i32 %23)
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%27 = call i32 @strncpy(i8* %25, i8* %26, i32 32)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %29, i32 128, i32 %30)
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%34 = call i32 @strncpy(i8* %32, i8* %33, i32 32)
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%37 = call i32 @hash_pass(i8* %35, i8* %36)
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 16
br i1 %39, label %40, label %48
40: ; preds = %14
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%42 = load i8*, i8** %4
%43 = load i32, i32* %3
%44 = call i64 @memcmp(i8* %41, i8* %42, i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = call i32 (...) @login()
store i32 0, i32* %9
br label %51
48: ; preds = %40, %14
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %49)
br label %10
51: ; preds = %46, %10
%52 = load i32, i32* %9
ret i32 %52
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter your username: \00"
@stdin = global i32 0
@.str.1 = [22 x i8] c"Enter your password: \00"
@.str.2 = [35 x i8] c"Authentication failed for user %s\0A\00"
define i32 @login_prompt(i32 %0, i8* %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = icmp sgt i32 %0, 16
%10 = call i32 @memset(i8* %6, i32 0, i32 32)
%11 = call i32 @memset(i8* %7, i32 0, i32 32)
%12 = call i32 @memset(i8* %8, i32 0, i32 128)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %8, i32 128, i32 %14)
%16 = call i32 @strncpy(i8* %7, i8* %8, i32 32)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %8, i32 128, i32 %18)
%20 = call i32 @strncpy(i8* %6, i8* %8, i32 32)
%21 = call i32 @hash_pass(i8* %6, i8* %7)
br i1 %9, label %22, label %27
22: ; preds = %2
%23 = call i64 @memcmp(i8* %6, i8* %1, i32 %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %58, %41, %22
%26 = call i32 (...) @login()
br label %63
27: ; preds = %22, %2
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%29 = call i32 @memset(i8* %6, i32 0, i32 32)
%30 = call i32 @memset(i8* %7, i32 0, i32 32)
%31 = call i32 @memset(i8* %8, i32 0, i32 128)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %8, i32 128, i32 %33)
%35 = call i32 @strncpy(i8* %7, i8* %8, i32 32)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @stdin
%38 = call i32 @fgets(i8* %8, i32 128, i32 %37)
%39 = call i32 @strncpy(i8* %6, i8* %8, i32 32)
%40 = call i32 @hash_pass(i8* %6, i8* %7)
br i1 %9, label %41, label %44
41: ; preds = %27
%42 = call i64 @memcmp(i8* %6, i8* %1, i32 %0)
%43 = icmp eq i64 %42, 0
br i1 %43, label %25, label %44
44: ; preds = %41, %27
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%46 = call i32 @memset(i8* %6, i32 0, i32 32)
%47 = call i32 @memset(i8* %7, i32 0, i32 32)
%48 = call i32 @memset(i8* %8, i32 0, i32 128)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%50 = load i32, i32* @stdin
%51 = call i32 @fgets(i8* %8, i32 128, i32 %50)
%52 = call i32 @strncpy(i8* %7, i8* %8, i32 32)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%54 = load i32, i32* @stdin
%55 = call i32 @fgets(i8* %8, i32 128, i32 %54)
%56 = call i32 @strncpy(i8* %6, i8* %8, i32 32)
%57 = call i32 @hash_pass(i8* %6, i8* %7)
br i1 %9, label %58, label %61
58: ; preds = %44
%59 = call i64 @memcmp(i8* %6, i8* %1, i32 %0)
%60 = icmp eq i64 %59, 0
br i1 %60, label %25, label %61
61: ; preds = %58, %44
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %63
63: ; preds = %61, %25
%64 = phi i32 [ 0, %25 ], [ -1, %61 ]
ret i32 %64
}