; LLVM IR from DionysiosB/CodeForces :: 0200-0299/217A-IceSkating.ll (Z6searchii)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl" }
%"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl" = type { %"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl_data" }
%"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.drift = type <{ i32, i32, i8, [3 x i8] }>

@array = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6searchii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %7) #3
  %9 = getelementptr inbounds %struct.drift, ptr %8, i32 0, i32 2
  %10 = load i8, ptr %9, align 4, !tbaa !9, !range !12, !noundef !13
  %11 = trunc i8 %10 to i1
  %12 = zext i1 %11 to i32
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %56

15:                                               ; preds = %2
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %17) #3
  %19 = getelementptr inbounds %struct.drift, ptr %18, i32 0, i32 2
  store i8 1, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %53, %15
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %56

25:                                               ; preds = %20
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %27) #3
  %29 = getelementptr inbounds %struct.drift, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %32) #3
  %34 = getelementptr inbounds %struct.drift, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = icmp eq i32 %30, %35
  br i1 %36, label %49, label %37

37:                                               ; preds = %25
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %39) #3
  %41 = getelementptr inbounds %struct.drift, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !15
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %44) #3
  %46 = getelementptr inbounds %struct.drift, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = icmp eq i32 %42, %47
  br i1 %48, label %49, label %52

49:                                               ; preds = %37, %25
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z6searchii(i32 noundef %50, i32 noundef %51)
  br label %52

52:                                               ; preds = %49, %37
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %20, !llvm.loop !16

56:                                               ; preds = %24, %14
  ret void
}

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

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

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

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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTS5drift", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !6, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl" }
%"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl" = type { %"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl_data" }
%"struct.std::_Vector_base<drift, std::allocator<drift>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@array = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6searchii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = tail call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %3) #1
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load i8, ptr %5, align 4, !tbaa !5, !range !11, !noundef !12
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %2
  %9 = tail call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %3) #1
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  store i8 1, ptr %10, align 4, !tbaa !5
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %8
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %27 ]
  %12 = tail call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %indvars.iv) #1
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = tail call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %3) #1
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = icmp eq i32 %13, %15
  br i1 %16, label %25, label %17

17:                                               ; preds = %.lr.ph
  %18 = tail call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %indvars.iv) #1
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = tail call noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @array, i64 noundef %3) #1
  %22 = getelementptr inbounds i8, ptr %21, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = icmp eq i32 %20, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %17, %.lr.ph
  %26 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_Z6searchii(i32 noundef %26, i32 noundef %1)
  br label %27

27:                                               ; preds = %17, %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %27, %8, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(9) ptr @_ZNSt6vectorI5driftSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) 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, !10, i64 8}
!6 = !{!"_ZTS5drift", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass