#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 */
scalar_t__ is_hostvar_char(char const);
char *strchr(char const *, char);
size_t sql_count_host_vars(const char *s) {
  size_t ret = 0;
  const char *pos = s;
  for (;;) {
    const char *a = strchr(pos, '\'');
    const char *b = strchr(pos, ':');
    if (!b)
      break;
    if (!a || b < a) {
      ++ret;
      pos = b + 1;
      for (; is_hostvar_char(*pos); ++pos)
        ;
      if (*pos == ':')
        ++pos;
    } else {
      pos = a + 1;
      pos = strchr(pos, '\'');
      if (!pos)
        break;
      ++pos;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<sql_count_host_vars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x27,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1170 <sql_count_host_vars+0x50>
jmp    122d <sql_count_host_vars+0x10d>
cmpq   $0x0,-0x20(%rbp)
je     1189 <sql_count_host_vars+0x69>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11ee <sql_count_host_vars+0xce>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <is_hostvar_char@plt>
cmp    $0x0,%rax
je     11cd <sql_count_host_vars+0xad>
jmp    11bc <sql_count_host_vars+0x9c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a1 <sql_count_host_vars+0x81>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    11e9 <sql_count_host_vars+0xc9>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1228 <sql_count_host_vars+0x108>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x27,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121c <sql_count_host_vars+0xfc>
jmp    122d <sql_count_host_vars+0x10d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <sql_count_host_vars+0x1c>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sql_count_host_vars>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d3 <sql_count_host_vars+0xb3>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x27,%esi
call   1030 <strchr@plt>
mov    %rax,%r15
xor    %r14d,%r14d
jmp    11a2 <sql_count_host_vars+0x82>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
mov    %r15,%rdi
mov    $0x27,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d6 <sql_count_host_vars+0xb6>
mov    %rax,%r12
add    $0x1,%r12
mov    %r12,%rdi
mov    $0x27,%esi
call   1030 <strchr@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d6 <sql_count_host_vars+0xb6>
test   %r15,%r15
je     11ac <sql_count_host_vars+0x8c>
cmp    %r15,%rbx
jae    1160 <sql_count_host_vars+0x40>
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1040 <is_hostvar_char@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    11b0 <sql_count_host_vars+0x90>
add    $0x1,%r14
lea    -0x1(%rbx),%r12
cmpb   $0x3a,-0x1(%rbx)
cmove  %rbx,%r12
jmp    117d <sql_count_host_vars+0x5d>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @sql_count_host_vars(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%3 = icmp eq i8* %2, null
br i1 %3, label %36, label %4
4: ; preds = %1
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 39)
br label %6
6: ; preds = %4, %30
%7 = phi i8* [ %34, %30 ], [ %2, %4 ]
%8 = phi i8* [ %33, %30 ], [ %5, %4 ]
%9 = phi i64 [ %32, %30 ], [ 0, %4 ]
%10 = icmp eq i8* %8, null
%11 = icmp ult i8* %7, %8
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %13, label %25
13: ; preds = %6, %13
%14 = phi i8* [ %15, %13 ], [ %7, %6 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = tail call i64 @is_hostvar_char(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %13
19: ; preds = %13
%20 = add i64 %9, 1
%21 = load i8, i8* %15
%22 = icmp eq i8 %21, 58
%23 = getelementptr inbounds i8, i8* %14, i64 2
%24 = select i1 %22, i8* %23, i8* %15
br label %30
25: ; preds = %6
%26 = getelementptr inbounds i8, i8* %8, i64 1
%27 = tail call i8* @strchr(i8* %26, i8 signext 39)
%28 = icmp eq i8* %27, null
%29 = getelementptr inbounds i8, i8* %27, i64 1
br i1 %28, label %36, label %30
30: ; preds = %25, %19
%31 = phi i8* [ %24, %19 ], [ %29, %25 ]
%32 = phi i64 [ %20, %19 ], [ %9, %25 ]
%33 = tail call i8* @strchr(i8* dereferenceable(1) %31, i8 signext 39)
%34 = tail call i8* @strchr(i8* dereferenceable(1) %31, i8 signext 58)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %6
36: ; preds = %30, %25, %1
%37 = phi i64 [ 0, %1 ], [ %9, %25 ], [ %32, %30 ]
ret i64 %37
}