#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_starting_index(int, int *, int, int);
int rewind_window_end_to_last_snp_with_start_end_index(
    int window_end_coordinate, int *snp_locations, char *child_sequence,
    int number_of_branch_snps, int start_index, int end_index) {
  int i = 0;
  if (window_end_coordinate == 0) {
    return 0;
  }
  end_index = find_starting_index(window_end_coordinate, snp_locations,
                                  start_index, end_index);
  if (end_index + 1 < number_of_branch_snps) {
    end_index++;
  }
  for (i = end_index; i >= 0; i--) {
    if (snp_locations[i] <= window_end_coordinate && child_sequence[i] != '-' &&
        child_sequence[i] != 'N') {
      return (snp_locations[i]);
    }
  }
  return window_end_coordinate;
}


x86 assembly (clang, -O0):
<rewind_window_end_to_last_snp_with_start_end_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    114b <rewind_window_end_to_last_snp_with_start_end_index+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <rewind_window_end_to_last_snp_with_start_end_index+0xe2>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1030 <find_starting_index@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jge    1178 <rewind_window_end_to_last_snp_with_start_end_index+0x68>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     11ec <rewind_window_end_to_last_snp_with_start_end_index+0xdc>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
jg     11d9 <rewind_window_end_to_last_snp_with_start_end_index+0xc9>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     11d9 <rewind_window_end_to_last_snp_with_start_end_index+0xc9>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4e,%eax
je     11d9 <rewind_window_end_to_last_snp_with_start_end_index+0xc9>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <rewind_window_end_to_last_snp_with_start_end_index+0xe2>
jmp    11de <rewind_window_end_to_last_snp_with_start_end_index+0xce>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    117e <rewind_window_end_to_last_snp_with_start_end_index+0x6e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewind_window_end_to_last_snp_with_start_end_index>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     1175 <rewind_window_end_to_last_snp_with_start_end_index+0x65>
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    %r8d,%edx
mov    %r9d,%ecx
call   1030 <find_starting_index@plt>
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
cmovl  %ecx,%eax
test   %eax,%eax
js     1171 <rewind_window_end_to_last_snp_with_start_end_index+0x61>
mov    %eax,%ecx
add    $0x1,%rcx
jmp    1156 <rewind_window_end_to_last_snp_with_start_end_index+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rcx
jle    1171 <rewind_window_end_to_last_snp_with_start_end_index+0x61>
mov    -0x4(%r15,%rcx,4),%eax
cmp    %ebx,%eax
jg     1150 <rewind_window_end_to_last_snp_with_start_end_index+0x40>
movzbl -0x1(%r14,%rcx,1),%edx
cmp    $0x4e,%dl
je     1150 <rewind_window_end_to_last_snp_with_start_end_index+0x40>
cmp    $0x2d,%dl
je     1150 <rewind_window_end_to_last_snp_with_start_end_index+0x40>
jmp    1177 <rewind_window_end_to_last_snp_with_start_end_index+0x67>
mov    %ebx,%eax
jmp    1177 <rewind_window_end_to_last_snp_with_start_end_index+0x67>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rewind_window_end_to_last_snp_with_start_end_index(i32 %0, i32* %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %8
store i32* %1, i32** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 0, i32* %14
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %6
store i32 0, i32* %7
br label %72
18: ; preds = %6
%19 = load i32, i32* %8
%20 = load i32*, i32** %9
%21 = load i32, i32* %12
%22 = load i32, i32* %13
%23 = call i32 @find_starting_index(i32 %19, i32* %20, i32 %21, i32 %22)
store i32 %23, i32* %13
%24 = load i32, i32* %13
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %11
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load i32, i32* %13
%30 = add nsw i32 %29, 1
store i32 %30, i32* %13
br label %31
31: ; preds = %28, %18
%32 = load i32, i32* %13
store i32 %32, i32* %14
br label %33
33: ; preds = %67, %31
%34 = load i32, i32* %14
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %70
36: ; preds = %33
%37 = load i32*, i32** %9
%38 = load i32, i32* %14
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %8
%43 = icmp sle i32 %41, %42
br i1 %43, label %44, label %66
44: ; preds = %36
%45 = load i8*, i8** %10
%46 = load i32, i32* %14
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 45
br i1 %51, label %52, label %66
52: ; preds = %44
%53 = load i8*, i8** %10
%54 = load i32, i32* %14
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 78
br i1 %59, label %60, label %66
60: ; preds = %52
%61 = load i32*, i32** %9
%62 = load i32, i32* %14
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
store i32 %65, i32* %7
br label %72
66: ; preds = %52, %44, %36
br label %67
67: ; preds = %66
%68 = load i32, i32* %14
%69 = add nsw i32 %68, -1
store i32 %69, i32* %14
br label %33
70: ; preds = %33
%71 = load i32, i32* %8
store i32 %71, i32* %7
br label %72
72: ; preds = %70, %60, %17
%73 = load i32, i32* %7
ret i32 %73
}

LLVM IR (-O2):
define i32 @rewind_window_end_to_last_snp_with_start_end_index(i32 %0, i32* %1, i8* nocapture %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp eq i32 %0, 0
br i1 %7, label %27, label %8
8: ; preds = %6
%9 = tail call i32 @find_starting_index(i32 %0, i32* %1, i32 %4, i32 %5)
%10 = add nsw i32 %9, 1
%11 = icmp slt i32 %10, %3
%12 = select i1 %11, i32 %10, i32 %9
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %27
14: ; preds = %8
%15 = zext i32 %12 to i64
br label %16
16: ; preds = %14, %24
%17 = phi i64 [ %15, %14 ], [ %25, %24 ]
%18 = getelementptr inbounds i32, i32* %1, i64 %17
%19 = load i32, i32* %18
%20 = icmp sgt i32 %19, %0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %2, i64 %17
%23 = load i8, i8* %22
switch i8 %23, label %27 [
i8 45, label %24
i8 78, label %24
]
24: ; preds = %21, %21, %16
%25 = add nsw i64 %17, -1
%26 = icmp sgt i64 %17, 0
br i1 %26, label %16, label %27
27: ; preds = %21, %24, %8, %6
%28 = phi i32 [ 0, %6 ], [ %0, %8 ], [ %19, %21 ], [ %0, %24 ]
ret i32 %28
}