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

; 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
@matchingCount = 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
@match = external dso_local global [310 x [310 x i32]], align 16
@mate1 = external dso_local global [310 x i32], align 16
@mate2 = external dso_local global [310 x i32], 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 nounwind uwtable
define dso_local void @_Z20primalInitializationv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %5

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

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

10:                                               ; preds = %5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [310 x i32], ptr @mate2, i64 0, i64 %12
  store i32 -1, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [310 x i32], ptr @mate1, i64 0, i64 %15
  store i32 -1, ptr %16, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %10
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !9

20:                                               ; preds = %9
  store i32 0, ptr @matchingCount, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %89, %20
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %84, %26
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 8, ptr %3, align 4
  br label %87

32:                                               ; preds = %27
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [310 x i32], ptr @mate2, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp eq i32 %36, -1
  br i1 %37, label %38, label %83

38:                                               ; preds = %32
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [310 x i64], ptr %41, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !11
  %50 = sub nsw i64 %45, %49
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [310 x i64], ptr @ly, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !11
  %55 = sub nsw i64 %50, %54
  %56 = icmp eq i64 %55, 0
  br i1 %56, label %57, label %83

57:                                               ; preds = %38
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [310 x [310 x i32]], ptr @match, i64 0, i64 %59
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [310 x i32], ptr %60, i64 0, i64 %62
  store i32 1, ptr %63, align 4, !tbaa !5
  %64 = load i32, ptr @matchingCount, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr @matchingCount, align 4, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [310 x i32], ptr @mate1, i64 0, i64 %68
  store i32 %66, ptr %69, align 4, !tbaa !5
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [310 x i32], ptr @mate2, i64 0, i64 %72
  store i32 %70, ptr %73, align 4, !tbaa !5
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %75
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [310 x i64], ptr %76, i64 0, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !11
  %81 = load i64, ptr @res, align 8, !tbaa !11
  %82 = add nsw i64 %81, %80
  store i64 %82, ptr @res, align 8, !tbaa !11
  store i32 8, ptr %3, align 4
  br label %87

83:                                               ; preds = %38, %32
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !13

87:                                               ; preds = %57, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %88

88:                                               ; preds = %87
  br label %89

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

92:                                               ; preds = %25
  ret void
}

attributes #0 = { 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!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"

@n = external dso_local local_unnamed_addr global i32, align 4
@matchingCount = 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 local_unnamed_addr global [310 x [310 x i64]], align 16
@lx = external dso_local local_unnamed_addr global [310 x i64], align 16
@ly = external dso_local local_unnamed_addr global [310 x i64], align 16
@match = external dso_local local_unnamed_addr global [310 x [310 x i32]], align 16
@mate1 = external dso_local local_unnamed_addr global [310 x i32], align 16
@mate2 = external dso_local local_unnamed_addr global [310 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z20primalInitializationv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not30 = icmp slt i32 %1, 1
  br i1 %.not30, label %._crit_edge.thread, label %.preheader.preheader

._crit_edge.thread:                               ; preds = %0
  store i32 0, ptr @matchingCount, align 4, !tbaa !5
  br label %._crit_edge39

.preheader.preheader:                             ; preds = %0
  %2 = zext nneg i32 %1 to i64
  %3 = shl nuw nsw i64 %2, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @mate2, i64 4), i8 -1, i64 %3, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @mate1, i64 4), i8 -1, i64 %3, i1 false), !tbaa !5
  store i32 0, ptr @matchingCount, align 4, !tbaa !5
  %res.promoted = load i64, ptr @res, align 8, !tbaa !9
  %4 = add nuw i32 %1, 1
  %wide.trip.count48 = zext i32 %4 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %..loopexit_crit_edge
  %indvars.iv45 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next46, %..loopexit_crit_edge ]
  %5 = phi i32 [ 0, %.preheader.preheader ], [ %30, %..loopexit_crit_edge ]
  %6 = phi i64 [ %res.promoted, %.preheader.preheader ], [ %29, %..loopexit_crit_edge ]
  %7 = getelementptr inbounds [310 x i64], ptr @lx, i64 0, i64 %indvars.iv45
  br label %8

._crit_edge39:                                    ; preds = %..loopexit_crit_edge, %._crit_edge.thread
  ret void

8:                                                ; preds = %.preheader, %28
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %28 ]
  %9 = getelementptr inbounds [310 x i32], ptr @mate2, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %12, label %28

12:                                               ; preds = %8
  %13 = getelementptr inbounds [310 x [310 x i64]], ptr @cost, i64 0, i64 %indvars.iv45, i64 %indvars.iv
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = getelementptr inbounds [310 x i64], ptr @ly, i64 0, i64 %indvars.iv
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = add i64 %17, %15
  %19 = icmp eq i64 %14, %18
  br i1 %19, label %20, label %28

20:                                               ; preds = %12
  %21 = getelementptr inbounds [310 x i32], ptr @mate2, i64 0, i64 %indvars.iv
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  %23 = getelementptr inbounds [310 x [310 x i32]], ptr @match, i64 0, i64 %indvars.iv45, i64 %indvars.iv
  store i32 1, ptr %23, align 4, !tbaa !5
  %24 = add nsw i32 %5, 1
  store i32 %24, ptr @matchingCount, align 4, !tbaa !5
  %25 = getelementptr inbounds [310 x i32], ptr @mate1, i64 0, i64 %indvars.iv45
  store i32 %22, ptr %25, align 4, !tbaa !5
  %26 = trunc nuw nsw i64 %indvars.iv45 to i32
  store i32 %26, ptr %21, align 4, !tbaa !5
  %27 = add nsw i64 %6, %14
  store i64 %27, ptr @res, align 8, !tbaa !9
  br label %..loopexit_crit_edge

28:                                               ; preds = %8, %12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count48
  br i1 %exitcond.not, label %..loopexit_crit_edge, label %8, !llvm.loop !11

..loopexit_crit_edge:                             ; preds = %28, %20
  %29 = phi i64 [ %27, %20 ], [ %6, %28 ]
  %30 = phi i32 [ %24, %20 ], [ %5, %28 ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count48
  br i1 %exitcond49.not, label %._crit_edge39, label %.preheader, !llvm.loop !13
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }

!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"}
!13 = distinct !{!13, !12}


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