#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__ has_invalid_email_chars(char const *, size_t);
int mem_count_chr(char const *, char, size_t);
scalar_t__ my_memstr(char const *, size_t, char *);
int is_valid_mailbox_mem(const void *name_arg, size_t namelen) {
  const char *name = name_arg;
  return !(!name || !namelen || has_invalid_email_chars(name, namelen) ||
           mem_count_chr(name, '@', namelen) != 1 || *name == '@' ||
           name[namelen - 1] == '@' || name[namelen - 1] == '.' ||
           my_memstr(name, namelen, ".."));
}


x86 assembly (clang, -O0):
<is_valid_mailbox_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x1,%al
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1218 <is_valid_mailbox_mem+0xe8>
mov    $0x1,%al
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     1218 <is_valid_mailbox_mem+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <has_invalid_email_chars@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
jne    1218 <is_valid_mailbox_mem+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40,%esi
call   1040 <mem_count_chr@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x1,%ecx
mov    %al,-0x19(%rbp)
jne    1218 <is_valid_mailbox_mem+0xe8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x40,%ecx
mov    %al,-0x19(%rbp)
je     1218 <is_valid_mailbox_mem+0xe8>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x40,%ecx
mov    %al,-0x19(%rbp)
je     1218 <is_valid_mailbox_mem+0xe8>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x2e,%ecx
mov    %al,-0x19(%rbp)
je     1218 <is_valid_mailbox_mem+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xdf7(%rip),%rdx
call   1030 <my_memstr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_mailbox_mem>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
test   %rdi,%rdi
je     1197 <is_valid_mailbox_mem+0x67>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1197 <is_valid_mailbox_mem+0x67>
mov    %rdi,%rbp
mov    %rbx,%rsi
call   1050 <has_invalid_email_chars@plt>
test   %rax,%rax
jne    1197 <is_valid_mailbox_mem+0x67>
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1040 <mem_count_chr@plt>
cmp    $0x1,%eax
jne    1197 <is_valid_mailbox_mem+0x67>
cmpb   $0x40,0x0(%rbp)
je     1197 <is_valid_mailbox_mem+0x67>
mov    -0x1(%rbx,%rbp,1),%al
cmp    $0x2e,%al
je     1197 <is_valid_mailbox_mem+0x67>
cmp    $0x40,%al
je     1197 <is_valid_mailbox_mem+0x67>
lea    0xe7e(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <my_memstr@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
define i32 @is_valid_mailbox_mem(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %48
9: ; preds = %2
%10 = load i64, i64* %4
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %48
12: ; preds = %9
%13 = load i8*, i8** %5
%14 = load i64, i64* %4
%15 = call i64 @has_invalid_email_chars(i8* %13, i64 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %48, label %17
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i64, i64* %4
%20 = call i32 @mem_count_chr(i8* %18, i8 signext 64, i64 %19)
%21 = icmp ne i32 %20, 1
br i1 %21, label %48, label %22
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 64
br i1 %26, label %48, label %27
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i64, i64* %4
%30 = sub i64 %29, 1
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 64
br i1 %34, label %48, label %35
35: ; preds = %27
%36 = load i8*, i8** %5
%37 = load i64, i64* %4
%38 = sub i64 %37, 1
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 46
br i1 %42, label %48, label %43
43: ; preds = %35
%44 = load i8*, i8** %5
%45 = load i64, i64* %4
%46 = call i64 @my_memstr(i8* %44, i64 %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%47 = icmp ne i64 %46, 0
br label %48
48: ; preds = %43, %35, %27, %22, %17, %12, %9, %2
%49 = phi i1 [ true, %35 ], [ true, %27 ], [ true, %22 ], [ true, %17 ], [ true, %12 ], [ true, %9 ], [ true, %2 ], [ %47, %43 ]
%50 = xor i1 %49, true
%51 = zext i1 %50 to i32
ret i32 %51
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
define i32 @is_valid_mailbox_mem(i8* %0, i64 %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i64 %1, 0
%5 = and i1 %3, %4
br i1 %5, label %6, label %23
6: ; preds = %2
%7 = tail call i64 @has_invalid_email_chars(i8* %0, i64 %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = tail call i32 @mem_count_chr(i8* %0, i8 signext 64, i64 %1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 64
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = add i64 %1, -1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
switch i8 %18, label %19 [
i8 64, label %23
i8 46, label %23
]
19: ; preds = %15
%20 = tail call i64 @my_memstr(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %15, %15, %19, %12, %9, %6, %2
%24 = phi i32 [ 0, %15 ], [ 0, %12 ], [ 0, %9 ], [ 0, %6 ], [ 0, %2 ], [ %22, %19 ], [ 0, %15 ]
ret i32 %24
}