#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 */
double calculatePasswordLength(short);
double ceil(double);
short getAMenuInput(int /*<<< orphan*/);
int /*<<< orphan*/ getPasswordLengthMenu();
short getTimeInput();
int /*<<< orphan*/ isValidBounds(short, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ purgeBuffer();
int /*<<< orphan*/ setNumberOfCharacters();
int /*<<< orphan*/ setPasswordAttackRate();
int /*<<< orphan*/ setTimeUnit();
void passwordLengthMenu(void) {
  short input, timeInput;
  double result;
  bool backFlag = false;
  while (!backFlag) {
    input = getAMenuInput(getPasswordLengthMenu());
    while (!isValidBounds(input, 0, 4)) {
      purgeBuffer();
      printf("\nNot a menu option\n");
      input = getAMenuInput(getPasswordLengthMenu());
    }
    switch (input) {
    case 1:
      timeInput = getTimeInput();
      while (0 > timeInput) {
        purgeBuffer();
        printf("\nTime must be positive.\n");
        timeInput = getTimeInput();
      }
      result = calculatePasswordLength(timeInput);
      printf("\nThis is the minimum password length for the time and "
             "attack rate given: %.1f (Rounded up)\n",
             ceil(result));
      break;
    case 2:
      setNumberOfCharacters();
      break;
    case 3:
      setTimeUnit();
      break;
    case 4:
      setPasswordAttackRate();
      break;
    case 0:
      backFlag = true;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<passwordLengthMenu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d5 <passwordLengthMenu+0x25>
jmp    12f8 <passwordLengthMenu+0x148>
mov    $0x0,%al
call   1030 <getPasswordLengthMenu@plt>
mov    %eax,%edi
call   1070 <getAMenuInput@plt>
mov    %ax,-0x2(%rbp)
xor    %esi,%esi
mov    $0x4,%edx
movswl -0x2(%rbp),%edi
call   10b0 <isValidBounds@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    120c <passwordLengthMenu+0x5c>
jmp    1238 <passwordLengthMenu+0x88>
mov    $0x0,%al
call   1080 <purgeBuffer@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <getPasswordLengthMenu@plt>
mov    %eax,%edi
call   1070 <getAMenuInput@plt>
mov    %ax,-0x2(%rbp)
jmp    11e7 <passwordLengthMenu+0x37>
movswl -0x2(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     12f3 <passwordLengthMenu+0x143>
mov    -0x20(%rbp),%rax
lea    0xdaa(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   10c0 <getTimeInput@plt>
mov    %ax,-0x4(%rbp)
movswl -0x4(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jle    129d <passwordLengthMenu+0xed>
mov    $0x0,%al
call   1080 <purgeBuffer@plt>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10c0 <getTimeInput@plt>
mov    %ax,-0x4(%rbp)
jmp    126a <passwordLengthMenu+0xba>
movswl -0x4(%rbp),%edi
call   1090 <calculatePasswordLength@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <ceil@plt>
lea    0xd85(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12f3 <passwordLengthMenu+0x143>
mov    $0x0,%al
call   10d0 <setNumberOfCharacters@plt>
jmp    12f3 <passwordLengthMenu+0x143>
mov    $0x0,%al
call   1060 <setTimeUnit@plt>
jmp    12f3 <passwordLengthMenu+0x143>
mov    $0x0,%al
call   10a0 <setPasswordAttackRate@plt>
jmp    12f3 <passwordLengthMenu+0x143>
movl   $0x1,-0x14(%rbp)
jmp    11bf <passwordLengthMenu+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passwordLengthMenu>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xeb9(%rip),%rbx
lea    0xe2a(%rip),%r12
lea    0xe93(%rip),%r14
lea    0xe30(%rip),%r15
jmp    11ff <passwordLengthMenu+0x3f>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <purgeBuffer@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getPasswordLengthMenu@plt>
mov    %eax,%edi
call   1080 <getAMenuInput@plt>
mov    %eax,%ebp
movswl %ax,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   10c0 <isValidBounds@plt>
test   %eax,%eax
je     11f0 <passwordLengthMenu+0x30>
movswl %bp,%eax
cmp    $0x4,%eax
ja     11ff <passwordLengthMenu+0x3f>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10d0 <getTimeInput@plt>
test   %ax,%ax
jns    1278 <passwordLengthMenu+0xb8>
xor    %eax,%eax
call   1090 <purgeBuffer@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1240 <passwordLengthMenu+0x80>
xor    %eax,%eax
call   10e0 <setNumberOfCharacters@plt>
jmp    11ff <passwordLengthMenu+0x3f>
xor    %eax,%eax
call   1070 <setTimeUnit@plt>
jmp    11ff <passwordLengthMenu+0x3f>
xor    %eax,%eax
call   10b0 <setPasswordAttackRate@plt>
jmp    11ff <passwordLengthMenu+0x3f>
movswl %ax,%edi
call   10a0 <calculatePasswordLength@plt>
call   1050 <ceil@plt>
mov    %r15,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
jmp    11ff <passwordLengthMenu+0x3f>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"\0ANot a menu option\0A\00"
@.str.1 = [25 x i8] c"\0ATime must be positive.\0A\00"
@.str.2 = [92 x i8] c"\0AThis is the minimum password length for the time and attack rate given: %.1f (Rounded up)\0A\00"
define void @passwordLengthMenu() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca double
%4 = alloca i32
store i32 0, i32* %4
br label %5
5: ; preds = %48, %0
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
%8 = xor i1 %7, true
br i1 %8, label %9, label %49
9: ; preds = %5
%10 = call i32 (...) @getPasswordLengthMenu()
%11 = call signext i16 @getAMenuInput(i32 %10)
store i16 %11, i16* %1
br label %12
12: ; preds = %17, %9
%13 = load i16, i16* %1
%14 = call i32 @isValidBounds(i16 signext %13, i32 0, i32 4)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = call i32 (...) @purgeBuffer()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%20 = call i32 (...) @getPasswordLengthMenu()
%21 = call signext i16 @getAMenuInput(i32 %20)
store i16 %21, i16* %1
br label %12
22: ; preds = %12
%23 = load i16, i16* %1
%24 = sext i16 %23 to i32
switch i32 %24, label %48 [
i32 1, label %25
i32 2, label %41
i32 3, label %43
i32 4, label %45
i32 0, label %47
]
25: ; preds = %22
%26 = call signext i16 (...) @getTimeInput()
store i16 %26, i16* %2
br label %27
27: ; preds = %31, %25
%28 = load i16, i16* %2
%29 = sext i16 %28 to i32
%30 = icmp sgt i32 0, %29
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = call i32 (...) @purgeBuffer()
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%34 = call signext i16 (...) @getTimeInput()
store i16 %34, i16* %2
br label %27
35: ; preds = %27
%36 = load i16, i16* %2
%37 = call double @calculatePasswordLength(i16 signext %36)
store double %37, double* %3
%38 = load double, double* %3
%39 = call double @llvm.ceil.f64(double %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.2, i64 0, i64 0), double %39)
br label %48
41: ; preds = %22
%42 = call i32 (...) @setNumberOfCharacters()
br label %48
43: ; preds = %22
%44 = call i32 (...) @setTimeUnit()
br label %48
45: ; preds = %22
%46 = call i32 (...) @setPasswordAttackRate()
br label %48
47: ; preds = %22
store i32 1, i32* %4
br label %48
48: ; preds = %22, %47, %45, %43, %41, %35
br label %5
49: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str.2 = [92 x i8] c"\0AThis is the minimum password length for the time and attack rate given: %.1f (Rounded up)\0A\00"
@str = [24 x i8] c"\0ATime must be positive.\00"
@str.3 = [19 x i8] c"\0ANot a menu option\00"
define void @passwordLengthMenu() {
br label %1
1: ; preds = %16, %0
%2 = tail call i32 (...) @getPasswordLengthMenu()
%3 = tail call signext i16 @getAMenuInput(i32 %2)
%4 = tail call i32 @isValidBounds(i16 signext %3, i32 0, i32 4)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %1, %6
%7 = tail call i32 (...) @purgeBuffer()
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
%9 = tail call i32 (...) @getPasswordLengthMenu()
%10 = tail call signext i16 @getAMenuInput(i32 %9)
%11 = tail call i32 @isValidBounds(i16 signext %10, i32 0, i32 4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %6, %1
%14 = phi i16 [ %3, %1 ], [ %10, %6 ]
%15 = sext i16 %14 to i32
switch i32 %15, label %16 [
i32 1, label %17
i32 2, label %30
i32 3, label %32
i32 4, label %34
i32 0, label %36
]
16: ; preds = %13, %34, %32, %30, %25
br label %1
17: ; preds = %13
%18 = tail call signext i16 (...) @getTimeInput()
%19 = icmp slt i16 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17, %20
%21 = tail call i32 (...) @purgeBuffer()
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%23 = tail call signext i16 (...) @getTimeInput()
%24 = icmp slt i16 %23, 0
br i1 %24, label %20, label %25
25: ; preds = %20, %17
%26 = phi i16 [ %18, %17 ], [ %23, %20 ]
%27 = tail call double @calculatePasswordLength(i16 signext %26)
%28 = tail call double @llvm.ceil.f64(double %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([92 x i8], [92 x i8]* @.str.2, i64 0, i64 0), double %28)
br label %16
30: ; preds = %13
%31 = tail call i32 (...) @setNumberOfCharacters()
br label %16
32: ; preds = %13
%33 = tail call i32 (...) @setTimeUnit()
br label %16
34: ; preds = %13
%35 = tail call i32 (...) @setPasswordAttackRate()
br label %16
36: ; preds = %13
ret void
}