#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 int64_t;

/* Variables and functions */
int /*<<< orphan*/ __asan_region_bounds(void *, void **, size_t *);
int64_t __asan_strlen(const char *str) {
  void *base;
  size_t size;
  if (!__asan_region_bounds((void *)str, &base, &size))
    return -1;
  const char *end = base + size;
  size_t result = 0;
  for (const char *ptr = str; ptr != end; ++ptr) {
    if (*ptr == '\0')
      return result;
    result++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<__asan_strlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <__asan_region_bounds@plt>
cmp    $0x0,%eax
jne    1142 <__asan_strlen+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <__asan_strlen+0x9c>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11a5 <__asan_strlen+0x95>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1188 <__asan_strlen+0x78>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11ac <__asan_strlen+0x9c>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    115e <__asan_strlen+0x4e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__asan_strlen>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <__asan_region_bounds@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     115b <__asan_strlen+0x4b>
mov    0x8(%rsp),%rcx
add    (%rsp),%rcx
cmp    %rbx,%rcx
je     115b <__asan_strlen+0x4b>
xor    %edx,%edx
cmpb   $0x0,(%rbx,%rdx,1)
je     1159 <__asan_strlen+0x49>
lea    (%rbx,%rdx,1),%rsi
add    $0x1,%rsi
add    $0x1,%rdx
cmp    %rcx,%rsi
jne    1140 <__asan_strlen+0x30>
jmp    115b <__asan_strlen+0x4b>
mov    %edx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @__asan_strlen(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = call i32 @__asan_region_bounds(i8* %0, i8** %2, i64* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i64, i64* %3
%11 = getelementptr i8, i8* %9, i64 %10
%12 = icmp eq i8* %11, %0
br i1 %12, label %24, label %13
13: ; preds = %8, %20
%14 = phi i8* [ %22, %20 ], [ %0, %8 ]
%15 = phi i64 [ %21, %20 ], [ 0, %8 ]
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = trunc i64 %15 to i32
br label %24
20: ; preds = %13
%21 = add i64 %15, 1
%22 = getelementptr inbounds i8, i8* %14, i64 1
%23 = icmp eq i8* %22, %11
br i1 %23, label %24, label %13
24: ; preds = %20, %8, %18, %1
%25 = phi i32 [ -1, %1 ], [ %19, %18 ], [ -1, %8 ], [ -1, %20 ]
ret i32 %25
}