#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 /*<<< orphan*/ ZERO;

/* Variables and functions */
scalar_t__ memcmp(char const *, char const *, size_t);
int fast_mem_is_zero(const char *mem, size_t len) {
  static const char ZERO[] = {
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  };
  while (len >= sizeof(ZERO)) {
    if ((memcmp((mem), (ZERO), (sizeof(ZERO)))))
      return 0;
    len -= sizeof(ZERO);
    mem += sizeof(ZERO);
  }
  if (len)
    return (0 == memcmp((mem), (ZERO), (len)));
  return 1;
}


x86 assembly (clang, -O0):
<fast_mem_is_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x20,-0x18(%rbp)
jb     1173 <fast_mem_is_zero+0x63>
mov    -0x10(%rbp),%rdi
lea    0xeca(%rip),%rsi
mov    $0x20,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     1156 <fast_mem_is_zero+0x46>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <fast_mem_is_zero+0xa1>
mov    -0x18(%rbp),%rax
sub    $0x20,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <fast_mem_is_zero+0x10>
cmpq   $0x0,-0x18(%rbp)
je     11aa <fast_mem_is_zero+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <fast_mem_is_zero+0xa1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fast_mem_is_zero>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
cmp    $0x20,%rsi
jb     1153 <fast_mem_is_zero+0x43>
lea    0xed8(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1177 <fast_mem_is_zero+0x67>
add    $0xffffffffffffffe0,%r14
add    $0x20,%rbx
cmp    $0x1f,%r14
ja     1130 <fast_mem_is_zero+0x20>
test   %r14,%r14
je     117b <fast_mem_is_zero+0x6b>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1180 <fast_mem_is_zero+0x70>
xor    %eax,%eax
jmp    1180 <fast_mem_is_zero+0x70>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@fast_mem_is_zero.ZERO = internal constant [32 x i8] zeroinitializer
define i32 @fast_mem_is_zero(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
br label %6
6: ; preds = %14, %2
%7 = load i64, i64* %5
%8 = icmp uge i64 %7, 32
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = load i8*, i8** %4
%11 = call i64 @memcmp(i8* %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @fast_mem_is_zero.ZERO, i64 0, i64 0), i64 32)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %3
br label %29
14: ; preds = %9
%15 = load i64, i64* %5
%16 = sub i64 %15, 32
store i64 %16, i64* %5
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 32
store i8* %18, i8** %4
br label %6
19: ; preds = %6
%20 = load i64, i64* %5
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = load i64, i64* %5
%25 = call i64 @memcmp(i8* %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @fast_mem_is_zero.ZERO, i64 0, i64 0), i64 %24)
%26 = icmp eq i64 0, %25
%27 = zext i1 %26 to i32
store i32 %27, i32* %3
br label %29
28: ; preds = %19
store i32 1, i32* %3
br label %29
29: ; preds = %28, %22, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@fast_mem_is_zero.ZERO = internal constant [32 x i8] zeroinitializer
define i32 @fast_mem_is_zero(i8* %0, i64 %1) {
%3 = icmp ugt i64 %1, 31
br i1 %3, label %4, label %13
4: ; preds = %2, %9
%5 = phi i64 [ %10, %9 ], [ %1, %2 ]
%6 = phi i8* [ %11, %9 ], [ %0, %2 ]
%7 = tail call i64 @memcmp(i8* %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @fast_mem_is_zero.ZERO, i64 0, i64 0), i64 32)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %4
%10 = add i64 %5, -32
%11 = getelementptr inbounds i8, i8* %6, i64 32
%12 = icmp ugt i64 %10, 31
br i1 %12, label %4, label %13
13: ; preds = %9, %2
%14 = phi i8* [ %0, %2 ], [ %11, %9 ]
%15 = phi i64 [ %1, %2 ], [ %10, %9 ]
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = tail call i64 @memcmp(i8* %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @fast_mem_is_zero.ZERO, i64 0, i64 0), i64 %15)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %4, %13, %17
%22 = phi i32 [ %20, %17 ], [ 1, %13 ], [ 0, %4 ]
ret i32 %22
}