#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*/ assert(char **);
size_t mx_strvec_length_cache(char **, size_t);
size_t mx_strvec_length(char **strvec) {
  char **sv;
  size_t len;
  assert(strvec);
  sv = strvec;
  len = mx_strvec_length_cache(sv, -1);
  if (len != -1)
    return len;
  for (; *sv; sv++)
    ;
  len = sv - strvec;
  mx_strvec_length_cache(sv, len);
  return len;
}


x86 assembly (clang, -O0):
<mx_strvec_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
call   1040 <mx_strvec_length_cache@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
je     1169 <mx_strvec_length+0x49>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mx_strvec_length+0x9a>
jmp    116e <mx_strvec_length+0x4e>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1192 <mx_strvec_length+0x72>
jmp    1181 <mx_strvec_length+0x61>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <mx_strvec_length+0x4e>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <mx_strvec_length_cache@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mx_strvec_length>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <assert@plt>
mov    %r14,%rdi
mov    $0xffffffffffffffff,%rsi
call   1040 <mx_strvec_length_cache@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
jne    116e <mx_strvec_length+0x4e>
add    $0xfffffffffffffff8,%r14
mov    $0xfffffffffffffff8,%rbx
nop
add    $0x8,%rbx
cmpq   $0x0,0x8(%r14)
lea    0x8(%r14),%r14
jne    1150 <mx_strvec_length+0x30>
sar    $0x3,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <mx_strvec_length_cache@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i64 @mx_strvec_length(i8** %0) {
%2 = tail call i32 @assert(i8** %0)
%3 = tail call i64 @mx_strvec_length_cache(i8** %0, i64 -1)
%4 = icmp eq i64 %3, -1
br i1 %4, label %5, label %16
5: ; preds = %1, %5
%6 = phi i8** [ %9, %5 ], [ %0, %1 ]
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
%9 = getelementptr inbounds i8*, i8** %6, i64 1
br i1 %8, label %10, label %5
10: ; preds = %5
%11 = ptrtoint i8** %6 to i64
%12 = ptrtoint i8** %0 to i64
%13 = sub i64 %11, %12
%14 = ashr exact i64 %13, 3
%15 = tail call i64 @mx_strvec_length_cache(i8** %6, i64 %14)
br label %16
16: ; preds = %1, %10
%17 = phi i64 [ %14, %10 ], [ %3, %1 ]
ret i64 %17
}