#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 *ft_next(char const *, char, int);
int ft_len(char const *s, char c) {
  int i;
  i = 0;
  while (*s != '\0') {
    s = ft_next(s, c, 1);
    if (*s != '\0') {
      i++;
      s = ft_next(s, c, 0);
    }
  }
  return (i);
}


x86 assembly (clang, -O0):
<ft_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1180 <ft_len+0x70>
mov    -0x8(%rbp),%rdi
mov    $0x1,%edx
movsbl -0x9(%rbp),%esi
call   1030 <ft_next@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117b <ft_len+0x6b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %edx,%edx
movsbl -0x9(%rbp),%esi
call   1030 <ft_next@plt>
mov    %rax,-0x8(%rbp)
jmp    1129 <ft_len+0x19>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_len>:
push   %rbp
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     115a <ft_len+0x4a>
mov    %rdi,%rax
xor    %ebx,%ebx
movsbl %sil,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1030 <ft_next@plt>
cmpb   $0x0,(%rax)
je     115c <ft_len+0x4c>
add    $0x1,%ebx
mov    %rax,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1030 <ft_next@plt>
cmpb   $0x0,(%rax)
jne    1130 <ft_len+0x20>
jmp    115c <ft_len+0x4c>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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