#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 atoi(char *);
char *strchr(char *, char);
char *strrchr(char *, char);
int get_bssid_ssid_level(char *survey_line, char **bssidpos, char **ssidpos,
                         int *level) {
  char *pos1 = survey_line, *pos2 = survey_line;
  char cachechar;
  int i;
  if ((pos1 = strrchr(pos2, ':'))) {
    cachechar = pos1[1];
    pos1[1] = 0;
    pos2 = strrchr(survey_line, '$') + 1;
    pos1[1] = cachechar;
  } else {
    return -1;
  }
  if (bssidpos)
    *bssidpos = pos2;
  if (ssidpos)
    *ssidpos = strchr(survey_line, '$') + 1;
  if (level) {
    pos1 = strchr(pos2, '$') + 1;
    pos1 = strchr(pos1, '$') + 1;
    *level = atoi(pos1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_bssid_ssid_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11ab <get_bssid_ssid_level+0x7b>
mov    -0x30(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x39(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x24,%esi
call   1040 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x39(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x1(%rax)
jmp    11b7 <get_bssid_ssid_level+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <get_bssid_ssid_level+0x113>
cmpq   $0x0,-0x18(%rbp)
je     11cd <get_bssid_ssid_level+0x9d>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11f4 <get_bssid_ssid_level+0xc4>
mov    -0x10(%rbp),%rdi
mov    $0x24,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     123c <get_bssid_ssid_level+0x10c>
mov    -0x38(%rbp),%rdi
mov    $0x24,%esi
call   1030 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x24,%esi
call   1030 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bssid_ssid_level>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11d3 <get_bssid_ssid_level+0xa3>
mov    %rax,%rbp
mov    %r14,(%rsp)
mov    0x1(%rax),%r14b
movb   $0x0,0x1(%rax)
mov    %rbx,%rdi
mov    $0x24,%esi
call   1040 <strrchr@plt>
mov    %rax,%r12
add    $0x1,%r12
mov    %r14b,0x1(%rbp)
test   %r13,%r13
je     1186 <get_bssid_ssid_level+0x56>
mov    %r12,0x0(%r13)
test   %r15,%r15
mov    (%rsp),%rbp
je     11a3 <get_bssid_ssid_level+0x73>
mov    %rbx,%rdi
mov    $0x24,%esi
call   1030 <strchr@plt>
add    $0x1,%rax
mov    %rax,(%r15)
xor    %ebx,%ebx
test   %rbp,%rbp
je     11d8 <get_bssid_ssid_level+0xa8>
mov    %r12,%rdi
mov    $0x24,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
mov    $0x24,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,0x0(%rbp)
jmp    11d8 <get_bssid_ssid_level+0xa8>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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