#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 *getZip(void) {
  printf("Enter a valid zip code: ");
  char *zip = InputHandler();
  checkNullity(zip);
  int len = strlen(zip);
  int numHyph = 0;
  if (len != 11) {
    if (len != 6) {
      printf("Invalid zip length\n");
      free(zip);
      exit(20);
    }
  }
  for (int i = 0; i < len; i++) {
    if (len != 6 && zip[i] == '-') {
      numHyph++;
      continue;
    }
    if (numHyph > 1) {
      printf("Invalid Input: only 1 hyphen '-' allowed in Zip Code\n");
      printf("Enter a Zip Code in format \"12345\" or \"12345-6789\"\n");
      free(zip);
      exit(21);
    }
    if (i == len - 1 && zip[i] == '\n') {
      continue;
    }
    if (!isdigit(zip[i])) {
      printf("Invalid Input: Numbers only in Zip Code. \n");
      printf("Enter a Zip Code in format \"12345\" or \"12345-6789\"\n");
      free(zip);
      exit(22);
    }
  }
  if ((len == 11) && zip[5] != '-') {
    printf("Invalid Input: 10 digit Zip Code missing '-' \n");
    printf("Enter a Zip Code in format \"12345\" or \"12345-6789\"\n");
    free(zip);
    exit(23);
  }
  return zip;
}


