#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 find_min_element_rotated(int *, int);
int /*<<< orphan*/ generate_list(int *, int);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ rotate_left(int *, int, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int sz = 10;
  int array[10];
  int k;
  srand(time(NULL));
  printf("original list:\n");
  generate_list(array, sz);
  print_array(array, sz);
  k = rand() % (sz * 2);
  printf("list rotated by %d:\n", k);
  rotate_left(array, sz, k);
  print_array(array, sz);
  k = find_min_element_rotated(array, sz);
  printf("\nsmallest item is: %d\nat position %d\n", array[k], k);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <generate_list@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <print_array@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1090 <rotate_left@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <print_array@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <find_min_element_rotated@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
mov    -0x34(%rbp),%edx
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <generate_list@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <print_array@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
shl    $0x2,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
lea    0xe05(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
call   10a0 <rotate_left@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <print_array@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <find_min_element_rotated@plt>
movslq %eax,%rdx
mov    (%rsp,%rdx,4),%esi
lea    0xddb(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"original list:\0A\00"
@.str.1 = [21 x i8] c"list rotated by %d:\0A\00"
@.str.2 = [38 x i8] c"\0Asmallest item is: %d\0Aat position %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @generate_list(i32* %8, i32 %9)
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @print_array(i32* %11, i32 %12)
%14 = call i32 (...) @rand()
%15 = load i32, i32* %2
%16 = mul nsw i32 %15, 2
%17 = srem i32 %14, %16
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = call i32 @rotate_left(i32* %20, i32 %21, i32 %22)
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%25 = load i32, i32* %2
%26 = call i32 @print_array(i32* %24, i32 %25)
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%28 = load i32, i32* %2
%29 = call i32 @find_min_element_rotated(i32* %27, i32 %28)
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"list rotated by %d:\0A\00"
@.str.2 = [38 x i8] c"\0Asmallest item is: %d\0Aat position %d\0A\00"
@str = [15 x i8] c"original list:\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%7 = call i32 @generate_list(i32* %6, i32 10)
%8 = call i32 @print_array(i32* %6, i32 10)
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 20
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @rotate_left(i32* %6, i32 10, i32 %10)
%13 = call i32 @print_array(i32* %6, i32 10)
%14 = call i32 @find_min_element_rotated(i32* %6, i32 10)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %14)
ret i32 0
}