#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 */
typedef char const uint8_t;
typedef size_t uint16_t;

/* Variables and functions */
int /*<<< orphan*/ FRM_init();
int /*<<< orphan*/ FRM_push(char const);
scalar_t__ atol(char *);
uint16_t parseTopicString(const char *topic, uint8_t dimensions) {
  uint16_t dataLength = 1, strIndex = 0;
  uint16_t i;
  FRM_init();
  strIndex = 0;
  while ((topic[strIndex] != 0) && (topic[strIndex] != ':')) {
    FRM_push(topic[strIndex]);
    strIndex++;
  }
  FRM_push(0);
  if (topic[strIndex] == ':') {
    strIndex++;
    char numStr[8] = {0};
    i = 0;
    while (topic[strIndex] != 0) {
      numStr[i] = topic[strIndex];
      i++;
      strIndex++;
    }
    dataLength = (uint16_t)atol(numStr);
  }
  FRM_push(dimensions);
  FRM_push((uint8_t)(dataLength & 0x00ff));
  FRM_push((uint8_t)((dataLength & 0xff00) >> 8));
  return dataLength;
}


x86 assembly (clang, -O0):
<parseTopicString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x1,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <FRM_init@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11a0 <parseTopicString+0x60>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11b0 <parseTopicString+0x70>
jmp    11d2 <parseTopicString+0x92>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <FRM_push@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1171 <parseTopicString+0x31>
xor    %edi,%edi
call   1060 <FRM_push@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1264 <parseTopicString+0x124>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1257 <parseTopicString+0x117>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1212 <parseTopicString+0xd2>
lea    -0x30(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,-0x18(%rbp)
movsbl -0x9(%rbp),%edi
call   1060 <FRM_push@plt>
mov    -0x18(%rbp),%rax
and    $0xff,%rax
movsbl %al,%edi
call   1060 <FRM_push@plt>
mov    -0x18(%rbp),%rax
and    $0xff00,%rax
shr    $0x8,%rax
movsbl %al,%edi
call   1060 <FRM_push@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseTopicString>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <FRM_init@plt>
add    $0x2,%rbx
nopl   0x0(%rax)
movzbl -0x2(%rbx),%eax
test   %al,%al
je     116a <parseTopicString+0x3a>
cmp    $0x3a,%al
je     116a <parseTopicString+0x3a>
movsbl %al,%edi
call   1050 <FRM_push@plt>
add    $0x1,%rbx
jmp    1150 <parseTopicString+0x20>
xor    %edi,%edi
call   1050 <FRM_push@plt>
mov    $0x1,%ebp
cmpb   $0x3a,-0x2(%rbx)
jne    11be <parseTopicString+0x8e>
movq   $0x0,0x8(%rsp)
mov    -0x1(%rbx),%al
test   %al,%al
je     11b1 <parseTopicString+0x81>
lea    0x8(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %al,(%rcx)
movzbl (%rbx),%eax
add    $0x1,%rbx
add    $0x1,%rcx
test   %al,%al
jne    11a0 <parseTopicString+0x70>
lea    0x8(%rsp),%rdi
call   1040 <atol@plt>
mov    %rax,%rbp
movsbl %r14b,%edi
call   1050 <FRM_push@plt>
movsbl %bpl,%edi
call   1050 <FRM_push@plt>
mov    %ebp,%eax
shr    $0x8,%eax
movsbl %al,%edi
call   1050 <FRM_push@plt>
mov    %rbp,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @parseTopicString(i8* nocapture %0, i8 signext %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to [8 x i8]*
%5 = tail call i32 (...) @FRM_init()
br label %6
6: ; preds = %10, %2
%7 = phi i64 [ 0, %2 ], [ %12, %10 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 0, label %13
i8 58, label %13
]
10: ; preds = %6
%11 = tail call i32 @FRM_push(i8 signext %9)
%12 = add i64 %7, 1
br label %6
13: ; preds = %6, %6
%14 = getelementptr inbounds i8, i8* %0, i64 %7
%15 = tail call i32 @FRM_push(i8 signext 0)
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 58
br i1 %17, label %18, label %36
18: ; preds = %13
%19 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%20 = add i64 %7, 1
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %18, %24
%25 = phi i8 [ %32, %24 ], [ %22, %18 ]
%26 = phi i64 [ %30, %24 ], [ %20, %18 ]
%27 = phi i64 [ %29, %24 ], [ 0, %18 ]
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 %27
store i8 %25, i8* %28
%29 = add i64 %27, 1
%30 = add i64 %26, 1
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %24
34: ; preds = %24, %18
%35 = call i64 @atol(i8* %19)
br label %36
36: ; preds = %34, %13
%37 = phi i64 [ %35, %34 ], [ 1, %13 ]
%38 = tail call i32 @FRM_push(i8 signext %1)
%39 = trunc i64 %37 to i8
%40 = tail call i32 @FRM_push(i8 signext %39)
%41 = lshr i64 %37, 8
%42 = trunc i64 %41 to i8
%43 = tail call i32 @FRM_push(i8 signext %42)
ret i64 %37
}