#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 */
char *strpbrk(char const *, char const *);
int delimiter_count(const char *haystack, const char *delimiter) {
  char *token_position;
  int number_of_tokens = 0;
  token_position = strpbrk(haystack, delimiter);
  while (token_position != NULL) {
    number_of_tokens++;
    token_position = strpbrk(token_position + 1, delimiter);
  }
  if (number_of_tokens > 0) {
    return number_of_tokens + 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<delimiter_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strpbrk@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1166 <delimiter_count+0x56>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strpbrk@plt>
mov    %rax,-0x20(%rbp)
jmp    1138 <delimiter_count+0x28>
cmpl   $0x0,-0x24(%rbp)
jle    117e <delimiter_count+0x6e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <delimiter_count+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delimiter_count>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1030 <strpbrk@plt>
test   %rax,%rax
je     1149 <delimiter_count+0x39>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rax
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strpbrk@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1130 <delimiter_count+0x20>
jmp    114b <delimiter_count+0x3b>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @delimiter_count(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i8* @strpbrk(i8* %8, i8* %9)
store i8* %10, i8** %6
br label %11
11: ; preds = %14, %2
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8*, i8** %5
%20 = call i8* @strpbrk(i8* %18, i8* %19)
store i8* %20, i8** %6
br label %11
21: ; preds = %11
%22 = load i32, i32* %7
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %28
27: ; preds = %21
store i32 0, i32* %3
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @delimiter_count(i8* %0, i8* nocapture %1) {
%3 = tail call i8* @strpbrk(i8* %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2, %5
%6 = phi i32 [ %8, %5 ], [ 0, %2 ]
%7 = phi i8* [ %10, %5 ], [ %3, %2 ]
%8 = add nuw nsw i32 %6, 1
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = tail call i8* @strpbrk(i8* %9, i8* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = add nuw nsw i32 %6, 2
br label %14
14: ; preds = %2, %12
%15 = phi i32 [ %13, %12 ], [ 0, %2 ]
ret i32 %15
}