#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 */
size_t strlen(char *);
size_t strListBlockLength(char *block) {
  char *p = block;
  size_t str_len;
  size_t block_len = 0;
  if (block == NULL)
    return (0);
  while ((str_len = strlen(p)) != 0) {
    block_len += (str_len + 1);
    p += (str_len + 1);
  }
  if (!block_len)
    block_len = 1;
  block_len++;
  return (block_len);
}


x86 assembly (clang, -O0):
<strListBlockLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <strListBlockLength+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11ac <strListBlockLength+0x9c>
jmp    1149 <strListBlockLength+0x39>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1185 <strListBlockLength+0x75>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1149 <strListBlockLength+0x39>
cmpq   $0x0,-0x28(%rbp)
jne    1198 <strListBlockLength+0x88>
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strListBlockLength>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1156 <strListBlockLength+0x46>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     115b <strListBlockLength+0x4b>
xor    %r14d,%r14d
nopl   0x0(%rax)
add    %rax,%r14
add    $0x1,%r14
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jne    1130 <strListBlockLength+0x20>
test   %r14,%r14
je     115b <strListBlockLength+0x4b>
add    $0x1,%r14
jmp    1161 <strListBlockLength+0x51>
xor    %r14d,%r14d
jmp    1161 <strListBlockLength+0x51>
mov    $0x2,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i64 @strListBlockLength(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %13, %6 ], [ %4, %3 ]
%8 = phi i64 [ %11, %6 ], [ 0, %3 ]
%9 = phi i8* [ %12, %6 ], [ %0, %3 ]
%10 = add i64 %7, 1
%11 = add i64 %10, %8
%12 = getelementptr inbounds i8, i8* %9, i64 %10
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = icmp eq i64 %11, 0
%17 = add i64 %11, 1
br i1 %16, label %18, label %19
18: ; preds = %3, %15
br label %19
19: ; preds = %18, %15, %1
%20 = phi i64 [ 0, %1 ], [ 2, %18 ], [ %17, %15 ]
ret i64 %20
}