#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 */
typedef int /*<<< orphan*/ X509;

/* Variables and functions */
int /*<<< orphan*/ GEN_EMAIL;
int do_x509_check(int /*<<< orphan*/ *, char const *, size_t, unsigned int,
                  int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ memchr(char const *, char, size_t);
size_t strlen(char const *);
int X509_check_email(X509 *x, const char *chk, size_t chklen,
                     unsigned int flags) {
  if (chk == NULL)
    return -2;
  if (chklen == 0)
    chklen = strlen(chk);
  else if (memchr(chk, '\0', chklen))
    return -2;
  return do_x509_check(x, chk, chklen, flags, GEN_EMAIL, NULL);
}


x86 assembly (clang, -O0):
<X509_check_email>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115e <X509_check_email+0x2e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11cb <X509_check_email+0x9b>
cmpq   $0x0,-0x20(%rbp)
jne    117b <X509_check_email+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
jmp    11a5 <X509_check_email+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1050 <memchr@plt>
cmp    $0x0,%rax
je     11a0 <X509_check_email+0x70>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11cb <X509_check_email+0x9b>
jmp    11a5 <X509_check_email+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    0x2e25(%rip),%rax
mov    (%rax),%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1030 <do_x509_check@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_check_email>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     115f <X509_check_email+0x2f>
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
test   %rdx,%rdx
je     116f <X509_check_email+0x3f>
xor    %esi,%esi
mov    %rbp,%rdx
call   1050 <memchr@plt>
test   %rax,%rax
je     1177 <X509_check_email+0x47>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    0x2e62(%rip),%rax
mov    (%rax),%r8d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
xor    %r9d,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <do_x509_check@plt>

LLVM IR (-O0):
@GEN_EMAIL = global i32 0
define i32 @X509_check_email(i32* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %4
store i32 -2, i32* %5
br label %33
13: ; preds = %4
%14 = load i64, i64* %8
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %8
br label %26
19: ; preds = %13
%20 = load i8*, i8** %7
%21 = load i64, i64* %8
%22 = call i64 @memchr(i8* %20, i8 signext 0, i64 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -2, i32* %5
br label %33
25: ; preds = %19
br label %26
26: ; preds = %25, %16
%27 = load i32*, i32** %6
%28 = load i8*, i8** %7
%29 = load i64, i64* %8
%30 = load i32, i32* %9
%31 = load i32, i32* @GEN_EMAIL
%32 = call i32 @do_x509_check(i32* %27, i8* %28, i64 %29, i32 %30, i32 %31, i32* null)
store i32 %32, i32* %5
br label %33
33: ; preds = %26, %24, %12
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@GEN_EMAIL = global i32 0
define i32 @X509_check_email(i32* %0, i8* %1, i64 %2, i32 %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %17, label %6
6: ; preds = %4
%7 = icmp eq i64 %2, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i64 @strlen(i8* %1)
br label %13
10: ; preds = %6
%11 = tail call i64 @memchr(i8* %1, i8 signext 0, i64 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10, %8
%14 = phi i64 [ %9, %8 ], [ %2, %10 ]
%15 = load i32, i32* @GEN_EMAIL
%16 = tail call i32 @do_x509_check(i32* %0, i8* %1, i64 %14, i32 %3, i32 %15, i32* null)
br label %17
17: ; preds = %10, %4, %13
%18 = phi i32 [ %16, %13 ], [ -2, %4 ], [ -2, %10 ]
ret i32 %18
}