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


x86 assembly (clang, -O0):
<extract_userhost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11e1 <extract_userhost+0x91>
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_userhost+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    127c <extract_userhost+0x12c>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dc <extract_userhost+0x8c>
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    1224 <extract_userhost+0xd4>
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121f <extract_userhost+0xcf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1224 <extract_userhost+0xd4>
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_userhost>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
cmpb   $0x22,(%rdi)
jne    1179 <extract_userhost+0x29>
lea    0x1(%r14),%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c6 <extract_userhost+0x76>
add    $0x1,%rax
mov    %rax,%rdi
jmp    117c <extract_userhost+0x2c>
mov    %r14,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119c <extract_userhost+0x4c>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
sub    %r14,%rbx
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <enough_mem@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
jmp    11c9 <extract_userhost+0x79>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @extract_userhost(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 %30
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 %71
17: ; preds = %10
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i8* @strchr(i8* %19, i8 signext 44)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %29, label %23
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8* %28, i8** %4
br label %29
29: ; preds = %23, %17
br label %42
30: ; preds = %1
%31 = load i8*, i8** %3
%32 = call i8* @strchr(i8* %31, i8 signext 44)
store i8* %32, i8** %4
%33 = load i8*, i8** %4
%34 = icmp ne i8* %33, null
br i1 %34, label %41, label %35
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = load i8*, i8** %3
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8* %40, i8** %4
br label %41
41: ; preds = %35, %30
br label %42
42: ; preds = %41, %29
%43 = load i8*, i8** %4
%44 = load i8*, i8** %3
%45 = ptrtoint i8* %43 to i64
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %45, %46
%48 = add nsw i64 %47, 1
%49 = trunc i64 %48 to i32
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %5
%52 = load i8*, i8** %5
%53 = call i32 @enough_mem(i8* %52)
%54 = load i8*, i8** %5
%55 = load i8*, i8** %3
%56 = load i8*, i8** %4
%57 = load i8*, i8** %3
%58 = ptrtoint i8* %56 to i64
%59 = ptrtoint i8* %57 to i64
%60 = sub i64 %58, %59
%61 = trunc i64 %60 to i32
%62 = call i32 @strncpy(i8* %54, i8* %55, i32 %61)
%63 = load i8*, i8** %5
%64 = load i8*, i8** %4
%65 = load i8*, i8** %3
%66 = ptrtoint i8* %64 to i64
%67 = ptrtoint i8* %65 to i64
%68 = sub i64 %66, %67
%69 = getelementptr inbounds i8, i8* %63, i64 %68
store i8 0, i8* %69
%70 = load i8*, i8** %5
store i8* %70, i8** %2
br label %71
71: ; preds = %42, %16
%72 = load i8*, i8** %2
ret i8* %72
}

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