#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 *getCC(void) {
  printf("Credit Card: ");
  char *cc = getInput();
  if (cc == NULL) {
    printf("You have entered an invalid credit card number.\n");
    exit(3);
  }
  unsigned int len = strlen(cc);
  if (len != 20) {
    printf("Your credit card information is an invalid length\n");
    printf("Please enter in the format: 1234-1234-1234-1234\n");
    free(cc);
    exit(4);
  }
  for (unsigned int i = 0; i < len; i++) {
    if (i == 4 || i == 9 || i == 14) {
      if (cc[i] != '-') {
        printf("Your credit card information is an invalid format\n");
        printf("Please enter in the format: 1234-1234-1234-1234\n");
        free(cc);
        exit(5);
      }
    } else {
      if (!isdigit(cc[i])) {
        if (!(i == len - 1 && cc[i] == '\n')) {
          printf("Your credit card information is an invalid format\n");
          printf("Please enter in the format: 1234-1234-1234-1234\n");
          free(cc);
          exit(6);
        }
      }
    }
  }
  return cc;
}


x86 assembly (clang, -O0):
<getCC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%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 <getCC+0x40>
lea    0xe7d(%rip),%rdi
call   1060 <printf@plt>
mov    $0x3,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
je     11e1 <getCC+0x81>
lea    0xe82(%rip),%rdi
call   1060 <printf@plt>
lea    0xea9(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   1080 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    12dc <getCC+0x17c>
cmpl   $0x4,-0x10(%rbp)
je     1212 <getCC+0xb2>
cmpl   $0x9,-0x10(%rbp)
je     1212 <getCC+0xb2>
cmpl   $0xe,-0x10(%rbp)
jne    1256 <getCC+0xf6>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     1251 <getCC+0xf1>
lea    0xe76(%rip),%rdi
call   1060 <printf@plt>
lea    0xe39(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x5,%edi
call   1080 <exit@plt>
jmp    12c9 <getCC+0x169>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    12c4 <getCC+0x164>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1294 <getCC+0x134>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     12bf <getCC+0x15f>
lea    0xe08(%rip),%rdi
call   1060 <printf@plt>
lea    0xdcb(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x6,%edi
call   1080 <exit@plt>
jmp    12c4 <getCC+0x164>
jmp    12c9 <getCC+0x169>
jmp    12ce <getCC+0x16e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e8 <getCC+0x88>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCC>:
push   %rbp
push   %r14
push   %rbx
lea    0xe85(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <getInput@plt>
test   %rax,%rax
je     1218 <getCC+0xa8>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <strlen@plt>
cmp    $0x14,%eax
jne    122e <getCC+0xbe>
xor    %ebx,%ebx
mov    $0x4210,%ebp
jmp    11c8 <getCC+0x58>
nopl   (%rax)
movsbl (%r14,%rbx,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     1203 <getCC+0x93>
add    $0x1,%rbx
cmp    $0x14,%rbx
je     1210 <getCC+0xa0>
cmp    $0xe,%ebx
ja     11b0 <getCC+0x40>
bt     %ebx,%ebp
jae    11b0 <getCC+0x40>
cmpb   $0x2d,(%r14,%rbx,1)
je     11be <getCC+0x4e>
lea    0xe2e(%rip),%rdi
call   1050 <puts@plt>
lea    0xe86(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
cmp    $0x13,%rbx
jne    1258 <getCC+0xe8>
cmpb   $0xa,(%r14,%rbx,1)
jne    1258 <getCC+0xe8>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe83(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
lea    0xe0b(%rip),%rdi
call   1050 <puts@plt>
lea    0xe31(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
lea    0xdaf(%rip),%rdi
call   1050 <puts@plt>
lea    0xe07(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x6,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@.str = [14 x i8] c"Credit Card: \00"
@str.6 = [50 x i8] c"Your credit card information is an invalid format\00"
@str.8 = [50 x i8] c"Your credit card information is an invalid length\00"
@str.9 = [48 x i8] c"Please enter in the format: 1234-1234-1234-1234\00"
@str.10 = [48 x i8] c"You have entered an invalid credit card number.\00"
define i8* @getCC() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 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 ([48 x i8], [48 x i8]* @str.10, i64 0, i64 0))
%6 = tail call i32 @exit(i32 3)
unreachable
7: ; preds = %0
%8 = tail call i32 @strlen(i8* %2)
%9 = icmp eq i32 %8, 20
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.8, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%13 = tail call i32 @free(i8* %2)
%14 = tail call i32 @exit(i32 4)
unreachable
15: ; preds = %44, %35
ret i8* %2
16: ; preds = %7, %44
%17 = phi i64 [ %45, %44 ], [ 0, %7 ]
%18 = trunc i64 %17 to i32
switch i32 %18, label %28 [
i32 14, label %19
i32 9, label %19
i32 4, label %19
]
19: ; preds = %16, %16, %16
%20 = getelementptr inbounds i8, i8* %2, i64 %17
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 45
br i1 %22, label %44, label %23
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.6, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%26 = tail call i32 @free(i8* %2)
%27 = tail call i32 @exit(i32 5)
unreachable
28: ; preds = %16
%29 = getelementptr inbounds i8, i8* %2, i64 %17
%30 = load i8, i8* %29
%31 = tail call i32 @isdigit(i8 signext %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %28
%34 = icmp eq i64 %17, 19
br i1 %34, label %35, label %39
35: ; preds = %33
%36 = getelementptr inbounds i8, i8* %2, i64 %17
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 10
br i1 %38, label %15, label %39
39: ; preds = %35, %33
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.6, i64 0, i64 0))
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%42 = tail call i32 @free(i8* %2)
%43 = tail call i32 @exit(i32 6)
unreachable
44: ; preds = %19, %28
%45 = add nuw nsw i64 %17, 1
%46 = icmp eq i64 %45, 20
br i1 %46, label %15, label %16
}