x86 assembly (clang, -O0):
<getZip>:
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)
cmpl   $0xb,-0xc(%rbp)
je     11e3 <getZip+0x73>
cmpl   $0x6,-0xc(%rbp)
je     11de <getZip+0x6e>
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x14,%edi
call   1080 <exit@plt>
jmp    11e3 <getZip+0x73>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12db <getZip+0x16b>
cmpl   $0x6,-0xc(%rbp)
je     1223 <getZip+0xb3>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    1223 <getZip+0xb3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12cd <getZip+0x15d>
cmpl   $0x1,-0x10(%rbp)
jle    1258 <getZip+0xe8>
lea    0xdf9(%rip),%rdi
call   1060 <printf@plt>
lea    0xe23(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x15,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1283 <getZip+0x113>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1283 <getZip+0x113>
jmp    12cd <getZip+0x15d>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    12c8 <getZip+0x158>
lea    0xdf3(%rip),%rdi
call   1060 <printf@plt>
lea    0xdb3(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x16,%edi
call   1080 <exit@plt>
jmp    12cd <getZip+0x15d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <getZip+0x7a>
cmpl   $0xb,-0xc(%rbp)
jne    1321 <getZip+0x1b1>
mov    -0x8(%rbp),%rax
movsbl 0x5(%rax),%eax
cmp    $0x2d,%eax
je     1321 <getZip+0x1b1>
lea    0xdc5(%rip),%rdi
call   1060 <printf@plt>
lea    0xd5a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x17,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getZip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe6e(%rip),%rdi
call   1070 <printf@plt>
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <InputHandler@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <checkNullity@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
cmp    $0x6,%eax
je     11c6 <getZip+0x46>
cmp    $0xb,%r12d
jne    129b <getZip+0x11b>
lea    -0x1(%r12),%ebx
mov    %r12d,%r13d
xor    %ebp,%ebp
jmp    11fb <getZip+0x7b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14,%rbp,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     1271 <getZip+0xf1>
add    $0x1,%rbp
cmp    %rbp,%r13
je     1224 <getZip+0xa4>
cmp    $0x6,%r12d
je     1210 <getZip+0x90>
cmpb   $0x2d,(%r14,%rbp,1)
jne    1210 <getZip+0x90>
add    $0x1,%r15d
jmp    11f2 <getZip+0x72>
xchg   %ax,%ax
cmp    $0x2,%r15d
jge    1247 <getZip+0xc7>
cmp    %rbp,%rbx
jne    11e0 <getZip+0x60>
cmpb   $0xa,(%r14,%rbx,1)
jne    11e0 <getZip+0x60>
jmp    11f2 <getZip+0x72>
cmp    $0xb,%r12d
jne    1235 <getZip+0xb5>
cmpb   $0x2d,0x5(%r14)
jne    12b9 <getZip+0x139>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe23(%rip),%rdi
call   1050 <puts@plt>
lea    0xe4c(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x15,%edi
call   1090 <exit@plt>
lea    0xdcf(%rip),%rdi
call   1050 <puts@plt>
lea    0xe22(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x16,%edi
call   1090 <exit@plt>
lea    0xe37(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x14,%edi
call   1090 <exit@plt>
lea    0xd59(%rip),%rdi
call   1050 <puts@plt>
lea    0xdda(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x17,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Enter a valid zip code: \00"
@.str.1 = [20 x i8] c"Invalid zip length\0A\00"
@.str.2 = [54 x i8] c"Invalid Input: only 1 hyphen '-' allowed in Zip Code\0A\00"
@.str.3 = [52 x i8] c"Enter a Zip Code in format \2212345\22 or \2212345-6789\22\0A\00"
@.str.4 = [43 x i8] c"Invalid Input: Numbers only in Zip Code. \0A\00"
@.str.5 = [47 x i8] c"Invalid Input: 10 digit Zip Code missing '-' \0A\00"
define i8* @getZip() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 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
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 11
br i1 %12, label %13, label %22
13: ; preds = %0
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 6
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8*, i8** %1
%19 = call i32 @free(i8* %18)
%20 = call i32 @exit(i32 20)
unreachable
21: ; preds = %13
br label %22
22: ; preds = %21, %0
store i32 0, i32* %4
br label %23
23: ; preds = %79, %22
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %82
27: ; preds = %23
%28 = load i32, i32* %2
%29 = icmp ne i32 %28, 6
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 eq i32 %36, 45
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %79
41: ; preds = %30, %27
%42 = load i32, i32* %3
%43 = icmp sgt i32 %42, 1
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
%47 = load i8*, i8** %1
%48 = call i32 @free(i8* %47)
%49 = call i32 @exit(i32 21)
unreachable
50: ; preds = %41
%51 = load i32, i32* %4
%52 = load i32, i32* %2
%53 = sub nsw i32 %52, 1
%54 = icmp eq i32 %51, %53
br i1 %54, label %55, label %64
55: ; preds = %50
%56 = load i8*, i8** %1
%57 = load i32, i32* %4
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 10
br i1 %62, label %63, label %64
63: ; preds = %55
br label %79
64: ; preds = %55, %50
%65 = load i8*, i8** %1
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = call i32 @isdigit(i8 signext %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %78, label %72
72: ; preds = %64
%73 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%74 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
%75 = load i8*, i8** %1
%76 = call i32 @free(i8* %75)
%77 = call i32 @exit(i32 22)
unreachable
78: ; preds = %64
br label %79
79: ; preds = %78, %63, %38
%80 = load i32, i32* %4
%81 = add nsw i32 %80, 1
store i32 %81, i32* %4
br label %23
82: ; preds = %23
%83 = load i32, i32* %2
%84 = icmp eq i32 %83, 11
br i1 %84, label %85, label %97
85: ; preds = %82
%86 = load i8*, i8** %1
%87 = getelementptr inbounds i8, i8* %86, i64 5
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = icmp ne i32 %89, 45
br i1 %90, label %91, label %97
91: ; preds = %85
%92 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%93 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
%94 = load i8*, i8** %1
%95 = call i32 @free(i8* %94)
%96 = call i32 @exit(i32 23)
unreachable
97: ; preds = %85, %82
%98 = load i8*, i8** %1
ret i8* %98
}

LLVM IR (-O2):
@.str = [25 x i8] c"Enter a valid zip code: \00"
@str = [46 x i8] c"Invalid Input: 10 digit Zip Code missing '-' \00"
@str.7 = [42 x i8] c"Invalid Input: Numbers only in Zip Code. \00"
@str.9 = [53 x i8] c"Invalid Input: only 1 hyphen '-' allowed in Zip Code\00"
@str.10 = [51 x i8] c"Enter a Zip Code in format \2212345\22 or \2212345-6789\22\00"
@str.11 = [19 x i8] c"Invalid zip length\00"
define i8* @getZip() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 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 eq i32 %4, 6
switch i32 %4, label %6 [
i32 11, label %10
i32 6, label %10
]
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 @free(i8* %2)
%9 = tail call i32 @exit(i32 20)
unreachable
10: ; preds = %0, %0
%11 = add nsw i32 %4, -1
%12 = zext i32 %11 to i64
%13 = zext i32 %4 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %12
br label %17
15: ; preds = %48
%16 = icmp eq i32 %4, 11
br i1 %16, label %52, label %61
17: ; preds = %10, %48
%18 = phi i64 [ 0, %10 ], [ %50, %48 ]
%19 = phi i32 [ 0, %10 ], [ %49, %48 ]
br i1 %5, label %26, label %20
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %2, i64 %18
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 45
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = add nsw i32 %19, 1
br label %48
26: ; preds = %20, %17
%27 = icmp sgt i32 %19, 1
br i1 %27, label %28, label %33
28: ; preds = %26
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.9, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.10, i64 0, i64 0))
%31 = tail call i32 @free(i8* %2)
%32 = tail call i32 @exit(i32 21)
unreachable
33: ; preds = %26
%34 = icmp eq i64 %18, %12
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i8, i8* %14
%37 = icmp eq i8 %36, 10
br i1 %37, label %48, label %38
38: ; preds = %35, %33
%39 = getelementptr inbounds i8, i8* %2, i64 %18
%40 = load i8, i8* %39
%41 = tail call i32 @isdigit(i8 signext %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.7, i64 0, i64 0))
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.10, i64 0, i64 0))
%46 = tail call i32 @free(i8* %2)
%47 = tail call i32 @exit(i32 22)
unreachable
48: ; preds = %38, %35, %24
%49 = phi i32 [ %25, %24 ], [ %19, %35 ], [ %19, %38 ]
%50 = add nuw nsw i64 %18, 1
%51 = icmp eq i64 %50, %13
br i1 %51, label %15, label %17
52: ; preds = %15
%53 = getelementptr inbounds i8, i8* %2, i64 5
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 45
br i1 %55, label %61, label %56
56: ; preds = %52
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.10, i64 0, i64 0))
%59 = tail call i32 @free(i8* %2)
%60 = tail call i32 @exit(i32 23)
unreachable
61: ; preds = %52, %15
ret i8* %2
}