#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 */
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
scalar_t__ strsep(char **, char const *);
unsigned int get_cells(const char *string, const char delimiter[]) {
  unsigned int count, at_least_one;
  char *copy, *copy_to_free;
  copy = strdup(string);
  if (!copy)
    return 0;
  copy_to_free = copy;
  count = 0;
  at_least_one = 0;
  while (strsep(&copy, delimiter)) {
    count += 1;
  }
  free(copy_to_free);
  return count + at_least_one;
}


x86 assembly (clang, -O0):
<get_cells>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1164 <get_cells+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <get_cells+0x81>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1040 <strsep@plt>
cmp    $0x0,%rax
je     119f <get_cells+0x6f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <get_cells+0x4a>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cells>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1050 <strdup@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     117d <get_cells+0x4d>
mov    %rax,%r14
mov    $0xffffffff,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strsep@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1160 <get_cells+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    117f <get_cells+0x4f>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_cells(i8* nocapture %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @strdup(i8* %0)
store i8* %5, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %2, %7
%8 = phi i32 [ %11, %7 ], [ 0, %2 ]
%9 = call i64 @strsep(i8** %3, i8* %1)
%10 = icmp eq i64 %9, 0
%11 = add i32 %8, 1
br i1 %10, label %12, label %7
12: ; preds = %7
%13 = call i32 @free(i8* %5)
br label %14
14: ; preds = %2, %12
%15 = phi i32 [ %8, %12 ], [ 0, %2 ]
ret i32 %15
}