#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);
int /*<<< orphan*/ strcpy(char *, char *);
char strlen(char *);
scalar_t__ strncmp(char *, char *, char);
int _bt_parse_connect(char *buf, char *mac) {
  char *sep, len;
  if (!buf || !mac)
    return -1;
  sep = strchr(buf, ',');
  if (sep) {
    *sep = '\0';
    sep++;
  }
  len = strlen("CONNECT ");
  if (strncmp(buf, "CONNECT ", len) == 0) {
    strcpy(mac, &buf[len]);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<_bt_parse_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <_bt_parse_connect+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1172 <_bt_parse_connect+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <_bt_parse_connect+0xb7>
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1060 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a2 <_bt_parse_connect+0x62>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
lea    0xe57(%rip),%rdi
call   1050 <strlen@plt>
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
movsbl -0x21(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f0 <_bt_parse_connect+0xb0>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsbq -0x21(%rbp),%rax
add    %rax,%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <_bt_parse_connect+0xb7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_bt_parse_connect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     11a8 <_bt_parse_connect+0x68>
mov    %rsi,%r14
test   %rsi,%rsi
je     11a8 <_bt_parse_connect+0x68>
mov    %rdi,%rbx
mov    $0x2c,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     116f <_bt_parse_connect+0x2f>
movb   $0x0,(%rax)
lea    0xe8a(%rip),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
movsbl %al,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11a8 <_bt_parse_connect+0x68>
movsbq %r15b,%rax
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"CONNECT \00"
define i32 @_bt_parse_connect(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 -1, i32* %3
br label %37
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i8* @strchr(i8* %15, i8 signext 44)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %6
store i8 0, i8* %20
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %6
br label %23
23: ; preds = %19, %14
%24 = call signext i8 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8 %24, i8* %7
%25 = load i8*, i8** %4
%26 = load i8, i8* %7
%27 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 signext %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = load i8*, i8** %4
%32 = load i8, i8* %7
%33 = sext i8 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @strcpy(i8* %30, i8* %34)
store i32 0, i32* %3
br label %37
36: ; preds = %23
store i32 -1, i32* %3
br label %37
37: ; preds = %36, %29, %13
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [9 x i8] c"CONNECT \00"
define i32 @_bt_parse_connect(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = tail call i8* @strchr(i8* %0, i8 signext 44)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %6
store i8 0, i8* %7
br label %10
10: ; preds = %9, %6
%11 = tail call signext i8 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = sext i8 %11 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i32 @strcpy(i8* %1, i8* %16)
br label %18
18: ; preds = %10, %2, %14
%19 = phi i32 [ 0, %14 ], [ -1, %2 ], [ -1, %10 ]
ret i32 %19
}