#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 findRoateIndex(int *, int /*<<< orphan*/, int);
int search(int *nums, int numsSize, int target) {
  int roateIndex = findRoateIndex(nums, 0, numsSize - 1);
  if (roateIndex == -1) {
    return binarySearch(nums, 0, numsSize - 1, target);
  }
  int result = binarySearch(nums, 0, roateIndex, target);
  if (result == -1) {
    result = binarySearch(nums, roateIndex + 1, numsSize - 1, target);
  }
  return result;
}


x86 assembly (clang, -O0):
<search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <findRoateIndex@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    116c <search+0x4c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%ecx
xor    %esi,%esi
call   1040 <binarySearch@plt>
mov    %eax,-0x4(%rbp)
jmp    11ab <search+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
xor    %esi,%esi
call   1040 <binarySearch@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11a5 <search+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1040 <binarySearch@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
add    $0xffffffff,%ebp
xor    %r12d,%r12d
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <findRoateIndex@plt>
cmp    $0xffffffff,%eax
je     1169 <search+0x49>
mov    %eax,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%edx
mov    %r14d,%ecx
call   1040 <binarySearch@plt>
cmp    $0xffffffff,%eax
je     1163 <search+0x43>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%ebx
mov    %ebx,%r12d
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <binarySearch@plt>

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

LLVM IR (-O2):
define i32 @search(i32* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %1, -1
%5 = tail call i32 @findRoateIndex(i32* %0, i32 0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = tail call i32 @binarySearch(i32* %0, i32 0, i32 %5, i32 %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = add nuw nsw i32 %5, 1
br label %12
12: ; preds = %3, %10
%13 = phi i32 [ %11, %10 ], [ 0, %3 ]
%14 = tail call i32 @binarySearch(i32* %0, i32 %13, i32 %4, i32 %2)
br label %15
15: ; preds = %12, %7
%16 = phi i32 [ %8, %7 ], [ %14, %12 ]
ret i32 %16
}