#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__ isspace(char);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
char tolower(char);
void email_normalize(char *email) {
  bool domain = false;
  while (*email) {
    if (isspace(*email) || (!domain && *email == '.')) {
      memmove(email, email + 1, strlen(email + 1) + 1);
    } else if (!domain && *email == '+') {
      char *p = email;
      while (*p && *p != '@')
        p++;
      memmove(email, p, strlen(p) + 1);
    } else if (*email == '@') {
      domain = true;
      email++;
    } else {
      *email = tolower(*email);
      email++;
    }
  }
}


x86 assembly (clang, -O0):
<email_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     12bb <email_normalize+0x17b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
jne    1190 <email_normalize+0x50>
cmpl   $0x0,-0xc(%rbp)
jne    11ca <email_normalize+0x8a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ca <email_normalize+0x8a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
jmp    12b6 <email_normalize+0x176>
cmpl   $0x0,-0xc(%rbp)
jne    1264 <email_normalize+0x124>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1264 <email_normalize+0x124>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     1211 <email_normalize+0xd1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1221 <email_normalize+0xe1>
jmp    1232 <email_normalize+0xf2>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11ec <email_normalize+0xac>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
jmp    12b1 <email_normalize+0x171>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    128c <email_normalize+0x14c>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    12ac <email_normalize+0x16c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    12b1 <email_normalize+0x171>
jmp    12b6 <email_normalize+0x176>
jmp    1153 <email_normalize+0x13>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<email_normalize>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     11f3 <email_normalize+0xb3>
mov    %rdi,%r14
xor    %ebp,%ebp
jmp    1182 <email_normalize+0x42>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%r14),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
mov    (%r14),%al
test   %al,%al
je     11f3 <email_normalize+0xb3>
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1160 <email_normalize+0x20>
mov    (%r14),%al
test   %ebp,%ebp
je     119c <email_normalize+0x5c>
cmp    $0x40,%al
je     11d7 <email_normalize+0x97>
jmp    11e2 <email_normalize+0xa2>
cmp    $0x40,%al
je     11d7 <email_normalize+0x97>
cmp    $0x2e,%al
je     1160 <email_normalize+0x20>
cmp    $0x2b,%al
jne    11e2 <email_normalize+0xa2>
mov    %r14,%rbx
test   $0xbf,%al
je     11bc <email_normalize+0x7c>
nop
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   $0xbf,%al
jne    11b0 <email_normalize+0x70>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
xor    %ebp,%ebp
jmp    117b <email_normalize+0x3b>
add    $0x1,%r14
mov    $0x1,%ebp
jmp    117b <email_normalize+0x3b>
movsbl %al,%edi
call   1050 <tolower@plt>
mov    %al,(%r14)
add    $0x1,%r14
jmp    117b <email_normalize+0x3b>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @email_normalize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %80, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %81
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = call i64 @isspace(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 46
br i1 %21, label %22, label %31
22: ; preds = %17, %9
%23 = load i8*, i8** %2
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @memmove(i8* %23, i8* %25, i64 %29)
br label %80
31: ; preds = %17, %14
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
br i1 %33, label %63, label %34
34: ; preds = %31
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 43
br i1 %38, label %39, label %63
39: ; preds = %34
%40 = load i8*, i8** %2
store i8* %40, i8** %4
br label %41
41: ; preds = %53, %39
%42 = load i8*, i8** %4
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = load i8*, i8** %4
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 64
br label %51
51: ; preds = %46, %41
%52 = phi i1 [ false, %41 ], [ %50, %46 ]
br i1 %52, label %53, label %56
53: ; preds = %51
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %4
br label %41
56: ; preds = %51
%57 = load i8*, i8** %2
%58 = load i8*, i8** %4
%59 = load i8*, i8** %4
%60 = call i64 @strlen(i8* %59)
%61 = add nsw i64 %60, 1
%62 = call i32 @memmove(i8* %57, i8* %58, i64 %61)
br label %79
63: ; preds = %34, %31
%64 = load i8*, i8** %2
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 64
br i1 %67, label %68, label %71
68: ; preds = %63
store i32 1, i32* %3
%69 = load i8*, i8** %2
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %2
br label %78
71: ; preds = %63
%72 = load i8*, i8** %2
%73 = load i8, i8* %72
%74 = call signext i8 @tolower(i8 signext %73)
%75 = load i8*, i8** %2
store i8 %74, i8* %75
%76 = load i8*, i8** %2
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %2
br label %78
78: ; preds = %71, %68
br label %79
79: ; preds = %78, %56
br label %80
80: ; preds = %79, %22
br label %5
81: ; preds = %5
ret void
}

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