#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rotate_array(int *, int);
int search(int *, int, int);
int test_case(int *nums, int len, int target) {
  int i, j, ret;
  for (i = 0; i < len; i++) {
    rotate_array(nums, len);
    printf("search %d in ", target);
    for (j = 0; j < len; j++) {
      printf("%*d ", 2, nums[j]);
    }
    ret = search(nums, len, target);
    if (ret == -1) {
      printf("not found\n");
    } else {
      printf(", found at %d\n", search(nums, len, target));
    }
  }
}


x86 assembly (clang, -O0):
<test_case>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1212 <test_case+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <rotate_array@plt>
mov    -0x18(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b1 <test_case+0x81>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe77(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1179 <test_case+0x49>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <search@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11e0 <test_case+0xb0>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ff <test_case+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <search@plt>
mov    %eax,%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1204 <test_case+0xd4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <test_case+0x19>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_case>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1206 <test_case+0xc6>
mov    %edx,%r14d
mov    %rdi,%rbx
mov    %esi,%r13d
lea    0xeab(%rip),%rbp
xor    %r15d,%r15d
mov    %edx,0x4(%rsp)
jmp    119a <test_case+0x5a>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1060 <search@plt>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%esi
add    $0x1,%r15d
cmp    %r12d,%r15d
je     1206 <test_case+0xc6>
mov    %rbx,%rdi
mov    %esi,%r12d
call   1030 <rotate_array@plt>
lea    0xe54(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    (%rbx,%r14,4),%edx
mov    %rbp,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    11c0 <test_case+0x80>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    0x4(%rsp),%r14d
mov    %r14d,%edx
call   1060 <search@plt>
cmp    $0xffffffff,%eax
jne    1170 <test_case+0x30>
lea    0xe23(%rip),%rdi
call   1040 <puts@plt>
jmp    118e <test_case+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"search %d in \00"
@.str.1 = [5 x i8] c"%*d \00"
@.str.2 = [11 x i8] c"not found\0A\00"
@.str.3 = [15 x i8] c", found at %d\0A\00"
define i32 @test_case(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %51, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %54
15: ; preds = %11
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = call i32 @rotate_array(i32* %16, i32 %17)
%19 = load i32, i32* %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 0, i32* %9
br label %21
21: ; preds = %32, %15
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %30)
br label %32
32: ; preds = %25
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %21
35: ; preds = %21
%36 = load i32*, i32** %5
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = call i32 @search(i32* %36, i32 %37, i32 %38)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %50
44: ; preds = %35
%45 = load i32*, i32** %5
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = call i32 @search(i32* %45, i32 %46, i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %44, %42
br label %51
51: ; preds = %50
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %11
54: ; preds = %11
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [14 x i8] c"search %d in \00"
@.str.1 = [5 x i8] c"%*d \00"
@.str.3 = [15 x i8] c", found at %d\0A\00"
@str = [10 x i8] c"not found\00"
define i32 @test_case(i32* %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %29
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %26, %5
%8 = phi i32 [ 0, %5 ], [ %27, %26 ]
%9 = tail call i32 @rotate_array(i32* %0, i32 %1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %16, %11 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %14)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = tail call i32 @search(i32* %0, i32 %1, i32 %2)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %26
23: ; preds = %18
%24 = tail call i32 @search(i32* %0, i32 %1, i32 %2)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %21, %23
%27 = add nuw nsw i32 %8, 1
%28 = icmp eq i32 %27, %1
br i1 %28, label %29, label %7
29: ; preds = %26, %3
ret i32 undef
}