#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*/ enough_mem(char *);
char *malloc(int);
char *strchr(char const *, char);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *extract_username(const char *s) {
  const char *p;
  char *r;
  if (*s == '"') {
    p = strchr(s + 1, '"');
    if (!p) {
      return 0;
    }
  } else {
    p = strchr(s, '@');
    if (!p) {
      p = strchr(s, ',');
    }
    if (!p) {
      p = s + strlen(s);
    }
  }
  r = malloc(p - s + 1);
  enough_mem(r);
  strncpy(r, s, p - s);
  r[p - s] = '\0';
  return r;
}


x86 assembly (clang, -O0):
<extract_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    119f <extract_username+0x4f>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <extract_username+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    1257 <extract_username+0x107>
jmp    11ff <extract_username+0xaf>
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ce <extract_username+0x7e>
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fa <extract_username+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11ff <extract_username+0xaf>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <enough_mem@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_username>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
cmpb   $0x22,(%rdi)
jne    1177 <extract_username+0x27>
lea    0x1(%r14),%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11af <extract_username+0x5f>
xor    %ebx,%ebx
jmp    11d9 <extract_username+0x89>
mov    %r14,%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11af <extract_username+0x5f>
mov    %r14,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11af <extract_username+0x5f>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%r15
add    %r14,%r15
sub    %r14,%r15
lea    0x1(%r15),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <enough_mem@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r15,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @extract_username(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 34
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = call i8* @strchr(i8* %12, i8 signext 34)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %10
store i8* null, i8** %2
br label %64
17: ; preds = %10
br label %36
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = call i8* @strchr(i8* %19, i8 signext 64)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = call i8* @strchr(i8* %24, i8 signext 44)
store i8* %25, i8** %4
br label %26
26: ; preds = %23, %18
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = load i8*, i8** %3
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8* %34, i8** %4
br label %35
35: ; preds = %29, %26
br label %36
36: ; preds = %35, %17
%37 = load i8*, i8** %4
%38 = load i8*, i8** %3
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = add nsw i64 %41, 1
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %5
%45 = load i8*, i8** %5
%46 = call i32 @enough_mem(i8* %45)
%47 = load i8*, i8** %5
%48 = load i8*, i8** %3
%49 = load i8*, i8** %4
%50 = load i8*, i8** %3
%51 = ptrtoint i8* %49 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = trunc i64 %53 to i32
%55 = call i32 @strncpy(i8* %47, i8* %48, i32 %54)
%56 = load i8*, i8** %5
%57 = load i8*, i8** %4
%58 = load i8*, i8** %3
%59 = ptrtoint i8* %57 to i64
%60 = ptrtoint i8* %58 to i64
%61 = sub i64 %59, %60
%62 = getelementptr inbounds i8, i8* %56, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %5
store i8* %63, i8** %2
br label %64
64: ; preds = %36, %16
%65 = load i8*, i8** %2
ret i8* %65
}

LLVM IR (-O2):
define i8* @extract_username(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 34
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = tail call i8* @strchr(i8* %5, i8 signext 34)
%7 = icmp eq i8* %6, null
br i1 %7, label %29, label %18
8: ; preds = %1
%9 = tail call i8* @strchr(i8* %0, i8 signext 64)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = tail call i8* @strchr(i8* %0, i8 signext 44)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i32 @strlen(i8* %0)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
br label %18
18: ; preds = %8, %11, %14, %4
%19 = phi i8* [ %6, %4 ], [ %12, %11 ], [ %17, %14 ], [ %9, %8 ]
%20 = ptrtoint i8* %19 to i64
%21 = ptrtoint i8* %0 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
%24 = add i32 %23, 1
%25 = tail call i8* @malloc(i32 %24)
%26 = tail call i32 @enough_mem(i8* %25)
%27 = tail call i32 @strncpy(i8* %25, i8* %0, i32 %23)
%28 = getelementptr inbounds i8, i8* %25, i64 %22
store i8 0, i8* %28
br label %29
29: ; preds = %4, %18
%30 = phi i8* [ %25, %18 ], [ null, %4 ]
ret i8* %30
}