#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 extract_ssid(char *);
int /*<<< orphan*/ lprintf(int, char *, ...);
int /*<<< orphan*/ memcpy(char *, unsigned char *, int);
int decode_pathtrace(unsigned char *element, int element_len) {
  char callsign[7];
  int ssid, c, network;
  if (element_len % 7)
    return -1;
  if (!element_len) {
    lprintf(14, "Empty Path\r\n");
    return 0;
  }
  lprintf(14, "Path: ");
  for (c = 0; c < element_len; c += 7) {
    memcpy(callsign, element + c, 6);
    ssid = extract_ssid(callsign);
    network = (int)*(element + c + 6);
    lprintf(14, " %s-%d (%d)", callsign, ssid, network);
  }
  lprintf(14, "\r\n");
  return 0;
}


x86 assembly (clang, -O0):
<decode_pathtrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     115f <decode_pathtrace+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <decode_pathtrace+0xf9>
cmpl   $0x0,-0x14(%rbp)
jne    1188 <decode_pathtrace+0x58>
mov    $0xe,%edi
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1050 <lprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1229 <decode_pathtrace+0xf9>
mov    $0xe,%edi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <lprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    120f <decode_pathtrace+0xdf>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    $0x6,%edx
call   1030 <memcpy@plt>
lea    -0x1b(%rbp),%rdi
call   1040 <extract_ssid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl 0x6(%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
lea    -0x1b(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    $0xe,%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <lprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x24(%rbp)
jmp    11a2 <decode_pathtrace+0x72>
mov    $0xe,%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1050 <lprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_pathtrace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
imul   $0xb6db6db7,%esi,%eax
add    $0x12492492,%eax
mov    $0xffffffff,%r14d
cmp    $0x24924924,%eax
ja     11eb <decode_pathtrace+0xbb>
mov    %esi,%r15d
test   %esi,%esi
je     11d5 <decode_pathtrace+0xa5>
mov    %rdi,%r13
lea    0xea5(%rip),%rsi
xor    %r14d,%r14d
mov    $0xe,%edi
xor    %eax,%eax
call   1050 <lprintf@plt>
test   %r15d,%r15d
jle    11cc <decode_pathtrace+0x9c>
lea    0x1(%rsp),%rbp
lea    0xe8c(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r13,1),%rsi
mov    %rbp,%rdi
mov    $0x6,%edx
call   1030 <memcpy@plt>
mov    %rbp,%rdi
call   1040 <extract_ssid@plt>
movzbl 0x6(%r13,%rbx,1),%r8d
mov    $0xe,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <lprintf@plt>
add    $0x7,%rbx
cmp    %r15d,%ebx
jl     1190 <decode_pathtrace+0x60>
lea    0xe37(%rip),%rsi
jmp    11df <decode_pathtrace+0xaf>
lea    0xe24(%rip),%rsi
xor    %r14d,%r14d
mov    $0xe,%edi
xor    %eax,%eax
call   1050 <lprintf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Empty Path\0D\0A\00"
@.str.1 = [7 x i8] c"Path: \00"
@.str.2 = [12 x i8] c" %s-%d (%d)\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
define i32 @decode_pathtrace(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [7 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = srem i32 %10, 7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %50
14: ; preds = %2
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %50
19: ; preds = %14
%20 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %21
21: ; preds = %45, %19
%22 = load i32, i32* %8
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %48
25: ; preds = %21
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %4
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 @memcpy(i8* %26, i8* %30, i32 6)
%32 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%33 = call i32 @extract_ssid(i8* %32)
store i32 %33, i32* %7
%34 = load i8*, i8** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 6
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
store i32 %40, i32* %9
%41 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%42 = load i32, i32* %7
%43 = load i32, i32* %9
%44 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %42, i32 %43)
br label %45
45: ; preds = %25
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 7
store i32 %47, i32* %8
br label %21
48: ; preds = %21
%49 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %50
50: ; preds = %48, %17, %13
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [13 x i8] c"Empty Path\0D\0A\00"
@.str.1 = [7 x i8] c"Path: \00"
@.str.2 = [12 x i8] c" %s-%d (%d)\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
define i32 @decode_pathtrace(i8* %0, i32 %1) {
%3 = alloca [7 x i8]
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%5 = srem i32 %1, 7
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = icmp eq i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %28
11: ; preds = %7
%12 = tail call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %26
14: ; preds = %11, %14
%15 = phi i64 [ %23, %14 ], [ 0, %11 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = call i32 @memcpy(i8* %4, i8* %16, i32 6)
%18 = call i32 @extract_ssid(i8* %4)
%19 = getelementptr inbounds i8, i8* %16, i64 6
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %18, i32 %21)
%23 = add nuw i64 %15, 7
%24 = trunc i64 %23 to i32
%25 = icmp slt i32 %24, %1
br i1 %25, label %14, label %26
26: ; preds = %14, %11
%27 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %2, %26, %9
%29 = phi i32 [ 0, %26 ], [ 0, %9 ], [ -1, %2 ]
ret i32 %29
}