#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 */
typedef int uint64_t;

/* Variables and functions */
int __insn_ctz(int);
int __insn_shl(unsigned long long, uintptr_t const);
int __insn_v1cmpeqi(int, int /*<<< orphan*/);
size_t strlen(const char *s) {
  const uintptr_t s_int = (uintptr_t)s;
  const uint64_t *p = (const uint64_t *)(s_int & -8);
  uint64_t v = *p | (__insn_shl(1ULL, (s_int << 3)) - 1);
  uint64_t bits;
  while ((bits = __insn_v1cmpeqi(v, 0)) == 0)
    v = *++p;
  return ((const char *)p) + (__insn_ctz(bits) >> 3) - s;
}


x86 assembly (clang, -O0):
<strlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0xfffffffffffffff8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rsi
shl    $0x3,%rsi
mov    $0x1,%edi
call   1040 <__insn_shl@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1050 <__insn_v1cmpeqi@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    11a8 <strlen+0x78>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    0x4(%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <strlen+0x48>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <__insn_ctz@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sar    $0x3,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strlen>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rdi,%rbx
and    $0xfffffffffffffff8,%rbx
mov    (%rbx),%ebp
lea    0x0(,%rdi,8),%rsi
mov    $0x1,%edi
call   1040 <__insn_shl@plt>
lea    -0x1(%rax),%edi
or     %ebp,%edi
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
call   1050 <__insn_v1cmpeqi@plt>
test   %eax,%eax
jne    1174 <strlen+0x44>
mov    0x4(%rbx),%edi
add    $0x4,%rbx
jmp    1160 <strlen+0x30>
mov    %eax,%edi
call   1030 <__insn_ctz@plt>
sar    $0x3,%eax
cltq
add    %rbx,%rax
sub    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @strlen(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = ptrtoint i8* %7 to i64
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = and i64 %9, -8
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = load i32, i32* %12
%14 = load i64, i64* %3
%15 = shl i64 %14, 3
%16 = call i32 @__insn_shl(i64 1, i64 %15)
%17 = sub nsw i32 %16, 1
%18 = or i32 %13, %17
store i32 %18, i32* %5
br label %19
19: ; preds = %23, %1
%20 = load i32, i32* %5
%21 = call i32 @__insn_v1cmpeqi(i32 %20, i32 0)
store i32 %21, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32*, i32** %4
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %4
%26 = load i32, i32* %25
store i32 %26, i32* %5
br label %19
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = bitcast i32* %28 to i8*
%30 = load i32, i32* %6
%31 = call i32 @__insn_ctz(i32 %30)
%32 = ashr i32 %31, 3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
%35 = load i8*, i8** %2
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
ret i64 %38
}

LLVM IR (-O2):
define i64 @strlen(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = and i64 %2, -8
%4 = inttoptr i64 %3 to i32*
%5 = load i32, i32* %4
%6 = shl i64 %2, 3
%7 = tail call i32 @__insn_shl(i64 1, i64 %6)
%8 = add nsw i32 %7, -1
%9 = or i32 %8, %5
%10 = tail call i32 @__insn_v1cmpeqi(i32 %9, i32 0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1, %12
%13 = phi i32* [ %14, %12 ], [ %4, %1 ]
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = load i32, i32* %14
%16 = tail call i32 @__insn_v1cmpeqi(i32 %15, i32 0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %12, label %18
18: ; preds = %12, %1
%19 = phi i32* [ %4, %1 ], [ %14, %12 ]
%20 = phi i32 [ %10, %1 ], [ %16, %12 ]
%21 = bitcast i32* %19 to i8*
%22 = tail call i32 @__insn_ctz(i32 %20)
%23 = ashr i32 %22, 3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = ptrtoint i8* %25 to i64
%27 = sub i64 %26, %2
ret i64 %27
}