#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 uint64_t;
typedef scalar_t__ int64_t;

/* Variables and functions */
int64_t contains0_sorted_rec(int64_t *arr, uint64_t len) {
  if (len == 0) {
    return 0;
  } else if (len == 1) {
    return arr[0] == 0 ? 1 : 0;
  } else {
    uint64_t halfway = len / 2;
    if (arr[halfway] > 0) {
      return contains0_sorted_rec(arr, halfway);
    } else {
      return contains0_sorted_rec(arr + halfway, len - halfway);
    }
  }
}


x86 assembly (clang, -O0):
<contains0_sorted_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1136 <contains0_sorted_rec+0x26>
movq   $0x0,-0x8(%rbp)
jmp    11b4 <contains0_sorted_rec+0xa4>
cmpl   $0x1,-0x14(%rbp)
jne    1160 <contains0_sorted_rec+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    11b4 <contains0_sorted_rec+0xa4>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jle    1196 <contains0_sorted_rec+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <contains0_sorted_rec@plt>
mov    %rax,-0x8(%rbp)
jmp    11b4 <contains0_sorted_rec+0xa4>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
call   1030 <contains0_sorted_rec@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contains0_sorted_rec>:
test   %esi,%esi
je     1128 <contains0_sorted_rec+0x28>
mov    %esi,%eax
cmp    $0x1,%esi
je     112b <contains0_sorted_rec+0x2b>
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
movslq %esi,%rcx
cmpq   $0x0,(%rdi,%rcx,8)
jg     1100 <contains0_sorted_rec>
lea    (%rdi,%rcx,8),%rdi
sub    %ecx,%eax
mov    %eax,%esi
jmp    1100 <contains0_sorted_rec>
xor    %eax,%eax
ret
xor    %eax,%eax
cmpq   $0x0,(%rdi)
sete   %al
ret

LLVM IR (-O0):
define i64 @contains0_sorted_rec(i64* %0, i32 %1) {
%3 = alloca i64
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
store i64* %0, i64** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i64 0, i64* %3
br label %43
10: ; preds = %2
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i64*, i64** %4
%15 = getelementptr inbounds i64, i64* %14, i64 0
%16 = load i64, i64* %15
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 1, i32 0
%20 = sext i32 %19 to i64
store i64 %20, i64* %3
br label %43
21: ; preds = %10
%22 = load i32, i32* %5
%23 = sdiv i32 %22, 2
store i32 %23, i32* %6
%24 = load i64*, i64** %4
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i64, i64* %24, i64 %26
%28 = load i64, i64* %27
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %21
%31 = load i64*, i64** %4
%32 = load i32, i32* %6
%33 = call i64 @contains0_sorted_rec(i64* %31, i32 %32)
store i64 %33, i64* %3
br label %43
34: ; preds = %21
%35 = load i64*, i64** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i64, i64* %35, i64 %37
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = sub nsw i32 %39, %40
%42 = call i64 @contains0_sorted_rec(i64* %38, i32 %41)
store i64 %42, i64* %3
br label %43
43: ; preds = %34, %30, %13, %9
%44 = load i64, i64* %3
ret i64 %44
}

LLVM IR (-O2):
define i64 @contains0_sorted_rec(i64* %0, i32 %1) {
br label %6
3: ; preds = %15
%4 = getelementptr inbounds i64, i64* %7, i64 %17
%5 = sub nsw i32 %10, %16
br label %6
6: ; preds = %3, %2
%7 = phi i64* [ %0, %2 ], [ %4, %3 ]
%8 = phi i32 [ %1, %2 ], [ %5, %3 ]
br label %9
9: ; preds = %15, %6
%10 = phi i32 [ %8, %6 ], [ %16, %15 ]
switch i32 %10, label %15 [
i32 0, label %21
i32 1, label %11
]
11: ; preds = %9
%12 = load i64, i64* %7
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i64
br label %21
15: ; preds = %9
%16 = sdiv i32 %10, 2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %7, i64 %17
%19 = load i64, i64* %18
%20 = icmp sgt i64 %19, 0
br i1 %20, label %9, label %3
21: ; preds = %9, %11
%22 = phi i64 [ %14, %11 ], [ 0, %9 ]
ret i64 %22
}