#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 */
scalar_t__ memcmp(char const *, char *, int);
unsigned char search_null_block(const char *in_buf, unsigned int in_buf_len,
                                unsigned int block_len, unsigned int *out_pos) {
  unsigned int pos = 0;
  unsigned int i = 0;
  for (pos = 0; pos + block_len <= in_buf_len; pos += block_len) {
    for (i = 0; i < block_len; i++) {
      if (memcmp(in_buf + pos + i, "\0", 1)) {
        i = block_len;
      } else {
        if (i == block_len - 1) {
          *out_pos = pos;
          return 1;
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<search_null_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
ja     11e1 <search_null_block+0xd1>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11ce <search_null_block+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    %rax,%rdi
mov    -0x28(%rbp),%eax
add    %rax,%rdi
lea    0xe8c(%rip),%rsi
mov    $0x1,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     1193 <search_null_block+0x83>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11bb <search_null_block+0xab>
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11b6 <search_null_block+0xa6>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movb   $0x1,-0x1(%rbp)
jmp    11e5 <search_null_block+0xd5>
jmp    11bb <search_null_block+0xab>
jmp    11c0 <search_null_block+0xb0>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1151 <search_null_block+0x41>
jmp    11d3 <search_null_block+0xc3>
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    113b <search_null_block+0x2b>
movb   $0x0,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_null_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
xor    %r15d,%r15d
mov    %esi,0x4(%rsp)
cmp    %esi,%edx
ja     11b9 <search_null_block+0xa9>
mov    %edx,%ebx
mov    %rcx,0x8(%rsp)
lea    -0x1(%rbx),%r14d
lea    0xebc(%rip),%rbp
mov    %edx,%eax
jmp    115a <search_null_block+0x4a>
nopl   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%eax
cmp    0x4(%rsp),%eax
ja     11cb <search_null_block+0xbb>
mov    %r15d,%ecx
mov    %r15d,(%rsp)
mov    %eax,%r15d
test   %ebx,%ebx
je     1150 <search_null_block+0x40>
mov    (%rsp),%r13d
add    0x10(%rsp),%r13
xor    %r12d,%r12d
jmp    118a <search_null_block+0x7a>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ecx
mov    %ecx,%r12d
cmp    %ebx,%ecx
jae    1150 <search_null_block+0x40>
mov    %r12d,%edi
add    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <memcmp@plt>
mov    %ebx,%ecx
test   %rax,%rax
jne    1180 <search_null_block+0x70>
mov    %r12d,%ecx
cmp    %r14d,%r12d
jne    1180 <search_null_block+0x70>
mov    0x8(%rsp),%rax
mov    (%rsp),%ecx
mov    %ecx,(%rax)
mov    $0x1,%r15b
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
jmp    11b9 <search_null_block+0xa9>

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
define zeroext i8 @search_null_block(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %10
br label %12
12: ; preds = %49, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %8
%15 = add i32 %13, %14
%16 = load i32, i32* %7
%17 = icmp ule i32 %15, %16
br i1 %17, label %18, label %53
18: ; preds = %12
store i32 0, i32* %11
br label %19
19: ; preds = %45, %18
%20 = load i32, i32* %11
%21 = load i32, i32* %8
%22 = icmp ult i32 %20, %21
br i1 %22, label %23, label %48
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = load i32, i32* %10
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %11
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i64 @memcmp(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = load i32, i32* %8
store i32 %34, i32* %11
br label %44
35: ; preds = %23
%36 = load i32, i32* %11
%37 = load i32, i32* %8
%38 = sub i32 %37, 1
%39 = icmp eq i32 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* %10
%42 = load i32*, i32** %9
store i32 %41, i32* %42
store i8 1, i8* %5
br label %54
43: ; preds = %35
br label %44
44: ; preds = %43, %33
br label %45
45: ; preds = %44
%46 = load i32, i32* %11
%47 = add i32 %46, 1
store i32 %47, i32* %11
br label %19
48: ; preds = %19
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = load i32, i32* %10
%52 = add i32 %51, %50
store i32 %52, i32* %10
br label %12
53: ; preds = %12
store i8 0, i8* %5
br label %54
54: ; preds = %53, %40
%55 = load i8, i8* %5
ret i8 %55
}

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
define zeroext i8 @search_null_block(i8* %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = icmp ugt i32 %2, %1
br i1 %5, label %31, label %6
6: ; preds = %4
%7 = icmp eq i32 %2, 0
%8 = add i32 %2, -1
br label %12
9: ; preds = %27, %12
%10 = add i32 %13, %2
%11 = icmp ugt i32 %10, %1
br i1 %11, label %31, label %12
12: ; preds = %6, %9
%13 = phi i32 [ %2, %6 ], [ %10, %9 ]
%14 = phi i32 [ 0, %6 ], [ %13, %9 ]
br i1 %7, label %9, label %15
15: ; preds = %12
%16 = zext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
br label %18
18: ; preds = %15, %27
%19 = phi i32 [ 0, %15 ], [ %29, %27 ]
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = tail call i64 @memcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = icmp eq i32 %19, %8
br i1 %25, label %26, label %27
26: ; preds = %24
store i32 %14, i32* %3
br label %31
27: ; preds = %18, %24
%28 = phi i32 [ %19, %24 ], [ %2, %18 ]
%29 = add i32 %28, 1
%30 = icmp ult i32 %29, %2
br i1 %30, label %18, label %9
31: ; preds = %9, %4, %26
%32 = phi i8 [ 1, %26 ], [ 0, %4 ], [ 0, %9 ]
ret i8 %32
}