#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 ssize_t;

/* Variables and functions */
int find_on_rotated(int *, size_t, int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, ...);
int main(void) {
  printf("Enter size of array, followed by the array elements, "
         "followed by the element to find.\n");
  size_t arr_sz;
  while (scanf("%zu", &arr_sz) == 1) {
    int arr[arr_sz];
    size_t i;
    for (i = 0; i < arr_sz; i++) {
      scanf("%d", &arr[i]);
    }
    int to_find;
    scanf("%d", &to_find);
    ssize_t res = find_on_rotated(arr, arr_sz, to_find);
    if (res == -1) {
      printf("Element not found.\n");
    } else {
      printf("%d found at i = %zd\n", to_find, res);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf03(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1236 <main+0x106>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d4 <main+0xa4>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1198 <main+0x68>
lea    0xe80(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <find_on_rotated@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1216 <main+0xe6>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122a <main+0xfa>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    114d <main+0x1d>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec4(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9c(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1242 <main+0x102>
lea    0xe85(%rip),%rbx
jmp    11c1 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    -0x34(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rsp
lea    0xe53(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1242 <main+0x102>
mov    %rsp,%r12
mov    -0x30(%rbp),%rax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmpq   $0x0,-0x30(%rbp)
je     120b <main+0xcb>
mov    %r14,%r15
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r13
add    $0x4,%r15
cmp    -0x30(%rbp),%r13
jb     11f0 <main+0xb0>
mov    %rbx,%rdi
lea    -0x34(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    %r14,%rdi
call   1030 <find_on_rotated@plt>
cmp    $0xffffffff,%eax
jne    1190 <main+0x50>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
jmp    11a3 <main+0x63>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [87 x i8] c"Enter size of array, followed by the array elements, followed by the element to find.\0A\00"
@.str.1 = [4 x i8] c"%zu\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [20 x i8] c"Element not found.\0A\00"
@.str.4 = [21 x i8] c"%d found at i = %zd\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %40, %0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %42
12: ; preds = %9
%13 = load i64, i64* %2
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i32, i64 %13
store i64 %13, i64* %4
store i64 0, i64* %5
br label %16
16: ; preds = %24, %12
%17 = load i64, i64* %5
%18 = load i64, i64* %2
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i64, i64* %5
%22 = getelementptr inbounds i32, i32* %15, i64 %21
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %20
%25 = load i64, i64* %5
%26 = add i64 %25, 1
store i64 %26, i64* %5
br label %16
27: ; preds = %16
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%29 = load i64, i64* %2
%30 = load i32, i32* %6
%31 = call i32 @find_on_rotated(i32* %15, i64 %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %40
36: ; preds = %27
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32 %38)
br label %40
40: ; preds = %36, %34
%41 = load i8*, i8** %3
br label %9
42: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%zu\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [21 x i8] c"%d found at i = %zd\0A\00"
@str = [86 x i8] c"Enter size of array, followed by the array elements, followed by the element to find.\00"
@str.5 = [19 x i8] c"Element not found.\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i32
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @str, i64 0, i64 0))
%4 = bitcast i64* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %36
7: ; preds = %0
%8 = bitcast i32* %2 to i8*
br label %9
9: ; preds = %7, %33
%10 = load i64, i64* %1
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = load i64, i64* %1
%14 = icmp eq i64 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %9, %15
%16 = phi i64 [ %19, %15 ], [ 0, %9 ]
%17 = getelementptr inbounds i32, i32* %12, i64 %16
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %17)
%19 = add nuw i64 %16, 1
%20 = load i64, i64* %1
%21 = icmp ult i64 %19, %20
br i1 %21, label %15, label %22
22: ; preds = %15, %9
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%24 = load i64, i64* %1
%25 = load i32, i32* %2
%26 = call i32 @find_on_rotated(i32* %12, i64 %24, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
br label %33
30: ; preds = %22
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 %26)
br label %33
33: ; preds = %30, %28
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%35 = icmp eq i32 %34, 1
br i1 %35, label %9, label %36
36: ; preds = %33, %0
ret i32 0
}