#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 */
char *strchr(char *, char const);
char *strdup(char *);
size_t strlen(char const *);
char *strndup(char *, size_t);
char *strstr(char *, char const *);
char *__parse_connect_arg(char *conargs, const char delim,
                          const char *fieldnm) {
  char *s, *e;
  size_t cnt;
  do {
    s = strstr(conargs, fieldnm);
    if (!s)
      goto empty_field;
    if (s == conargs || *(s - 1) == delim) {
      s += strlen(fieldnm);
      if (*s == '=')
        break;
    }
    conargs = strchr(s, delim);
    if (!conargs)
      goto empty_field;
    conargs++;
  } while (1);
  s++;
  e = strchr(s, delim);
  if (e)
    cnt = e - s;
  else
    cnt = strlen(s);
  return strndup(s, cnt);
empty_field:
  return strdup("\0");
}


x86 assembly (clang, -O0):
<__parse_connect_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1187 <__parse_connect_arg+0x37>
jmp    126f <__parse_connect_arg+0x11f>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11a9 <__parse_connect_arg+0x59>
mov    -0x28(%rbp),%rax
movsbl -0x1(%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    11d4 <__parse_connect_arg+0x84>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
jne    11cf <__parse_connect_arg+0x7f>
jmp    1210 <__parse_connect_arg+0xc0>
jmp    11d4 <__parse_connect_arg+0x84>
mov    -0x28(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f5 <__parse_connect_arg+0xa5>
jmp    126f <__parse_connect_arg+0x11f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1166 <__parse_connect_arg+0x16>
jmp    1210 <__parse_connect_arg+0xc0>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     124c <__parse_connect_arg+0xfc>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    1259 <__parse_connect_arg+0x109>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <strndup@plt>
mov    %rax,-0x8(%rbp)
jmp    127f <__parse_connect_arg+0x12f>
lea    0xd8a(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__parse_connect_arg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdx,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11cb <__parse_connect_arg+0x7b>
mov    %rax,%rbp
movsbl %r14b,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %rbx,%rbp
je     118b <__parse_connect_arg+0x3b>
cmp    %r14b,-0x1(%rbp)
jne    11a1 <__parse_connect_arg+0x51>
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbp,1),%rbx
cmpb   $0x3d,0x0(%rbp,%rax,1)
je     11df <__parse_connect_arg+0x8f>
mov    %rbx,%rbp
mov    %rbp,%rdi
mov    %r15d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11cb <__parse_connect_arg+0x7b>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1180 <__parse_connect_arg+0x30>
lea    0xe2e(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <strdup@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f8 <__parse_connect_arg+0xa8>
sub    %rbx,%rax
jmp    1200 <__parse_connect_arg+0xb0>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strndup@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
define noalias i8* @__parse_connect_arg(i8* %0, i8 signext %1, i8* nocapture %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %40, label %9
6: ; preds = %22
%7 = tail call i8* @strstr(i8* dereferenceable(1) %26, i8* dereferenceable(1) %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %40, label %9
9: ; preds = %3, %6
%10 = phi i8* [ %7, %6 ], [ %4, %3 ]
%11 = phi i8* [ %26, %6 ], [ %0, %3 ]
%12 = icmp eq i8* %10, %11
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 -1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, %1
br i1 %16, label %17, label %22
17: ; preds = %13, %9
%18 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%19 = getelementptr inbounds i8, i8* %10, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 61
br i1 %21, label %27, label %22
22: ; preds = %17, %13
%23 = phi i8* [ %19, %17 ], [ %10, %13 ]
%24 = tail call i8* @strchr(i8* %23, i8 signext %1)
%25 = icmp eq i8* %24, null
%26 = getelementptr inbounds i8, i8* %24, i64 1
br i1 %25, label %40, label %6
27: ; preds = %17
%28 = getelementptr inbounds i8, i8* %19, i64 1
%29 = tail call i8* @strchr(i8* %28, i8 signext %1)
%30 = icmp eq i8* %29, null
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = ptrtoint i8* %29 to i64
%33 = ptrtoint i8* %28 to i64
%34 = sub i64 %32, %33
br label %37
35: ; preds = %27
%36 = tail call i64 @strlen(i8* %28)
br label %37
37: ; preds = %35, %31
%38 = phi i64 [ %34, %31 ], [ %36, %35 ]
%39 = tail call i8* @strndup(i8* %28, i64 %38)
br label %42
40: ; preds = %6, %22, %3
%41 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = phi i8* [ %39, %37 ], [ %41, %40 ]
ret i8* %43
}