#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 */
struct katcl_parse {
  int dummy;
};
struct katcl_byte_bit {
  int dummy;
};

/* Variables and functions */
char *get_string_parse_katcl(struct katcl_parse *, unsigned int);
int make_bb_katcl(struct katcl_byte_bit *, unsigned long, unsigned long);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int get_bb_parse_katcl(struct katcl_parse *p, unsigned int index,
                       struct katcl_byte_bit *b) {
  char *string, *end;
  unsigned long byte, bit;
  if (b == NULL) {
    return -1;
  }
  string = get_string_parse_katcl(p, index);
  if (string == NULL) {
    return -1;
  }
  if (string[0] != ':') {
    byte = strtoul(string, &end, 0);
    if (end[0] == ':') {
      string = end;
    }
  } else {
    byte = 0;
  }
  if (string[0] == ':') {
    bit = strtoul(string + 1, NULL, 0);
  } else {
    bit = 0;
  }
  return make_bb_katcl(b, byte, bit);
}


x86 assembly (clang, -O0):
<get_bb_parse_katcl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115a <get_bb_parse_katcl+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <get_bb_parse_katcl+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <get_string_parse_katcl@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1181 <get_bb_parse_katcl+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <get_bb_parse_katcl+0xe1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     11c1 <get_bb_parse_katcl+0x91>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    11bc <get_bb_parse_katcl+0x8c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11c9 <get_bb_parse_katcl+0x99>
movq   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    11f5 <get_bb_parse_katcl+0xc5>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x40(%rbp)
jmp    11fd <get_bb_parse_katcl+0xcd>
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1030 <make_bb_katcl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bb_parse_katcl>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1157 <get_bb_parse_katcl+0x27>
mov    %rdx,%r14
call   1040 <get_string_parse_katcl@plt>
test   %rax,%rax
je     1157 <get_bb_parse_katcl+0x27>
mov    %rax,%rbx
cmpb   $0x3a,(%rax)
jne    1168 <get_bb_parse_katcl+0x38>
xor    %r15d,%r15d
jmp    118b <get_bb_parse_katcl+0x5b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rsp,%rsi
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,%r15
mov    (%rsp),%rax
cmpb   $0x3a,(%rax)
cmove  %rax,%rbx
cmpb   $0x3a,(%rbx)
jne    119e <get_bb_parse_katcl+0x6e>
add    $0x1,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <make_bb_katcl@plt>

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

LLVM IR (-O2):
%struct.katcl_parse = type { i32 }
%struct.katcl_byte_bit = type { i32 }
define i32 @get_bb_parse_katcl(%struct.katcl_parse* %0, i32 %1, %struct.katcl_byte_bit* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq %struct.katcl_byte_bit* %2, null
br i1 %6, label %30, label %7
7: ; preds = %3
%8 = tail call i8* @get_string_parse_katcl(%struct.katcl_parse* %0, i32 %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %30, label %10
10: ; preds = %7
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 58
br i1 %12, label %21, label %13
13: ; preds = %10
%14 = call i64 @strtoul(i8* %8, i8** %4, i32 0)
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 58
%18 = select i1 %17, i8* %15, i8* %8
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 58
br i1 %20, label %21, label %26
21: ; preds = %10, %13
%22 = phi i64 [ %14, %13 ], [ 0, %10 ]
%23 = phi i8* [ %18, %13 ], [ %8, %10 ]
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = tail call i64 @strtoul(i8* nocapture %24, i8** null, i32 0)
br label %26
26: ; preds = %13, %21
%27 = phi i64 [ %22, %21 ], [ %14, %13 ]
%28 = phi i64 [ %25, %21 ], [ 0, %13 ]
%29 = tail call i32 @make_bb_katcl(%struct.katcl_byte_bit* %2, i64 %27, i64 %28)
br label %30
30: ; preds = %7, %3, %26
%31 = phi i32 [ %29, %26 ], [ -1, %3 ], [ -1, %7 ]
ret i32 %31
}