; LLVM IR from ahr9n/psolving-paradigms :: 5.other-techniques/CodeForces 711C - Coloring Trees.ll (Z2dpiii)

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

@trees = external dso_local global i32, align 4
@colors = external dso_local global i32, align 4
@neededBeauty = external dso_local global i32, align 4
@color = external dso_local global [101 x i64], align 16
@litre = external dso_local global [101 x [101 x i64]], align 16
@memo = external dso_local global [101 x [101 x [101 x i64]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z2dpiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr @trees, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %3
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr @neededBeauty, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, i64 0, i64 4557430888798830399
  store i64 %20, ptr %4, align 8
  br label %103

21:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [101 x [101 x [101 x i64]]], ptr @memo, i64 0, i64 %23
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [101 x [101 x i64]], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [101 x i64], ptr %27, i64 0, i64 %29
  store ptr %30, ptr %8, align 8, !tbaa !9
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = xor i64 %32, -1
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %21
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  %37 = load i64, ptr %36, align 8, !tbaa !11
  store i64 %37, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %102

38:                                               ; preds = %21
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  store i64 4557430888798830399, ptr %39, align 8, !tbaa !11
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [101 x i64], ptr @color, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %65

45:                                               ; preds = %38
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [101 x i64], ptr @color, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !11
  %52 = trunc i64 %51 to i32
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [101 x i64], ptr @color, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !11
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = icmp ne i64 %57, %59
  %61 = zext i1 %60 to i32
  %62 = add nsw i32 %53, %61
  %63 = call noundef i64 @_Z2dpiii(i32 noundef %47, i32 noundef %52, i32 noundef %62)
  %64 = load ptr, ptr %8, align 8, !tbaa !9
  store i64 %63, ptr %64, align 8, !tbaa !11
  br label %99

65:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %95, %65
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = load i32, ptr @colors, align 4, !tbaa !5
  %69 = icmp sle i32 %67, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %66
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %98

71:                                               ; preds = %66
  %72 = load ptr, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [101 x [101 x i64]], ptr @litre, i64 0, i64 %74
  %76 = load i32, ptr %10, align 4, !tbaa !5
  %77 = sub nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [101 x i64], ptr %75, i64 0, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !11
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = load i32, ptr %10, align 4, !tbaa !5
  %84 = load i32, ptr %7, align 4, !tbaa !5
  %85 = load i32, ptr %10, align 4, !tbaa !5
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = icmp ne i32 %85, %86
  %88 = zext i1 %87 to i32
  %89 = add nsw i32 %84, %88
  %90 = call noundef i64 @_Z2dpiii(i32 noundef %82, i32 noundef %83, i32 noundef %89)
  %91 = add nsw i64 %80, %90
  store i64 %91, ptr %11, align 8, !tbaa !11
  %92 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %72, ptr noundef nonnull align 8 dereferenceable(8) %11)
  %93 = load i64, ptr %92, align 8, !tbaa !11
  %94 = load ptr, ptr %8, align 8, !tbaa !9
  store i64 %93, ptr %94, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %95

95:                                               ; preds = %71
  %96 = load i32, ptr %10, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %10, align 4, !tbaa !5
  br label %66, !llvm.loop !13

98:                                               ; preds = %70
  br label %99

99:                                               ; preds = %98, %45
  %100 = load ptr, ptr %8, align 8, !tbaa !9
  %101 = load i64, ptr %100, align 8, !tbaa !11
  store i64 %101, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %102

102:                                              ; preds = %99, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %103

103:                                              ; preds = %102, %15
  %104 = load i64, ptr %4, align 8
  ret i64 %104
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 = { inlinehint 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !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"

@trees = external dso_local local_unnamed_addr global i32, align 4
@colors = external dso_local local_unnamed_addr global i32, align 4
@neededBeauty = external dso_local local_unnamed_addr global i32, align 4
@color = external dso_local local_unnamed_addr global [101 x i64], align 16
@litre = external dso_local local_unnamed_addr global [101 x [101 x i64]], align 16
@memo = external dso_local global [101 x [101 x [101 x i64]]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z2dpiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  %5 = load i32, ptr @trees, align 4, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %7, label %11

7:                                                ; preds = %3
  %8 = load i32, ptr @neededBeauty, align 4, !tbaa !5
  %9 = icmp eq i32 %8, %2
  %10 = select i1 %9, i64 0, i64 4557430888798830399
  br label %common.ret

11:                                               ; preds = %3
  %12 = sext i32 %0 to i64
  %13 = sext i32 %1 to i64
  %14 = sext i32 %2 to i64
  %15 = getelementptr inbounds [101 x [101 x [101 x i64]]], ptr @memo, i64 0, i64 %12, i64 %13, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %.not = icmp eq i64 %16, -1
  br i1 %.not, label %17, label %common.ret

17:                                               ; preds = %11
  store i64 4557430888798830399, ptr %15, align 8, !tbaa !9
  %18 = getelementptr inbounds [101 x i64], ptr @color, i64 0, i64 %12
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %.not30 = icmp eq i64 %19, 0
  br i1 %.not30, label %.preheader, label %23

.preheader:                                       ; preds = %17
  %20 = load i32, ptr @colors, align 4, !tbaa !5
  %.not3132 = icmp slt i32 %20, 1
  br i1 %.not3132, label %common.ret, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %21 = add nsw i32 %0, 1
  %22 = zext i32 %1 to i64
  br label %30

common.ret:                                       ; preds = %7, %11, %.preheader, %30, %23
  %common.ret.op = phi i64 [ %29, %23 ], [ %10, %7 ], [ %16, %11 ], [ 4557430888798830399, %.preheader ], [ %41, %30 ]
  ret i64 %common.ret.op

23:                                               ; preds = %17
  %24 = add nsw i32 %0, 1
  %25 = trunc i64 %19 to i32
  %26 = icmp ne i64 %19, %13
  %27 = zext i1 %26 to i32
  %28 = add nsw i32 %27, %2
  %29 = tail call noundef i64 @_Z2dpiii(i32 noundef %24, i32 noundef %25, i32 noundef %28)
  store i64 %29, ptr %15, align 8, !tbaa !9
  br label %common.ret

30:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %30 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %31 = add nsw i64 %indvars.iv, -1
  %32 = getelementptr inbounds [101 x [101 x i64]], ptr @litre, i64 0, i64 %12, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = icmp ne i64 %indvars.iv, %22
  %35 = zext i1 %34 to i32
  %36 = add nsw i32 %35, %2
  %37 = trunc nuw nsw i64 %indvars.iv to i32
  %38 = call noundef i64 @_Z2dpiii(i32 noundef %21, i32 noundef %37, i32 noundef %36)
  %39 = add nsw i64 %38, %33
  store i64 %39, ptr %4, align 8, !tbaa !9
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %41 = load i64, ptr %40, align 8, !tbaa !9
  store i64 %41, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = load i32, ptr @colors, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %.not31.not = icmp slt i64 %indvars.iv, %43
  br i1 %.not31.not, label %30, label %common.ret, !llvm.loop !11
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { 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 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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