#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__ strcmp(char *, char const *);
char *strtok(char *, char const *);
int detect_delim_count(char *i_str, const char *delim) {
  char *itr_str = NULL;
  char *parser = NULL;
  int count = 0;
  itr_str = i_str;
  for (parser = strtok(itr_str, delim); parser && *parser;
       parser = strtok(NULL, delim)) {
    if (strcmp(parser, delim) != 0)
      count++;
  }
  return (count - 1);
}


x86 assembly (clang, -O0):
<detect_delim_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x25(%rbp)
je     1180 <detect_delim_count+0x60>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1190 <detect_delim_count+0x70>
jmp    11cb <detect_delim_count+0xab>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11b0 <detect_delim_count+0x90>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b5 <detect_delim_count+0x95>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1160 <detect_delim_count+0x40>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_delim_count>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1166 <detect_delim_count+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x0,(%rax)
je     1166 <detect_delim_count+0x46>
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1140 <detect_delim_count+0x20>
add    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @detect_delim_count(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
store i8* null, i8** %6
store i32 0, i32* %7
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = load i8*, i8** %4
%11 = call i8* @strtok(i8* %9, i8* %10)
store i8* %11, i8** %6
br label %12
12: ; preds = %31, %2
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %15, %12
%21 = phi i1 [ false, %12 ], [ %19, %15 ]
br i1 %21, label %22, label %34
22: ; preds = %20
%23 = load i8*, i8** %6
%24 = load i8*, i8** %4
%25 = call i64 @strcmp(i8* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %30
30: ; preds = %27, %22
br label %31
31: ; preds = %30
%32 = load i8*, i8** %4
%33 = call i8* @strtok(i8* null, i8* %32)
store i8* %33, i8** %6
br label %12
34: ; preds = %20
%35 = load i32, i32* %7
%36 = sub nsw i32 %35, 1
ret i32 %36
}

LLVM IR (-O2):
define i32 @detect_delim_count(i8* %0, i8* %1) {
%3 = tail call i8* @strtok(i8* %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2, %10
%6 = phi i32 [ %14, %10 ], [ 0, %2 ]
%7 = phi i8* [ %15, %10 ], [ %3, %2 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = tail call i64 @strcmp(i8* %7, i8* %1)
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %6, %13
%15 = tail call i8* @strtok(i8* null, i8* %1)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %5
17: ; preds = %5, %10, %2
%18 = phi i32 [ 0, %2 ], [ %14, %10 ], [ %6, %5 ]
%19 = add nsw i32 %18, -1
ret i32 %19
}