#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*/ exit(int);
int /*<<< orphan*/ free(char *);
char *getInput();
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *);
unsigned int strlen(char *);
char *getAmt(void) {
  printf("Amount: ");
  char *amnt = getInput();
  if (amnt == NULL) {
    printf("You have entered an invalid amount.\n");
    exit(16);
  }
  unsigned int len = strlen(amnt);
  unsigned int dot = 0;
  for (unsigned int i = 0; i < len; i++) {
    if (i == 0 && amnt[i] == '$') {
      continue;
    }
    if (amnt[i] == '.' && dot < 1) {
      dot++;
      continue;
    }
    if (i == len - 1 && amnt[i] == '\n') {
      continue;
    }
    if (!isdigit(amnt[i])) {
      printf("You have entered an invalid amount.\n");
      printf("Please use the format $123.45\n");
      free(amnt);
      exit(18);
    }
  }
  return amnt;
}


x86 assembly (clang, -O0):
<getAmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getInput@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a0 <getAmt+0x40>
lea    0xe78(%rip),%rdi
call   1060 <printf@plt>
mov    $0x10,%edi
call   1080 <exit@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
jae    1296 <getAmt+0x136>
cmpl   $0x0,-0x14(%rbp)
jne    11e9 <getAmt+0x89>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
jne    11e9 <getAmt+0x89>
jmp    1288 <getAmt+0x128>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1215 <getAmt+0xb5>
cmpl   $0x1,-0x10(%rbp)
jae    1215 <getAmt+0xb5>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1288 <getAmt+0x128>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    123f <getAmt+0xdf>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    123f <getAmt+0xdf>
jmp    1288 <getAmt+0x128>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    1283 <getAmt+0x123>
lea    0xdaa(%rip),%rdi
call   1060 <printf@plt>
lea    0xdc3(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x12,%edi
call   1080 <exit@plt>
jmp    1288 <getAmt+0x128>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <getAmt+0x5a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAmt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe81(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <getInput@plt>
test   %rax,%rax
je     1252 <getAmt+0xe2>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     11da <getAmt+0x6a>
mov    %eax,%r14d
lea    -0x1(%r14),%r15d
mov    (%r12),%al
xor    %ebp,%ebp
cmp    $0x24,%al
je     11d4 <getAmt+0x64>
cmp    $0x2e,%al
jne    11bf <getAmt+0x4f>
mov    $0x1,%ebp
jmp    11d4 <getAmt+0x64>
test   %r15,%r15
jne    11c8 <getAmt+0x58>
cmp    $0xa,%al
je     11da <getAmt+0x6a>
movsbl %al,%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     1228 <getAmt+0xb8>
cmp    $0x1,%r14d
jne    11e6 <getAmt+0x76>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%r14d
mov    $0x1,%ebx
jmp    1209 <getAmt+0x99>
movsbl %al,%edi
call   1040 <isdigit@plt>
mov    %ebp,%ecx
test   %eax,%eax
je     1228 <getAmt+0xb8>
add    $0x1,%rbx
mov    %ecx,%ebp
cmp    %rbx,%r14
je     11da <getAmt+0x6a>
movzbl (%r12,%rbx,1),%eax
cmp    $0x2e,%al
jne    121b <getAmt+0xab>
mov    $0x1,%ecx
test   %ebp,%ebp
je     11fe <getAmt+0x8e>
cmp    %rbx,%r15
jne    11f0 <getAmt+0x80>
cmp    $0xa,%al
jne    11f0 <getAmt+0x80>
mov    %ebp,%ecx
jmp    11fe <getAmt+0x8e>
lea    0xdf8(%rip),%rdi
call   1050 <puts@plt>
lea    0xdce(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x12,%edi
call   1090 <exit@plt>
lea    0xdce(%rip),%rdi
call   1050 <puts@plt>
mov    $0x10,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Amount: \00"
@.str.1 = [37 x i8] c"You have entered an invalid amount.\0A\00"
@.str.2 = [31 x i8] c"Please use the format $123.45\0A\00"
define i8* @getAmt() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = call i8* (...) @getInput()
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 16)
unreachable
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %15
15: ; preds = %74, %12
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp ult i32 %16, %17
br i1 %18, label %19, label %77
19: ; preds = %15
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i8*, i8** %1
%24 = load i32, i32* %4
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 36
br i1 %29, label %30, label %31
30: ; preds = %22
br label %74
31: ; preds = %22, %19
%32 = load i8*, i8** %1
%33 = load i32, i32* %4
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 46
br i1 %38, label %39, label %45
39: ; preds = %31
%40 = load i32, i32* %3
%41 = icmp ult i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %3
%44 = add i32 %43, 1
store i32 %44, i32* %3
br label %74
45: ; preds = %39, %31
%46 = load i32, i32* %4
%47 = load i32, i32* %2
%48 = sub i32 %47, 1
%49 = icmp eq i32 %46, %48
br i1 %49, label %50, label %59
50: ; preds = %45
%51 = load i8*, i8** %1
%52 = load i32, i32* %4
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 10
br i1 %57, label %58, label %59
58: ; preds = %50
br label %74
59: ; preds = %50, %45
%60 = load i8*, i8** %1
%61 = load i32, i32* %4
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = call i32 @isdigit(i8 signext %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %73, label %67
67: ; preds = %59
%68 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%69 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%70 = load i8*, i8** %1
%71 = call i32 @free(i8* %70)
%72 = call i32 @exit(i32 18)
unreachable
73: ; preds = %59
br label %74
74: ; preds = %73, %58, %42, %30
%75 = load i32, i32* %4
%76 = add i32 %75, 1
store i32 %76, i32* %4
br label %15
77: ; preds = %15
%78 = load i8*, i8** %1
ret i8* %78
}

LLVM IR (-O2):
@.str = [9 x i8] c"Amount: \00"
@str.3 = [30 x i8] c"Please use the format $123.45\00"
@str.4 = [36 x i8] c"You have entered an invalid amount.\00"
define i8* @getAmt() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* (...) @getInput()
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.4, i64 0, i64 0))
%6 = tail call i32 @exit(i32 16)
unreachable
7: ; preds = %0
%8 = tail call i32 @strlen(i8* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %7
%11 = add i32 %8, -1
%12 = zext i32 %11 to i64
%13 = zext i32 %8 to i64
%14 = load i8, i8* %2
switch i8 %14, label %15 [
i8 36, label %23
i8 46, label %22
]
15: ; preds = %10
%16 = icmp eq i32 %11, 0
%17 = icmp eq i8 %14, 10
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %26, label %19
19: ; preds = %15
%20 = tail call i32 @isdigit(i8 signext %14)
%21 = icmp eq i32 %20, 0
br i1 %21, label %42, label %23
22: ; preds = %10
br label %23
23: ; preds = %10, %22, %19
%24 = phi i32 [ 0, %10 ], [ 0, %19 ], [ 1, %22 ]
%25 = icmp eq i32 %8, 1
br i1 %25, label %26, label %27
26: ; preds = %47, %15, %23, %7
ret i8* %2
27: ; preds = %23, %47
%28 = phi i64 [ %49, %47 ], [ 1, %23 ]
%29 = phi i32 [ %48, %47 ], [ %24, %23 ]
%30 = getelementptr inbounds i8, i8* %2, i64 %28
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 46
%33 = icmp eq i32 %29, 0
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %47, label %35
35: ; preds = %27
%36 = icmp eq i64 %28, %12
%37 = icmp eq i8 %31, 10
%38 = select i1 %36, i1 %37, i1 false
br i1 %38, label %47, label %39
39: ; preds = %35
%40 = tail call i32 @isdigit(i8 signext %31)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39, %19
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.4, i64 0, i64 0))
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.3, i64 0, i64 0))
%45 = tail call i32 @free(i8* %2)
%46 = tail call i32 @exit(i32 18)
unreachable
47: ; preds = %35, %27, %39
%48 = phi i32 [ %29, %39 ], [ 1, %27 ], [ %29, %35 ]
%49 = add nuw nsw i64 %28, 1
%50 = icmp eq i64 %49, %13
br i1 %50, label %26, label %27
}