int find_start_of_right_subsequence(int *arr, int len) {
  int c;
  for (c = len - 1; c >= 0; c--) {
    if (arr[c] < arr[c - 1])
      return c + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_start_of_right_subsequence>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1160 <find_start_of_right_subsequence+0x60>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    114d <find_start_of_right_subsequence+0x4d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1167 <find_start_of_right_subsequence+0x67>
jmp    1152 <find_start_of_right_subsequence+0x52>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1114 <find_start_of_right_subsequence+0x14>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_start_of_right_subsequence>:
movslq %esi,%rcx
lea    0x1(%rcx),%eax
cs nopw 0x0(%rax,%rax,1)
test   %rcx,%rcx
jle    112b <find_start_of_right_subsequence+0x2b>
lea    -0x1(%rcx),%rdx
mov    %edx,%esi
mov    (%rdi,%rsi,4),%esi
add    $0xffffffff,%eax
cmp    -0x8(%rdi,%rcx,4),%esi
mov    %rdx,%rcx
jge    1110 <find_start_of_right_subsequence+0x10>
ret
xor    %eax,%eax
ret

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

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