#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 get_window_end_coordinates_excluding_gaps_with_start_end_index(
    int window_start_coordinate, int window_size, int *snp_locations,
    char *child_sequence, int number_of_snps, int start_index, int end_index) {
  int i;
  int window_end_coordinate = window_start_coordinate + window_size;
  start_index = find_starting_index(window_start_coordinate, snp_locations,
                                    start_index, end_index);
  int last_snp_location = 0;
  for (i = start_index; i < number_of_snps; i++) {
    if (snp_locations[i] >= window_start_coordinate &&
        snp_locations[i] < window_end_coordinate) {
      last_snp_location = i;
      if (child_sequence[i] == '-' || child_sequence[i] == 'N') {
        window_end_coordinate++;
      }
    }
    if (snp_locations[i] > window_end_coordinate) {
      break;
    }
  }
  if (last_snp_location > 0) {
    return snp_locations[last_snp_location] + 1;
  } else {
    return window_end_coordinate;
  }
}


x86 assembly (clang, -O0):
<get_window_end_coordinates_excluding_gaps_with_start_end_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    0x10(%rbp),%ecx
call   1030 <find_starting_index@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11fa <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xea>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
jl     11ce <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xbe>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x30(%rbp),%eax
jge    11ce <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xbe>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     11c0 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xb0>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4e,%eax
jne    11c9 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xb9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ce <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xbe>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x30(%rbp),%eax
jle    11e7 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xd7>
jmp    11fa <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xea>
jmp    11ec <get_window_end_coordinates_excluding_gaps_with_start_end_index+0xdc>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115c <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x4c>
cmpl   $0x0,-0x34(%rbp)
jle    121a <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x10a>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x110>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_window_end_coordinates_excluding_gaps_with_start_end_index>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r12d
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x30(%rsp),%ecx
add    %edi,%ebx
mov    %rdx,%rsi
mov    %r9d,%edx
call   1030 <find_starting_index@plt>
cmp    %r12d,%eax
jge    1192 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x82>
movslq %eax,%rdx
movslq %r12d,%rsi
add    $0x1,%rdx
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
mov    -0x4(%r14,%rdx,4),%edi
cmp    %ebp,%edi
jl     1172 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x62>
cmp    %ebx,%edi
jge    1172 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x62>
movzbl -0x1(%r15,%rdx,1),%ecx
cmp    $0x2d,%cl
je     116d <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x5d>
cmp    $0x4e,%cl
jne    1170 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x60>
add    $0x1,%ebx
mov    %eax,%ecx
cmp    %ebx,%edi
jg     1185 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x75>
add    $0x1,%eax
lea    0x1(%rdx),%rdi
cmp    %rsi,%rdx
mov    %rdi,%rdx
jl     1150 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x40>
test   %ecx,%ecx
jle    1192 <get_window_end_coordinates_excluding_gaps_with_start_end_index+0x82>
mov    %ecx,%eax
mov    (%r14,%rax,4),%ebx
add    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_window_end_coordinates_excluding_gaps_with_start_end_index(i32 %0, i32 %1, i32* %2, i8* nocapture %3, i32 %4, i32 %5, i32 %6) {
%8 = add nsw i32 %1, %0
%9 = tail call i32 @find_starting_index(i32 %0, i32* %2, i32 %5, i32 %6)
%10 = icmp slt i32 %9, %4
br i1 %10, label %11, label %43
11: ; preds = %7
%12 = sext i32 %9 to i64
%13 = sext i32 %4 to i64
br label %14
14: ; preds = %29, %11
%15 = phi i64 [ %33, %29 ], [ %12, %11 ]
%16 = phi i32 [ %31, %29 ], [ 0, %11 ]
%17 = phi i32 [ %30, %29 ], [ %8, %11 ]
%18 = getelementptr inbounds i32, i32* %2, i64 %15
%19 = load i32, i32* %18
%20 = icmp sge i32 %19, %0
%21 = icmp slt i32 %19, %17
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %29
23: ; preds = %14
%24 = getelementptr inbounds i8, i8* %3, i64 %15
%25 = load i8, i8* %24
%26 = trunc i64 %15 to i32
switch i8 %25, label %29 [
i8 45, label %27
i8 78, label %27
]
27: ; preds = %23, %23
%28 = add nsw i32 %17, 1
br label %29
29: ; preds = %23, %27, %14
%30 = phi i32 [ %28, %27 ], [ %17, %14 ], [ %17, %23 ]
%31 = phi i32 [ %26, %27 ], [ %16, %14 ], [ %26, %23 ]
%32 = icmp sle i32 %19, %30
%33 = add nsw i64 %15, 1
%34 = icmp slt i64 %33, %13
%35 = select i1 %32, i1 %34, i1 false
br i1 %35, label %14, label %36
36: ; preds = %29
%37 = icmp sgt i32 %31, 0
br i1 %37, label %38, label %43
38: ; preds = %36
%39 = zext i32 %31 to i64
%40 = getelementptr inbounds i32, i32* %2, i64 %39
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1
br label %43
43: ; preds = %7, %36, %38
%44 = phi i32 [ %42, %38 ], [ %30, %36 ], [ %8, %7 ]
ret i32 %44
}