; LLVM IR from reyadussalahin/problem-solving :: dynamic_programming/basic/loj/F1106 (Solution)

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

@d = external dso_local global [30 x i32], align 16
@f = external dso_local global [30 x i32], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@trace = external dso_local global [30 x [200 x i32]], align 16
@dist = external dso_local global [30 x i32], align 16
@dp = external dso_local global [30 x [200 x i32]], align 16
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@h = external dso_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [29 x i8], align 1

; 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: nounwind uwtable
declare dso_local void @printTrace(i32 noundef, i32 noundef) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @maxfish(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %88, %0
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %91

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %30, %16
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 30
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %33

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [30 x [200 x i32]], ptr @dp, i64 0, i64 %23
  %25 = getelementptr inbounds [200 x i32], ptr %24, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %25, i8 -1, i64 800, i1 false)
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [30 x [200 x i32]], ptr @trace, i64 0, i64 %27
  %29 = getelementptr inbounds [200 x i32], ptr %28, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %29, i8 -1, i64 800, i1 false)
  br label %30

30:                                               ; preds = %21
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %17, !llvm.loop !9

33:                                               ; preds = %20
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @n, ptr noundef @h)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %45, %33
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = icmp sle i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %48

40:                                               ; preds = %35
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [30 x i32], ptr @f, i64 0, i64 %42
  %44 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %43)
  br label %45

45:                                               ; preds = %40
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %6, align 4, !tbaa !5
  br label %35, !llvm.loop !11

48:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %59, %48
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %62

54:                                               ; preds = %49
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [30 x i32], ptr @d, i64 0, i64 %56
  %58 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %57)
  br label %59

59:                                               ; preds = %54
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !5
  br label %49, !llvm.loop !12

62:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %73, %62
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %63
  store i32 14, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %76

68:                                               ; preds = %63
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [30 x i32], ptr @dist, i64 0, i64 %70
  %72 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %71)
  br label %73

73:                                               ; preds = %68
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %8, align 4, !tbaa !5
  br label %63, !llvm.loop !13

76:                                               ; preds = %67
  %77 = load i32, ptr @h, align 4, !tbaa !5
  %78 = mul nsw i32 %77, 60
  %79 = sdiv i32 %78, 5
  store i32 %79, ptr @h, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %80 = load i32, ptr @h, align 4, !tbaa !5
  %81 = call i32 @maxfish(i32 noundef 1, i32 noundef %80)
  store i32 %81, ptr %9, align 4, !tbaa !5
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %82)
  %84 = load i32, ptr @h, align 4, !tbaa !5
  call void @printTrace(i32 noundef 1, i32 noundef %84)
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %86 = load i32, ptr %9, align 4, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %86)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %88

88:                                               ; preds = %76
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !14

91:                                               ; preds = %15
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %92 = load i32, ptr %1, align 4
  ret i32 %92
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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

@d = external dso_local global [30 x i32], align 16
@f = external dso_local global [30 x i32], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@trace = external dso_local local_unnamed_addr global [30 x [200 x i32]], align 16
@dist = external dso_local global [30 x i32], align 16
@dp = external dso_local local_unnamed_addr global [30 x [200 x i32]], align 16
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@h = external dso_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [29 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @printTrace(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @maxfish(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %.not34 = icmp slt i32 %3, 1
  br i1 %.not34, label %._crit_edge36, label %.preheader25

.preheader25:                                     ; preds = %0, %._crit_edge
  %.02135 = phi i32 [ %22, %._crit_edge ], [ 1, %0 ]
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24000) @dp, i8 -1, i64 24000, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24000) @trace, i8 -1, i64 24000, i1 false)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @n, ptr noundef nonnull @h)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not2227 = icmp slt i32 %5, 1
  br i1 %.not2227, label %._crit_edge, label %.lr.ph

._crit_edge36:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0

.preheader24:                                     ; preds = %.lr.ph
  %.not2329 = icmp slt i32 %8, 1
  br i1 %.not2329, label %._crit_edge, label %.lr.ph31

.lr.ph:                                           ; preds = %.preheader25, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader25 ]
  %6 = getelementptr inbounds [30 x i32], ptr @f, i64 0, i64 %indvars.iv
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %.not22.not = icmp slt i64 %indvars.iv, %9
  br i1 %.not22.not, label %.lr.ph, label %.preheader24, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph31
  %10 = icmp sgt i32 %13, 1
  br i1 %10, label %.lr.ph33, label %._crit_edge

.lr.ph31:                                         ; preds = %.preheader24, %.lr.ph31
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.lr.ph31 ], [ 1, %.preheader24 ]
  %11 = getelementptr inbounds [30 x i32], ptr @d, i64 0, i64 %indvars.iv39
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %11)
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %.not23.not = icmp slt i64 %indvars.iv39, %14
  br i1 %.not23.not, label %.lr.ph31, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph33, %.preheader25, %.preheader24, %.preheader
  %15 = load i32, ptr @h, align 4, !tbaa !5
  %16 = mul nsw i32 %15, 12
  store i32 %16, ptr @h, align 4, !tbaa !5
  %17 = call i32 @maxfish(i32 noundef 1, i32 noundef %16)
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %.02135)
  %19 = load i32, ptr @h, align 4, !tbaa !5
  call void @printTrace(i32 noundef 1, i32 noundef %19)
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %17)
  %22 = add nuw nsw i32 %.02135, 1
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.02135, %23
  br i1 %.not.not, label %.preheader25, label %._crit_edge36, !llvm.loop !12

.lr.ph33:                                         ; preds = %.preheader, %.lr.ph33
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %.lr.ph33 ], [ 1, %.preheader ]
  %24 = getelementptr inbounds [30 x i32], ptr @dist, i64 0, i64 %indvars.iv42
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %24)
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next43, %27
  br i1 %28, label %.lr.ph33, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nofree 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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