; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/Other/DIBZ2016/DZ16SHOP/A.ll (Z18dualInitializationv)

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

@n = external dso_local global i32, align 4
@res = external dso_local global i64, align 8
@cost = external dso_local global [310 x [310 x i64]], align 16
@lx = external dso_local global [310 x i64], align 16
@ly = external dso_local global [310 x i64], align 16

; 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: mustprogress uwtable
define dso_local void @_Z18dualInitializationv() #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 i64, align 8
  store i64 0, ptr @res, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 1, ptr %1, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %45, %0
  %8 = load i32, ptr %1, align 4, !tbaa !9
  %9 = load i32, ptr @n, align 4, !tbaa !9
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i32, ptr %1, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %14
  %16 = getelementptr inbounds [310 x i64], ptr %15, i64 0, i64 1
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %19
  store i64 %17, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 2, ptr %3, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %41, %12
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = load i32, ptr @n, align 4, !tbaa !9
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %44

26:                                               ; preds = %21
  %27 = load i32, ptr %1, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %28
  %30 = load i32, ptr %1, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %31
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [310 x i64], ptr %32, i64 0, i64 %34
  %36 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef nonnull align 8 dereferenceable(8) %35)
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = load i32, ptr %1, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %39
  store i64 %37, ptr %40, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %26
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !9
  br label %21, !llvm.loop !11

44:                                               ; preds = %25
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %1, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %1, align 4, !tbaa !9
  br label %7, !llvm.loop !13

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

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

53:                                               ; preds = %49
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %97

54:                                               ; preds = %49
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [310 x i64], ptr getelementptr inbounds ([310 x [310 x i64]], ptr @cost, i64 0, i64 1), i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = load i64, ptr getelementptr inbounds ([310 x i64], ptr @lx, i64 0, i64 1), align 8, !tbaa !5
  %60 = sub nsw i64 %58, %59
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [310 x i64], ptr @ly, i64 0, i64 %62
  store i64 %60, ptr %63, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 2, ptr %5, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %90, %54
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = load i32, ptr @n, align 4, !tbaa !9
  %67 = icmp sle i32 %65, %66
  br i1 %67, label %69, label %68

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

69:                                               ; preds = %64
  %70 = load i32, ptr %4, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [310 x i64], ptr @ly, i64 0, i64 %71
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %74
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [310 x i64], ptr %75, i64 0, i64 %77
  %79 = load i64, ptr %78, align 8, !tbaa !5
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %81
  %83 = load i64, ptr %82, align 8, !tbaa !5
  %84 = sub nsw i64 %79, %83
  store i64 %84, ptr %6, align 8, !tbaa !5
  %85 = 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) %6)
  %86 = load i64, ptr %85, align 8, !tbaa !5
  %87 = load i32, ptr %4, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [310 x i64], ptr @ly, i64 0, i64 %88
  store i64 %86, ptr %89, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %90

90:                                               ; preds = %69
  %91 = load i32, ptr %5, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %5, align 4, !tbaa !9
  br label %64, !llvm.loop !14

93:                                               ; preds = %68
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %4, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %4, align 4, !tbaa !9
  br label %49, !llvm.loop !15

97:                                               ; preds = %53
  ret void
}

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@res = external dso_local local_unnamed_addr global i64, align 8
@cost = external dso_local global [310 x [310 x i64]], align 16
@lx = external dso_local global [310 x i64], align 16
@ly = external dso_local global [310 x i64], align 16

; 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: mustprogress nounwind uwtable
define dso_local void @_Z18dualInitializationv() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  store i64 0, ptr @res, align 8, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %.not29 = icmp slt i32 %2, 1
  br i1 %.not29, label %._crit_edge41, label %.lr.ph32

.lr.ph32:                                         ; preds = %0
  %3 = icmp eq i32 %2, 1
  br i1 %3, label %.lr.ph40.thread, label %.lr.ph32.split

.lr.ph40.thread:                                  ; preds = %.lr.ph32
  %4 = load i64, ptr getelementptr inbounds (i8, ptr @cost, i64 2488), align 8, !tbaa !5
  store i64 %4, ptr getelementptr inbounds (i8, ptr @lx, i64 8), align 8, !tbaa !5
  br label %._crit_edge41.loopexit

.preheader:                                       ; preds = %._crit_edge
  %.not2438 = icmp slt i32 %10, 1
  br i1 %.not2438, label %._crit_edge41, label %.lr.ph40

.lr.ph40:                                         ; preds = %.preheader
  %5 = icmp eq i32 %10, 1
  br i1 %5, label %._crit_edge41.loopexit, label %.lr.ph40.split

