#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*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
int get_ssid_bssid(char *survey_line, char *bssidbuf, char *ssidbuf) {
  char *pos1 = survey_line, *pos2 = survey_line;
  char cachechar;
  if ((pos1 = strrchr(pos2, ':'))) {
    cachechar = pos1[1];
    pos1[1] = 0;
    pos2 = strrchr(survey_line, '$') + 1;
    pos1[1] = cachechar;
    pos1 = strchr(pos2, '$');
  } else {
    return -1;
  }
  strncpy(bssidbuf, pos2, pos1 - pos2);
  bssidbuf[pos1 - pos2] = 0;
  pos1 = strchr(survey_line, '$') + 1;
  strncpy(ssidbuf, pos1, pos2 - pos1 - 1);
  ssidbuf[pos2 - pos1 - 1] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<get_ssid_bssid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11b9 <get_ssid_bssid+0x89>
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x31(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x24,%esi
call   1050 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x31(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
jmp    11c5 <get_ssid_bssid+0x95>
movl   $0xffffffff,-0x4(%rbp)
jmp    1244 <get_ssid_bssid+0x114>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ssid_bssid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x3a,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11d9 <get_ssid_bssid+0xa9>
mov    %rax,%rbx
mov    %rbp,(%rsp)
mov    0x1(%rax),%r14b
movb   $0x0,0x1(%rax)
mov    %r12,%rdi
mov    $0x24,%esi
call   1050 <strrchr@plt>
mov    %rax,%r13
lea    0x1(%rax),%rbp
mov    %r14b,0x1(%rbx)
mov    %rbp,%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
sub    %rbp,%rbx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r12,%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rsi
mov    %rsi,%rax
not    %rax
lea    (%rax,%r13,1),%rbx
add    $0x1,%rbx
mov    (%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
xor    %eax,%eax
jmp    11de <get_ssid_bssid+0xae>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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