#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 *strstr(char const *, char const *);
size_t pathitems_count(const char *ptr, const char *delim, size_t dl) {
  size_t c = 0;
  if (dl == 0)
    return 0;
  ptr = strstr(ptr, delim);
  while (ptr != NULL) {
    c++;
    ptr = strstr(ptr + dl, delim);
  }
  return c + 1;
}


x86 assembly (clang, -O0):
<pathitems_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1144 <pathitems_count+0x34>
movq   $0x0,-0x8(%rbp)
jmp    1192 <pathitems_count+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1186 <pathitems_count+0x76>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x10(%rbp)
jmp    1155 <pathitems_count+0x45>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathitems_count>:
push   %r15
push   %r14
push   %rbx
test   %rdx,%rdx
je     1149 <pathitems_count+0x39>
mov    %rdx,%r15
mov    %rsi,%r14
call   1030 <strstr@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     114b <pathitems_count+0x3b>
nop
add    %r15,%rax
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strstr@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <pathitems_count+0x20>
jmp    114b <pathitems_count+0x3b>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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