.lr.ph32.split:                                   ; preds = %.lr.ph32, %._crit_edge
  %6 = phi i32 [ %10, %._crit_edge ], [ %2, %.lr.ph32 ]
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge ], [ 1, %.lr.ph32 ]
  %7 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %indvars.iv45, i64 1
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %indvars.iv45
  store i64 %8, ptr %9, align 8, !tbaa !5
  %.not2627 = icmp slt i32 %6, 2
  br i1 %.not2627, label %.lr.ph32.split.._crit_edge_crit_edge, label %.lr.ph

.lr.ph32.split.._crit_edge_crit_edge:             ; preds = %.lr.ph32.split
  %.pre63 = sext i32 %6 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph32.split.._crit_edge_crit_edge
  %.pre-phi64 = phi i64 [ %.pre63, %.lr.ph32.split.._crit_edge_crit_edge ], [ %15, %.lr.ph ]
  %10 = phi i32 [ %6, %.lr.ph32.split.._crit_edge_crit_edge ], [ %14, %.lr.ph ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %.not.not = icmp slt i64 %indvars.iv45, %.pre-phi64
  br i1 %.not.not, label %.lr.ph32.split, label %.preheader, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph32.split, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 2, %.lr.ph32.split ]
  %11 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %indvars.iv45, i64 %indvars.iv
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %11)
  %13 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %13, ptr %9, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = load i32, ptr @n, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %.not26.not = icmp slt i64 %indvars.iv, %15
  br i1 %.not26.not, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge41.loopexit:                           ; preds = %.lr.ph40.thread, %.lr.ph40
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @lx, i64 8), align 8, !tbaa !5
  %17 = load i64, ptr getelementptr inbounds (i8, ptr @cost, i64 2488), align 8, !tbaa !5
  %18 = sub nsw i64 %17, %16
  store i64 %18, ptr getelementptr inbounds (i8, ptr @ly, i64 8), align 8, !tbaa !5
  br label %._crit_edge41

._crit_edge41:                                    ; preds = %._crit_edge37, %0, %._crit_edge41.loopexit, %.preheader
  ret void

.lr.ph40.split:                                   ; preds = %.lr.ph40, %._crit_edge37
  %19 = phi i32 [ %25, %._crit_edge37 ], [ %10, %.lr.ph40 ]
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %._crit_edge37 ], [ 1, %.lr.ph40 ]
  %20 = getelementptr inbounds [310 x i64], ptr getelementptr inbounds (i8, ptr @cost, i64 2480), i64 0, i64 %indvars.iv54
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = load i64, ptr getelementptr inbounds (i8, ptr @lx, i64 8), align 8, !tbaa !5
  %23 = sub nsw i64 %21, %22
  %24 = getelementptr inbounds [310 x i64], ptr @ly, i64 0, i64 %indvars.iv54
  store i64 %23, ptr %24, align 8, !tbaa !5
  %.not2533 = icmp slt i32 %19, 2
  br i1 %.not2533, label %.lr.ph40.split.._crit_edge37_crit_edge, label %.lr.ph36

.lr.ph40.split.._crit_edge37_crit_edge:           ; preds = %.lr.ph40.split
  %.pre = sext i32 %19 to i64
  br label %._crit_edge37

._crit_edge37:                                    ; preds = %.lr.ph36, %.lr.ph40.split.._crit_edge37_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.lr.ph40.split.._crit_edge37_crit_edge ], [ %34, %.lr.ph36 ]
  %25 = phi i32 [ %19, %.lr.ph40.split.._crit_edge37_crit_edge ], [ %33, %.lr.ph36 ]
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %.not24.not = icmp slt i64 %indvars.iv54, %.pre-phi
  br i1 %.not24.not, label %.lr.ph40.split, label %._crit_edge41, !llvm.loop !15

.lr.ph36:                                         ; preds = %.lr.ph40.split, %.lr.ph36
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %.lr.ph36 ], [ 2, %.lr.ph40.split ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %26 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %indvars.iv51, i64 %indvars.iv54
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %indvars.iv51
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = sub nsw i64 %27, %29
  store i64 %30, ptr %1, align 8, !tbaa !5
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %32 = load i64, ptr %31, align 8, !tbaa !5
  store i64 %32, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %33 = load i32, ptr @n, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %.not25.not = icmp slt i64 %indvars.iv51, %34
  br i1 %.not25.not, label %.lr.ph36, label %._crit_edge37, !llvm.loop !16
}

; 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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12, !13}
!16 = distinct !{!16, !12}


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