#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 *InputHandler();
int /*<<< orphan*/ checkNullity(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
char *getAmount(void) {
  printf("Enter purchase amount: ");
  char *amount = InputHandler();
  checkNullity(amount);
  int len = strlen(amount);
  unsigned int period = 0;
  for (int i = 0; i < len; i++) {
    if (i == 0 && amount[i] == '$') {
      continue;
    }
    if (i == 0 && amount[i] != '$') {
      printf("Invalid imput: Please start amount with $ \n");
      exit(4);
    }
    if (amount[i] == '.') {
      period++;
      continue;
    }
    if (period > 1) {
      printf("Invalid imput: Please use no more than 1 \".\"\n");
      exit(5);
    }
    if (i == len - 1 && amount[i] == '\n') {
      continue;
    }
    if (!isdigit(amount[i])) {
      if (!(i == len - 1 && amount[i] == '\n')) {
        printf("You have entered invalid input.\n");
        printf("Please enter amount in format $120.00\n");
        free(amount);
        exit(6);
      }
    }
  }
  if (amount[len - 4] != '.') {
    printf("You have entered invalid input.\n");
    printf("Please enter amount in format $120.00\n");
    free(amount);
    exit(6);
  }
  return amount;
}


x86 assembly (clang, -O0):
<getAmount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <InputHandler@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <checkNullity@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1308 <getAmount+0x198>
cmpl   $0x0,-0x14(%rbp)
jne    11e2 <getAmount+0x72>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
jne    11e2 <getAmount+0x72>
jmp    12fa <getAmount+0x18a>
cmpl   $0x0,-0x14(%rbp)
jne    1217 <getAmount+0xa7>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
je     1217 <getAmount+0xa7>
lea    0xe10(%rip),%rdi
call   1060 <printf@plt>
mov    $0x4,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    123a <getAmount+0xca>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12fa <getAmount+0x18a>
cmpl   $0x1,-0x10(%rbp)
jbe    125a <getAmount+0xea>
lea    0xdf9(%rip),%rdi
call   1060 <printf@plt>
mov    $0x5,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1285 <getAmount+0x115>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1285 <getAmount+0x115>
jmp    12fa <getAmount+0x18a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    12f5 <getAmount+0x185>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12c5 <getAmount+0x155>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     12f0 <getAmount+0x180>
lea    0xda6(%rip),%rdi
call   1060 <printf@plt>
lea    0xdbb(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x6,%edi
call   1080 <exit@plt>
jmp    12f5 <getAmount+0x185>
jmp    12fa <getAmount+0x18a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <getAmount+0x42>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     134d <getAmount+0x1dd>
lea    0xd49(%rip),%rdi
call   1060 <printf@plt>
lea    0xd5e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x6,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAmount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe6e(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <InputHandler@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <checkNullity@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    11c9 <getAmount+0x49>
cmpb   $0x24,(%r12)
jne    127b <getAmount+0xfb>
cmp    $0x1,%r14d
jne    11e6 <getAmount+0x66>
movslq %r14d,%rax
cmpb   $0x2e,-0x4(%rax,%r12,1)
jne    123b <getAmount+0xbb>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    -0x1(%r14),%r15d
mov    %r14d,%r13d
xor    %ebp,%ebp
mov    $0x1,%ebx
jmp    120c <getAmount+0x8c>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0x1,%rbx
cmp    %rbx,%r13
je     11c9 <getAmount+0x49>
movzbl (%r12,%rbx,1),%eax
cmp    $0x2e,%al
je     1200 <getAmount+0x80>
cmp    $0x2,%ebp
jae    1265 <getAmount+0xe5>
cmp    %rbx,%r15
jne    1223 <getAmount+0xa3>
cmp    $0xa,%al
je     1203 <getAmount+0x83>
movsbl %al,%edi
call   1040 <isdigit@plt>
test   %eax,%eax
jne    1203 <getAmount+0x83>
cmp    %rbx,%r15
jne    123b <getAmount+0xbb>
cmpb   $0xa,(%r12,%rbx,1)
je     1203 <getAmount+0x83>
lea    0xdd6(%rip),%rdi
call   1050 <puts@plt>
lea    0xdea(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x6,%edi
call   1090 <exit@plt>
lea    0xdf2(%rip),%rdi
call   1050 <puts@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
lea    0xe09(%rip),%rdi
call   1050 <puts@plt>
mov    $0x4,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Enter purchase amount: \00"
@.str.1 = [44 x i8] c"Invalid imput: Please start amount with $ \0A\00"
@.str.2 = [46 x i8] c"Invalid imput: Please use no more than 1 \22.\22\0A\00"
@.str.3 = [33 x i8] c"You have entered invalid input.\0A\00"
@.str.4 = [39 x i8] c"Please enter amount in format $120.00\0A\00"
define i8* @getAmount() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = call i8* (...) @InputHandler()
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = call i32 @checkNullity(i8* %7)
%9 = load i8*, i8** %1
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %11
11: ; preds = %101, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %104
15: ; preds = %11
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i8*, i8** %1
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 36
br i1 %25, label %26, label %27
26: ; preds = %18
br label %101
27: ; preds = %18, %15
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = load i8*, i8** %1
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 36
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 4)
unreachable
41: ; preds = %30, %27
%42 = load i8*, i8** %1
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 46
br i1 %48, label %49, label %52
49: ; preds = %41
%50 = load i32, i32* %3
%51 = add i32 %50, 1
store i32 %51, i32* %3
br label %101
52: ; preds = %41
%53 = load i32, i32* %3
%54 = icmp ugt i32 %53, 1
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @exit(i32 5)
unreachable
58: ; preds = %52
%59 = load i32, i32* %4
%60 = load i32, i32* %2
%61 = sub nsw i32 %60, 1
%62 = icmp eq i32 %59, %61
br i1 %62, label %63, label %72
63: ; preds = %58
%64 = load i8*, i8** %1
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 10
br i1 %70, label %71, label %72
71: ; preds = %63
br label %101
72: ; preds = %63, %58
%73 = load i8*, i8** %1
%74 = load i32, i32* %4
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = call i32 @isdigit(i8 signext %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %100, label %80
80: ; preds = %72
%81 = load i32, i32* %4
%82 = load i32, i32* %2
%83 = sub nsw i32 %82, 1
%84 = icmp eq i32 %81, %83
br i1 %84, label %85, label %93
85: ; preds = %80
%86 = load i8*, i8** %1
%87 = load i32, i32* %4
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 10
br i1 %92, label %99, label %93
93: ; preds = %85, %80
%94 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%95 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%96 = load i8*, i8** %1
%97 = call i32 @free(i8* %96)
%98 = call i32 @exit(i32 6)
unreachable
99: ; preds = %85
br label %100
100: ; preds = %99, %72
br label %101
101: ; preds = %100, %71, %49, %26
%102 = load i32, i32* %4
%103 = add nsw i32 %102, 1
store i32 %103, i32* %4
br label %11
104: ; preds = %11
%105 = load i8*, i8** %1
%106 = load i32, i32* %2
%107 = sub nsw i32 %106, 4
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %105, i64 %108
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp ne i32 %111, 46
br i1 %112, label %113, label %119
113: ; preds = %104
%114 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%115 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%116 = load i8*, i8** %1
%117 = call i32 @free(i8* %116)
%118 = call i32 @exit(i32 6)
unreachable
119: ; preds = %104
%120 = load i8*, i8** %1
ret i8* %120
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter purchase amount: \00"
@str.6 = [32 x i8] c"You have entered invalid input.\00"
@str.7 = [38 x i8] c"Please enter amount in format $120.00\00"
@str.8 = [45 x i8] c"Invalid imput: Please use no more than 1 \22.\22\00"
@str.9 = [43 x i8] c"Invalid imput: Please start amount with $ \00"
define i8* @getAmount() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* (...) @InputHandler()
%3 = tail call i32 @checkNullity(i8* %2)
%4 = tail call i32 @strlen(i8* %2)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %0
%7 = add nsw i32 %4, -1
%8 = zext i32 %7 to i64
%9 = zext i32 %4 to i64
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 36
br i1 %11, label %12, label %20
12: ; preds = %6
%13 = icmp eq i32 %4, 1
br i1 %13, label %14, label %23
14: ; preds = %52, %12, %0
%15 = add nsw i32 %4, -4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 46
br i1 %19, label %61, label %56
20: ; preds = %6
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.9, i64 0, i64 0))
%22 = tail call i32 @exit(i32 4)
unreachable
23: ; preds = %12, %52
%24 = phi i64 [ %54, %52 ], [ 1, %12 ]
%25 = phi i32 [ %53, %52 ], [ 0, %12 ]
%26 = getelementptr inbounds i8, i8* %2, i64 %24
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 46
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = add i32 %25, 1
br label %52
31: ; preds = %23
%32 = icmp ugt i32 %25, 1
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.8, i64 0, i64 0))
%35 = tail call i32 @exit(i32 5)
unreachable
36: ; preds = %31
%37 = icmp eq i64 %24, %8
%38 = icmp eq i8 %27, 10
%39 = select i1 %37, i1 %38, i1 false
br i1 %39, label %52, label %40
40: ; preds = %36
%41 = tail call i32 @isdigit(i8 signext %27)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %40
br i1 %37, label %44, label %47
44: ; preds = %43
%45 = load i8, i8* %26
%46 = icmp eq i8 %45, 10
br i1 %46, label %52, label %47
47: ; preds = %44, %43
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.7, i64 0, i64 0))
%50 = tail call i32 @free(i8* %2)
%51 = tail call i32 @exit(i32 6)
unreachable
52: ; preds = %36, %40, %44, %29
%53 = phi i32 [ %30, %29 ], [ %25, %40 ], [ %25, %44 ], [ %25, %36 ]
%54 = add nuw nsw i64 %24, 1
%55 = icmp eq i64 %54, %9
br i1 %55, label %14, label %23
56: ; preds = %14
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.7, i64 0, i64 0))
%59 = tail call i32 @free(i8* %2)
%60 = tail call i32 @exit(i32 6)
unreachable
61: ; preds = %14
ret i8* %2
}