; LLVM IR from upupming/algorithm :: kick-start/2020/2020F-C.ll (Z8findNextiiRSt6vectorIiSaIiEES2_)

; 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"

@s = external dso_local global i32, align 4
@visited = external dso_local global [100 x [100 x i32]], align 16
@delta = external dso_local global [2 x [3 x [2 x i32]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8findNextiiRSt6vectorIiSaIiEES2_(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %67, %4
  %13 = load i32, ptr %9, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 3
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %70

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = srem i32 %18, 2
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2 x [3 x [2 x i32]]], ptr @delta, i64 0, i64 %20
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [3 x [2 x i32]], ptr %21, i64 0, i64 %23
  %25 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 0
  %26 = load i32, ptr %25, align 8, !tbaa !5
  %27 = add nsw i32 %17, %26
  store i32 %27, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = srem i32 %29, 2
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2 x [3 x [2 x i32]]], ptr @delta, i64 0, i64 %31
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [3 x [2 x i32]], ptr %32, i64 0, i64 %34
  %36 = getelementptr inbounds [2 x i32], ptr %35, i64 0, i64 1
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %28, %37
  store i32 %38, ptr %11, align 4, !tbaa !5
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = icmp sge i32 %39, 1
  br i1 %40, label %41, label %66

41:                                               ; preds = %16
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = load i32, ptr @s, align 4, !tbaa !5
  %44 = icmp sle i32 %42, %43
  br i1 %44, label %45, label %66

45:                                               ; preds = %41
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = icmp sge i32 %46, 1
  br i1 %47, label %48, label %66

48:                                               ; preds = %45
  %49 = load i32, ptr %11, align 4, !tbaa !5
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = mul nsw i32 2, %50
  %52 = sub nsw i32 %51, 1
  %53 = icmp sle i32 %49, %52
  br i1 %53, label %54, label %66

54:                                               ; preds = %48
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100 x [100 x i32]], ptr @visited, i64 0, i64 %56
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100 x i32], ptr %57, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %66, label %63

63:                                               ; preds = %54
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %64, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %65 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %65, ptr noundef nonnull align 4 dereferenceable(4) %11)
  br label %66

66:                                               ; preds = %63, %54, %48, %45, %41, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %9, align 4, !tbaa !5
  br label %12, !llvm.loop !11

70:                                               ; preds = %15
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@s = external dso_local local_unnamed_addr global i32, align 4
@visited = external dso_local local_unnamed_addr global [100 x [100 x i32]], align 16
@delta = external dso_local local_unnamed_addr global [2 x [3 x [2 x i32]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8findNextiiRSt6vectorIiSaIiEES2_(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = srem i32 %1, 2
  %8 = sext i32 %7 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %9 = getelementptr inbounds [2 x [3 x [2 x i32]]], ptr @delta, i64 0, i64 %8, i64 0
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = add nsw i32 %10, %0
  store i32 %11, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %12 = getelementptr inbounds i8, ptr %9, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, %1
  store i32 %14, ptr %6, align 4, !tbaa !5
  %15 = icmp sgt i32 %11, 0
  br i1 %15, label %16, label %27

16:                                               ; preds = %4
  %17 = load i32, ptr @s, align 4, !tbaa !5
  %18 = icmp sle i32 %11, %17
  %19 = icmp sgt i32 %14, 0
  %or.cond = select i1 %18, i1 %19, i1 false
  %20 = shl nuw nsw i32 %11, 1
  %.not.not = icmp slt i32 %14, %20
  %or.cond12 = select i1 %or.cond, i1 %.not.not, i1 false
  br i1 %or.cond12, label %21, label %27

21:                                               ; preds = %16
  %22 = zext nneg i32 %11 to i64
  %23 = zext nneg i32 %14 to i64
  %24 = getelementptr inbounds [100 x [100 x i32]], ptr @visited, i64 0, i64 %22, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %26, label %27

26:                                               ; preds = %21
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 4 dereferenceable(4) %5)
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 4 dereferenceable(4) %6)
  br label %27

27:                                               ; preds = %26, %21, %16, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %28 = getelementptr inbounds [2 x [3 x [2 x i32]]], ptr @delta, i64 0, i64 %8, i64 1
  %29 = load i32, ptr %28, align 8, !tbaa !5
  %30 = add nsw i32 %29, %0
  store i32 %30, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %31 = getelementptr inbounds i8, ptr %28, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, %1
  store i32 %33, ptr %6, align 4, !tbaa !5
  %34 = icmp sgt i32 %30, 0
  br i1 %34, label %35, label %46

35:                                               ; preds = %27
  %36 = load i32, ptr @s, align 4, !tbaa !5
  %37 = icmp sle i32 %30, %36
  %38 = icmp sgt i32 %33, 0
  %or.cond.1 = select i1 %37, i1 %38, i1 false
  %39 = shl nuw nsw i32 %30, 1
  %.not.not.1 = icmp slt i32 %33, %39
  %or.cond12.1 = select i1 %or.cond.1, i1 %.not.not.1, i1 false
  br i1 %or.cond12.1, label %40, label %46

40:                                               ; preds = %35
  %41 = zext nneg i32 %30 to i64
  %42 = zext nneg i32 %33 to i64
  %43 = getelementptr inbounds [100 x [100 x i32]], ptr @visited, i64 0, i64 %41, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %44, 0
  br i1 %.not.1, label %45, label %46

45:                                               ; preds = %40
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 4 dereferenceable(4) %5)
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 4 dereferenceable(4) %6)
  br label %46

46:                                               ; preds = %45, %40, %35, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %47 = getelementptr inbounds [2 x [3 x [2 x i32]]], ptr @delta, i64 0, i64 %8, i64 2
  %48 = load i32, ptr %47, align 8, !tbaa !5
  %49 = add nsw i32 %48, %0
  store i32 %49, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %50 = getelementptr inbounds i8, ptr %47, i64 4
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = add nsw i32 %51, %1
  store i32 %52, ptr %6, align 4, !tbaa !5
  %53 = icmp sgt i32 %49, 0
  br i1 %53, label %54, label %65

54:                                               ; preds = %46
  %55 = load i32, ptr @s, align 4, !tbaa !5
  %56 = icmp sle i32 %49, %55
  %57 = icmp sgt i32 %52, 0
  %or.cond.2 = select i1 %56, i1 %57, i1 false
  %58 = shl nuw nsw i32 %49, 1
  %.not.not.2 = icmp slt i32 %52, %58
  %or.cond12.2 = select i1 %or.cond.2, i1 %.not.not.2, i1 false
  br i1 %or.cond12.2, label %59, label %65

59:                                               ; preds = %54
  %60 = zext nneg i32 %49 to i64
  %61 = zext nneg i32 %52 to i64
  %62 = getelementptr inbounds [100 x [100 x i32]], ptr @visited, i64 0, i64 %60, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %.not.2 = icmp eq i32 %63, 0
  br i1 %.not.2, label %64, label %65

64:                                               ; preds = %59
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 4 dereferenceable(4) %5)
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 4 dereferenceable(4) %6)
  br label %65

65:                                               ; preds = %64, %59, %54, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  ret void
}

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass