#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 */
scalar_t__ isalnum(unsigned char);
char const *strchr(char const *, char);
int strlen(char const *);
int cgi_goodemailaddress(const char *addr) {
  int i;
  if (strchr(addr, '@') == NULL)
    return 0;
  if (addr[strlen(addr - 1)] == '@' || addr[strlen(addr - 1)] == '.' ||
      addr[0] == '@' || addr[0] == '.')
    return 0;
  if (strchr(strchr(addr, '@'), '.') == NULL ||
      strchr(strchr(addr, '@') + 1, '@') != NULL)
    return 0;
  for (i = 0; i < strlen(addr); i++) {
    if (isalnum((unsigned char)addr[i]) == 0 && addr[i] != '.' &&
        addr[i] != '@' && addr[i] != '_' && addr[i] != '-')
      return (0);
  }
  return 1;
}


x86 assembly (clang, -O0):
<cgi_goodemailaddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1160 <cgi_goodemailaddress+0x30>
movl   $0x0,-0x4(%rbp)
jmp    12f4 <cgi_goodemailaddress+0x1c4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x40,%eax
je     11d6 <cgi_goodemailaddress+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     11d6 <cgi_goodemailaddress+0xa6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
je     11d6 <cgi_goodemailaddress+0xa6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11e2 <cgi_goodemailaddress+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    12f4 <cgi_goodemailaddress+0x1c4>
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1230 <cgi_goodemailaddress+0x100>
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     123c <cgi_goodemailaddress+0x10c>
movl   $0x0,-0x4(%rbp)
jmp    12f4 <cgi_goodemailaddress+0x1c4>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    12ed <cgi_goodemailaddress+0x1bd>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
jne    12da <cgi_goodemailaddress+0x1aa>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     12da <cgi_goodemailaddress+0x1aa>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x40,%eax
je     12da <cgi_goodemailaddress+0x1aa>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
je     12da <cgi_goodemailaddress+0x1aa>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     12da <cgi_goodemailaddress+0x1aa>
movl   $0x0,-0x4(%rbp)
jmp    12f4 <cgi_goodemailaddress+0x1c4>
jmp    12df <cgi_goodemailaddress+0x1af>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1243 <cgi_goodemailaddress+0x113>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgi_goodemailaddress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x40,%esi
call   1040 <strchr@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     122c <cgi_goodemailaddress+0xfc>
lea    -0x1(%rbx),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x40,(%rbx,%rax,1)
je     122c <cgi_goodemailaddress+0xfc>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2e,(%rbx,%rax,1)
je     122c <cgi_goodemailaddress+0xfc>
mov    (%rbx),%al
cmp    $0x2e,%al
je     122c <cgi_goodemailaddress+0xfc>
cmp    $0x40,%al
je     122c <cgi_goodemailaddress+0xfc>
mov    %rbx,%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     122c <cgi_goodemailaddress+0xfc>
add    $0x1,%r14
mov    %r14,%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    122c <cgi_goodemailaddress+0xfc>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1226 <cgi_goodemailaddress+0xf6>
xor    %ebp,%ebp
movabs $0x4000000080003,%r14
xor    %r15d,%r15d
jmp    1203 <cgi_goodemailaddress+0xd3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1226 <cgi_goodemailaddress+0xf6>
movzbl (%rbx,%rbp,1),%edi
call   1050 <isalnum@plt>
test   %rax,%rax
jne    11f0 <cgi_goodemailaddress+0xc0>
movzbl (%rbx,%rbp,1),%eax
add    $0xd3,%al
cmp    $0x32,%al
ja     122c <cgi_goodemailaddress+0xfc>
movzbl %al,%eax
bt     %rax,%r14
jb     11f0 <cgi_goodemailaddress+0xc0>
jmp    122c <cgi_goodemailaddress+0xfc>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cgi_goodemailaddress(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strchr(i8* %5, i8 signext 64)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %106
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 64
br i1 %18, label %41, label %19
19: ; preds = %9
%20 = load i8*, i8** %3
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 46
br i1 %28, label %41, label %29
29: ; preds = %19
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 64
br i1 %34, label %41, label %35
35: ; preds = %29
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 46
br i1 %40, label %41, label %42
41: ; preds = %35, %29, %19, %9
store i32 0, i32* %2
br label %106
42: ; preds = %35
%43 = load i8*, i8** %3
%44 = call i8* @strchr(i8* %43, i8 signext 64)
%45 = call i8* @strchr(i8* %44, i8 signext 46)
%46 = icmp eq i8* %45, null
br i1 %46, label %53, label %47
47: ; preds = %42
%48 = load i8*, i8** %3
%49 = call i8* @strchr(i8* %48, i8 signext 64)
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = call i8* @strchr(i8* %50, i8 signext 64)
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %54
53: ; preds = %47, %42
store i32 0, i32* %2
br label %106
54: ; preds = %47
store i32 0, i32* %4
br label %55
55: ; preds = %102, %54
%56 = load i32, i32* %4
%57 = load i8*, i8** %3
%58 = call i32 @strlen(i8* %57)
%59 = icmp slt i32 %56, %58
br i1 %59, label %60, label %105
60: ; preds = %55
%61 = load i8*, i8** %3
%62 = load i32, i32* %4
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = call i64 @isalnum(i8 zeroext %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %101
68: ; preds = %60
%69 = load i8*, i8** %3
%70 = load i32, i32* %4
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 46
br i1 %75, label %76, label %101
76: ; preds = %68
%77 = load i8*, i8** %3
%78 = load i32, i32* %4
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp ne i32 %82, 64
br i1 %83, label %84, label %101
84: ; preds = %76
%85 = load i8*, i8** %3
%86 = load i32, i32* %4
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp ne i32 %90, 95
br i1 %91, label %92, label %101
92: ; preds = %84
%93 = load i8*, i8** %3
%94 = load i32, i32* %4
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp ne i32 %98, 45
br i1 %99, label %100, label %101
100: ; preds = %92
store i32 0, i32* %2
br label %106
101: ; preds = %92, %84, %76, %68, %60
br label %102
102: ; preds = %101
%103 = load i32, i32* %4
%104 = add nsw i32 %103, 1
store i32 %104, i32* %4
br label %55
105: ; preds = %55
store i32 1, i32* %2
br label %106
106: ; preds = %105, %100, %53, %41, %8
%107 = load i32, i32* %2
ret i32 %107
}

LLVM IR (-O2):
define i32 @cgi_goodemailaddress(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 64)
%3 = icmp eq i8* %2, null
br i1 %3, label %43, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 -1
%6 = tail call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 64
br i1 %10, label %43, label %11
11: ; preds = %4
%12 = tail call i32 @strlen(i8* %5)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 46
br i1 %16, label %43, label %17
17: ; preds = %11
%18 = load i8, i8* %0
switch i8 %18, label %19 [
i8 64, label %43
i8 46, label %43
]
19: ; preds = %17
%20 = tail call i8* @strchr(i8* %0, i8 signext 64)
%21 = tail call i8* @strchr(i8* dereferenceable(1) %20, i8 signext 46)
%22 = icmp eq i8* %21, null
br i1 %22, label %43, label %23
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %20, i64 1
%25 = tail call i8* @strchr(i8* %24, i8 signext 64)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = tail call i32 @strlen(i8* %0)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %43
30: ; preds = %27, %38
%31 = phi i64 [ %39, %38 ], [ 0, %27 ]
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = load i8, i8* %32
%34 = tail call i64 @isalnum(i8 zeroext %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = load i8, i8* %32
switch i8 %37, label %43 [
i8 46, label %38
i8 64, label %38
i8 95, label %38
i8 45, label %38
]
38: ; preds = %36, %36, %36, %36, %30
%39 = add nuw nsw i64 %31, 1
%40 = tail call i32 @strlen(i8* %0)
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %30, label %43
43: ; preds = %36, %38, %27, %19, %23, %4, %11, %17, %17, %1
%44 = phi i32 [ 0, %1 ], [ 0, %17 ], [ 0, %17 ], [ 0, %11 ], [ 0, %4 ], [ 0, %23 ], [ 0, %19 ], [ 1, %27 ], [ 0, %36 ], [ 1, %38 ]
ret i32 %44
}