; LLVM IR from andreimaximov/algorithms :: hacker-rank/algorithms/search/connected-cell-in-a-grid (main)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@_ZL7DELTA_X = external hidden constant [8 x i16], align 16
@_ZL7DELTA_Y = external hidden constant [8 x i16], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9floodfillRSt6vectorIS_IiSaIiEESaIS1_EEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %12, i64 noundef %14) #3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef %17) #3
  store i32 0, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %86, %3
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 8
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %89

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [8 x i16], ptr @_ZL7DELTA_X, i64 0, i64 %26
  %28 = load i16, ptr %27, align 2, !tbaa !11
  %29 = sext i16 %28 to i32
  %30 = add nsw i32 %24, %29
  %31 = trunc i32 %30 to i16
  store i16 %31, ptr %10, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [8 x i16], ptr @_ZL7DELTA_Y, i64 0, i64 %34
  %36 = load i16, ptr %35, align 2, !tbaa !11
  %37 = sext i16 %36 to i32
  %38 = add nsw i32 %32, %37
  %39 = trunc i32 %38 to i16
  store i16 %39, ptr %11, align 2, !tbaa !11
  %40 = load i16, ptr %10, align 2, !tbaa !11
  %41 = sext i16 %40 to i32
  %42 = icmp slt i32 %41, 0
  br i1 %42, label %62, label %43

43:                                               ; preds = %23
  %44 = load i16, ptr %10, align 2, !tbaa !11
  %45 = sext i16 %44 to i64
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i16, ptr %11, align 2, !tbaa !11
  %48 = sext i16 %47 to i64
  %49 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %46, i64 noundef %48) #3
  %50 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %49) #3
  %51 = icmp uge i64 %45, %50
  br i1 %51, label %62, label %52

52:                                               ; preds = %43
  %53 = load i16, ptr %11, align 2, !tbaa !11
  %54 = sext i16 %53 to i32
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %62, label %56

56:                                               ; preds = %52
  %57 = load i16, ptr %11, align 2, !tbaa !11
  %58 = sext i16 %57 to i64
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = call noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %59) #3
  %61 = icmp uge i64 %58, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %56, %52, %43, %23
  store i32 4, ptr %9, align 4
  br label %83

63:                                               ; preds = %56
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load i16, ptr %11, align 2, !tbaa !11
  %66 = sext i16 %65 to i64
  %67 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %64, i64 noundef %66) #3
  %68 = load i16, ptr %10, align 2, !tbaa !11
  %69 = sext i16 %68 to i64
  %70 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %67, i64 noundef %69) #3
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %63
  store i32 4, ptr %9, align 4
  br label %83

74:                                               ; preds = %63
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load i16, ptr %11, align 2, !tbaa !11
  %77 = sext i16 %76 to i32
  %78 = load i16, ptr %10, align 2, !tbaa !11
  %79 = sext i16 %78 to i32
  %80 = call noundef i32 @_Z9floodfillRSt6vectorIS_IiSaIiEESaIS1_EEii(ptr noundef nonnull align 8 dereferenceable(24) %75, i32 noundef %77, i32 noundef %79)
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = add nsw i32 %81, %80
  store i32 %82, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %83

83:                                               ; preds = %74, %73, %62
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  %84 = load i32, ptr %9, align 4
  switch i32 %84, label %91 [
    i32 0, label %85
    i32 4, label %86
  ]

85:                                               ; preds = %83
  br label %86

86:                                               ; preds = %85, %83
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %8, align 4, !tbaa !9
  br label %19, !llvm.loop !13

89:                                               ; preds = %22
  %90 = load i32, ptr %7, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %90

91:                                               ; preds = %83
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@_ZL7DELTA_X = external hidden local_unnamed_addr constant [8 x i16], align 16
@_ZL7DELTA_Y = external hidden local_unnamed_addr constant [8 x i16], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9floodfillRSt6vectorIS_IiSaIiEESaIS1_EEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %1 to i64
  %5 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %4) #1
  %6 = sext i32 %2 to i64
  %7 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %6) #1
  store i32 0, ptr %7, align 4, !tbaa !5
  %8 = trunc i32 %2 to i16
  %9 = trunc i32 %1 to i16
  br label %11

10:                                               ; preds = %38
  ret i32 %.1

11:                                               ; preds = %3, %38
  %indvars.iv = phi i64 [ 0, %3 ], [ %indvars.iv.next, %38 ]
  %.031 = phi i32 [ 1, %3 ], [ %.1, %38 ]
  %12 = getelementptr inbounds [8 x i16], ptr @_ZL7DELTA_X, i64 0, i64 %indvars.iv
  %13 = load i16, ptr %12, align 2, !tbaa !9
  %14 = add i16 %13, %8
  %15 = sext i16 %14 to i32
  %16 = icmp slt i16 %14, 0
  br i1 %16, label %38, label %17

17:                                               ; preds = %11
  %18 = getelementptr inbounds [8 x i16], ptr @_ZL7DELTA_Y, i64 0, i64 %indvars.iv
  %19 = load i16, ptr %18, align 2, !tbaa !9
  %20 = add i16 %19, %9
  %21 = zext nneg i16 %14 to i64
  %22 = sext i16 %20 to i64
  %23 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %22) #1
  %24 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %23) #1
  %25 = icmp ule i64 %24, %21
  %26 = sext i16 %20 to i32
  %27 = icmp slt i16 %20, 0
  %or.cond = or i1 %27, %25
  br i1 %or.cond, label %38, label %28

28:                                               ; preds = %17
  %29 = tail call noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %.not = icmp ugt i64 %29, %22
  br i1 %.not, label %30, label %38

30:                                               ; preds = %28
  %31 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %22) #1
  %32 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %21) #1
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %38, label %35

35:                                               ; preds = %30
  %36 = tail call noundef i32 @_Z9floodfillRSt6vectorIS_IiSaIiEESaIS1_EEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %26, i32 noundef %15)
  %37 = add nsw i32 %36, %.031
  br label %38

38:                                               ; preds = %30, %11, %17, %28, %35
  %.1 = phi i32 [ %37, %35 ], [ %.031, %28 ], [ %.031, %17 ], [ %.031, %11 ], [ %.031, %30 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 8
  br i1 %exitcond.not, label %10, label %11, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass