; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/311 Division 2/Problem E/E.ll (Z6insertii)

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

%struct.node = type <{ [2 x ptr], i32, [4 x i8] }>

@s = external dso_local global [5001 x i8], align 16
@dp = external dso_local global [5000 x [5000 x i32]], align 16
@l = external dso_local global i32, align 4
@ROOT = external dso_local global ptr, align 8

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

11:                                               ; preds = %69, %2
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr @l, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %72

16:                                               ; preds = %11
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.node, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = sub nsw i32 %23, 97
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2 x ptr], ptr %18, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %46

29:                                               ; preds = %16
  %30 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %30)
          to label %31 unwind label %42

31:                                               ; preds = %29
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = sub nsw i32 %38, 97
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2 x ptr], ptr %33, i64 0, i64 %40
  store ptr %30, ptr %41, align 8, !tbaa !9
  br label %46

42:                                               ; preds = %29
  %43 = landingpad { ptr, i32 }
          cleanup
  %44 = extractvalue { ptr, i32 } %43, 0
  store ptr %44, ptr %7, align 8
  %45 = extractvalue { ptr, i32 } %43, 1
  store i32 %45, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %30, i64 noundef 24) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %73

46:                                               ; preds = %31, %16
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = sub nsw i32 %53, 97
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [2 x ptr], ptr %48, i64 0, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  store ptr %57, ptr %5, align 8, !tbaa !9
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [5000 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.node, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !12
  %68 = add nsw i32 %67, %64
  store i32 %68, ptr %66, align 8, !tbaa !12
  br label %69

69:                                               ; preds = %46
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !5
  br label %11, !llvm.loop !14

72:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void

73:                                               ; preds = %42
  %74 = load ptr, ptr %7, align 8
  %75 = load i32, ptr %8, align 4
  %76 = insertvalue { ptr, i32 } poison, ptr %74, 0
  %77 = insertvalue { ptr, i32 } %76, i32 %75, 1
  resume { ptr, i32 } %77
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #3 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; 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 = { nobuiltin allocsize(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 = { 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 #4 = { nobuiltin nounwind "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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"_ZTS4node", !7, i64 0, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"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 [5001 x i8], align 16
@dp = external dso_local local_unnamed_addr global [5000 x [5000 x i32]], align 16
@l = external dso_local local_unnamed_addr global i32, align 4
@ROOT = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = load i32, ptr @l, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, %1
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %5 = load ptr, ptr @ROOT, align 8, !tbaa !9
  %6 = sext i32 %0 to i64
  %7 = sext i32 %1 to i64
  br label %8

._crit_edge:                                      ; preds = %23, %2
  ret void

8:                                                ; preds = %.lr.ph, %23
  %9 = phi i32 [ %3, %.lr.ph ], [ %24, %23 ]
  %indvars.iv = phi i64 [ %7, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %.01112 = phi ptr [ %5, %.lr.ph ], [ %26, %23 ]
  %10 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %indvars.iv
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = sext i8 %11 to i64
  %13 = add nsw i64 %12, -97
  %14 = getelementptr inbounds [2 x ptr], ptr %.01112, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %23

17:                                               ; preds = %8
  %18 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #3
  tail call void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %18)
  %19 = load i8, ptr %10, align 1, !tbaa !11
  %20 = sext i8 %19 to i64
  %21 = add nsw i64 %20, -97
  %22 = getelementptr inbounds [2 x ptr], ptr %.01112, i64 0, i64 %21
  store ptr %18, ptr %22, align 8, !tbaa !9
  %.pre = load i8, ptr %10, align 1, !tbaa !11
  %.pre15 = load i32, ptr @l, align 4, !tbaa !5
  %.pre16 = sext i8 %.pre to i64
  %.pre17 = add nsw i64 %.pre16, -97
  br label %23

23:                                               ; preds = %17, %8
  %.pre-phi18 = phi i64 [ %.pre17, %17 ], [ %13, %8 ]
  %24 = phi i32 [ %.pre15, %17 ], [ %9, %8 ]
  %25 = getelementptr inbounds [2 x ptr], ptr %.01112, i64 0, i64 %.pre-phi18
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %6, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %26, i64 16
  %30 = load i32, ptr %29, align 8, !tbaa !12
  %31 = add nsw i32 %30, %28
  store i32 %31, ptr %29, align 8, !tbaa !12
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %32 = sext i32 %24 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %8, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

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 = { nobuiltin allocsize(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 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 #3 = { builtin allocsize(0) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"_ZTS4node", !7, i64 0, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass