#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*/ isalpha(char);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *);
unsigned int strlen(char *);
char *getEmail(void) {
  printf("Email: ");
  char *email = getInput();
  if (email == NULL) {
    printf("You have entered an invalid email.\n");
    exit(20);
  }
  unsigned int len = strlen(email);
  if (len < 5) {
    printf("You have entered an invalid email.\n");
    printf("Please use the format jon.doe@example.com\n");
    free(email);
    exit(21);
  }
  bool hasAmpersand = false;
  for (unsigned int i = 0; i > len; i++) {
    switch (email[i]) {
    case '@':
      if (hasAmpersand) {
        printf("You have entered an invalid email.\n");
        printf("Please use the format jon.doe@example.com\n");
        free(email);
        exit(21);
      } else {
        hasAmpersand = true;
      }
      continue;
    case '.':
      continue;
    case '\n':
      if (i == len - 1) {
        continue;
      } else {
        printf("You have entered an invalid email.\n");
        printf("Please use the format jon.doe@example.com\n");
        free(email);
        exit(23);
      }
    default:
      if (!isdigit(email[i]) || !isalpha(email[i])) {
        printf("You have entered an invalid email.\n");
        printf("Please use the format jon.doe@example.com\n");
        free(email);
        exit(22);
      }
    }
  }
  return email;
}


x86 assembly (clang, -O0):
<getEmail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getInput@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11b0 <getEmail+0x40>
lea    0xe67(%rip),%rdi
call   1060 <printf@plt>
mov    $0x14,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jae    11f1 <getEmail+0x81>
lea    0xe3b(%rip),%rdi
call   1060 <printf@plt>
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x15,%edi
call   1090 <exit@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jbe    1345 <getEmail+0x1d5>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
sub    $0xa,%eax
je     128f <getEmail+0x11f>
jmp    1227 <getEmail+0xb7>
mov    -0x18(%rbp),%eax
sub    $0x2e,%eax
je     128a <getEmail+0x11a>
jmp    1238 <getEmail+0xc8>
mov    -0x18(%rbp),%eax
sub    $0x40,%eax
jne    12d0 <getEmail+0x160>
jmp    1249 <getEmail+0xd9>
cmpl   $0x0,-0x10(%rbp)
je     127e <getEmail+0x10e>
lea    0xdae(%rip),%rdi
call   1060 <printf@plt>
lea    0xdc6(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x15,%edi
call   1090 <exit@plt>
movl   $0x1,-0x10(%rbp)
jmp    1337 <getEmail+0x1c7>
jmp    1337 <getEmail+0x1c7>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12a5 <getEmail+0x135>
jmp    1337 <getEmail+0x1c7>
lea    0xd5c(%rip),%rdi
call   1060 <printf@plt>
lea    0xd74(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x17,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
je     1302 <getEmail+0x192>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%eax
jne    132d <getEmail+0x1bd>
lea    0xcff(%rip),%rdi
call   1060 <printf@plt>
lea    0xd17(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x16,%edi
call   1090 <exit@plt>
jmp    1332 <getEmail+0x1c2>
jmp    1337 <getEmail+0x1c7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ff <getEmail+0x8f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getEmail>:
push   %rbx
lea    0xe98(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <getInput@plt>
test   %rax,%rax
je     118e <getEmail+0x2e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x4,%eax
jbe    11a4 <getEmail+0x44>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x14,%edi
call   1080 <exit@plt>
lea    0xe87(%rip),%rdi
call   1040 <puts@plt>
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x15,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"Email: \00"
@.str.1 = [36 x i8] c"You have entered an invalid email.\0A\00"
@.str.2 = [43 x i8] c"Please use the format jon.doe@example.com\0A\00"
define i8* @getEmail() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 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 ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 20)
unreachable
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp ult i32 %15, 5
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %1
%21 = call i32 @free(i8* %20)
%22 = call i32 @exit(i32 21)
unreachable
23: ; preds = %12
store i32 0, i32* %3
store i32 0, i32* %4
br label %24
24: ; preds = %83, %23
%25 = load i32, i32* %4
%26 = load i32, i32* %2
%27 = icmp ugt i32 %25, %26
br i1 %27, label %28, label %86
28: ; preds = %24
%29 = load i8*, i8** %1
%30 = load i32, i32* %4
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
switch i32 %34, label %59 [
i32 64, label %35
i32 46, label %46
i32 10, label %47
]
35: ; preds = %28
%36 = load i32, i32* %3
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%41 = load i8*, i8** %1
%42 = call i32 @free(i8* %41)
%43 = call i32 @exit(i32 21)
unreachable
44: ; preds = %35
store i32 1, i32* %3
br label %45
45: ; preds = %44
br label %83
46: ; preds = %28
br label %83
47: ; preds = %28
%48 = load i32, i32* %4
%49 = load i32, i32* %2
%50 = sub i32 %49, 1
%51 = icmp eq i32 %48, %50
br i1 %51, label %52, label %53
52: ; preds = %47
br label %83
53: ; preds = %47
%54 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%55 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%56 = load i8*, i8** %1
%57 = call i32 @free(i8* %56)
%58 = call i32 @exit(i32 23)
unreachable
59: ; preds = %28
%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 %67, label %75
67: ; preds = %59
%68 = load i8*, i8** %1
%69 = load i32, i32* %4
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = call i32 @isalpha(i8 signext %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %81, label %75
75: ; preds = %67, %59
%76 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%77 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%78 = load i8*, i8** %1
%79 = call i32 @free(i8* %78)
%80 = call i32 @exit(i32 22)
unreachable
81: ; preds = %67
br label %82
82: ; preds = %81
br label %83
83: ; preds = %82, %52, %46, %45
%84 = load i32, i32* %4
%85 = add i32 %84, 1
store i32 %85, i32* %4
br label %24
86: ; preds = %24
%87 = load i8*, i8** %1
ret i8* %87
}

LLVM IR (-O2):
@.str = [8 x i8] c"Email: \00"
@str.3 = [42 x i8] c"Please use the format jon.doe@example.com\00"
@str.4 = [35 x i8] c"You have entered an invalid email.\00"
define i8* @getEmail() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 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 ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
%6 = tail call i32 @exit(i32 20)
unreachable
7: ; preds = %0
%8 = tail call i32 @strlen(i8* %2)
%9 = icmp ult i32 %8, 5
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.3, i64 0, i64 0))
%13 = tail call i32 @free(i8* %2)
%14 = tail call i32 @exit(i32 21)
unreachable
15: ; preds = %7
ret i8* %2
}