#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 binarySearch(int, int *, int, int);
int binarySearchMin(int *, int /*<<< orphan*/, int);
int searchRotatedArray(int target, int *arr, int arrLen) {
  int minIdx = binarySearchMin(arr, 0, arrLen - 1);
  if ((target >= arr[0]) && (arr[0] > arr[minIdx])) {
    return binarySearch(target, arr, 0, minIdx - 1);
  } else {
    return binarySearch(target, arr, minIdx, arrLen - 1);
  }
}


x86 assembly (clang, -O0):
<searchRotatedArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <binarySearchMin@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jl     1188 <searchRotatedArray+0x68>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1188 <searchRotatedArray+0x68>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
call   1040 <binarySearch@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <searchRotatedArray+0x80>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
call   1040 <binarySearch@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchRotatedArray>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
add    $0xffffffff,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <binarySearchMin@plt>
mov    (%rbx),%ecx
cmp    %r14d,%ecx
jg     1159 <searchRotatedArray+0x39>
movslq %eax,%rdx
cmp    (%rbx,%rdx,4),%ecx
jle    1159 <searchRotatedArray+0x39>
add    $0xffffffff,%eax
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %eax,%ecx
jmp    1163 <searchRotatedArray+0x43>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <binarySearch@plt>

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

LLVM IR (-O2):
define i32 @searchRotatedArray(i32 %0, i32* %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = tail call i32 @binarySearchMin(i32* %1, i32 0, i32 %4)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, %0
br i1 %7, label %16, label %8
8: ; preds = %3
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = icmp sgt i32 %6, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = add nsw i32 %5, -1
%15 = tail call i32 @binarySearch(i32 %0, i32* %1, i32 0, i32 %14)
br label %18
16: ; preds = %8, %3
%17 = tail call i32 @binarySearch(i32 %0, i32* %1, i32 %5, i32 %4)
br label %18
18: ; preds = %16, %13
%19 = phi i32 [ %15, %13 ], [ %17, %16 ]
ret i32 %19
}