; LLVM IR from VastoLorde95/Competitive-Programming :: HackerEarth/IndiaHacks/Semi/Problem E (E)

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

@t = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@z = external dso_local global i64, align 8
@a = external dso_local global [200200 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %7

7:                                                ; preds = %104, %28, %0
  %8 = load i64, ptr @t, align 8, !tbaa !5
  %9 = add nsw i64 %8, -1
  store i64 %9, ptr @t, align 8, !tbaa !5
  %10 = icmp ne i64 %8, 0
  br i1 %10, label %11, label %109

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m, ptr noundef @z)
  call void @llvm.memset.p0.i64(ptr align 16 @a, i8 0, i64 1601600, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %22, %11
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = load i64, ptr @n, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %25

18:                                               ; preds = %13
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %20)
  br label %22

22:                                               ; preds = %18
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = add nsw i64 %23, 1
  store i64 %24, ptr %2, align 8, !tbaa !5
  br label %13, !llvm.loop !9

25:                                               ; preds = %17
  %26 = load i64, ptr @n, align 8, !tbaa !5
  %27 = icmp eq i64 %26, 1
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load i64, ptr @a, align 16, !tbaa !5
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %29)
  br label %7, !llvm.loop !11

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %32 = load i64, ptr @n, align 8, !tbaa !5
  %33 = sub nsw i64 %32, 1
  store i64 %33, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 1, ptr %4, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %54, %31
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = icmp sge i64 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %59

38:                                               ; preds = %34
  %39 = load i64, ptr @n, align 8, !tbaa !5
  %40 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = mul nsw i64 %42, %45
  %47 = add nsw i64 %41, %46
  %48 = load i64, ptr @m, align 8, !tbaa !5
  %49 = add nsw i64 %47, %48
  %50 = load i64, ptr @m, align 8, !tbaa !5
  %51 = srem i64 %49, %50
  %52 = load i64, ptr @n, align 8, !tbaa !5
  %53 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %52
  store i64 %51, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %38
  %55 = load i64, ptr %3, align 8, !tbaa !5
  %56 = add nsw i64 %55, -1
  store i64 %56, ptr %3, align 8, !tbaa !5
  %57 = load i64, ptr %4, align 8, !tbaa !5
  %58 = sub nsw i64 0, %57
  store i64 %58, ptr %4, align 8, !tbaa !5
  br label %34, !llvm.loop !12

59:                                               ; preds = %37
  %60 = load i64, ptr @n, align 8, !tbaa !5
  %61 = srem i64 %60, 2
  %62 = icmp eq i64 %61, 0
  br i1 %62, label %63, label %99

63:                                               ; preds = %59
  %64 = load i64, ptr @n, align 8, !tbaa !5
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr @n, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %66 = load i64, ptr @n, align 8, !tbaa !5
  %67 = trunc i64 %66 to i32
  store i32 %67, ptr %5, align 4, !tbaa !13
  br label %68

68:                                               ; preds = %90, %63
  %69 = load i32, ptr %5, align 4, !tbaa !13
  %70 = sext i32 %69 to i64
  %71 = load i64, ptr @n, align 8, !tbaa !5
  %72 = mul nsw i64 2, %71
  %73 = icmp slt i64 %70, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %93

75:                                               ; preds = %68
  %76 = load i32, ptr %5, align 4, !tbaa !13
  %77 = sext i32 %76 to i64
  %78 = load i64, ptr @n, align 8, !tbaa !5
  %79 = sub nsw i64 %77, %78
  %80 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !5
  %82 = sub nsw i64 0, %81
  %83 = load i64, ptr @m, align 8, !tbaa !5
  %84 = add nsw i64 %82, %83
  %85 = load i64, ptr @m, align 8, !tbaa !5
  %86 = srem i64 %84, %85
  %87 = load i32, ptr %5, align 4, !tbaa !13
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %88
  store i64 %86, ptr %89, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %75
  %91 = load i32, ptr %5, align 4, !tbaa !13
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %5, align 4, !tbaa !13
  br label %68, !llvm.loop !15

93:                                               ; preds = %74
  %94 = load i64, ptr @n, align 8, !tbaa !5
  %95 = mul nsw i64 2, %94
  store i64 %95, ptr @n, align 8, !tbaa !5
  %96 = load i64, ptr @n, align 8, !tbaa !5
  %97 = load i64, ptr @z, align 8, !tbaa !5
  %98 = srem i64 %97, %96
  store i64 %98, ptr @z, align 8, !tbaa !5
  br label %104

99:                                               ; preds = %59
  %100 = load i64, ptr @n, align 8, !tbaa !5
  %101 = add nsw i64 %100, 1
  %102 = load i64, ptr @z, align 8, !tbaa !5
  %103 = srem i64 %102, %101
  store i64 %103, ptr @z, align 8, !tbaa !5
  br label %104

104:                                              ; preds = %99, %93
  %105 = load i64, ptr @z, align 8, !tbaa !5
  %106 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %105
  %107 = load i64, ptr %106, align 8, !tbaa !5
  %108 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %107)
  br label %7, !llvm.loop !11

109:                                              ; preds = %7
  ret i32 0
}

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

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

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

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

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

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

@t = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@z = external dso_local global i64, align 8
@a = external dso_local global [200200 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i64, ptr @t, align 8, !tbaa !5
  %3 = add nsw i64 %2, -1
  store i64 %3, ptr @t, align 8, !tbaa !5
  %.not29 = icmp eq i64 %2, 0
  br i1 %.not29, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %0, %.backedge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @z)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1601600) @a, i8 0, i64 1601600, i1 false)
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge23

._crit_edge:                                      ; preds = %.lr.ph
  %7 = icmp eq i64 %14, 1
  br i1 %7, label %.backedge, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %8 = icmp sgt i64 %14, 0
  br i1 %8, label %.lr.ph22, label %._crit_edge23

.lr.ph22:                                         ; preds = %.preheader
  %9 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %14
  %10 = load i64, ptr @m, align 8, !tbaa !5
  %xtraiter = and i64 %14, 1
  %.promoted = load i64, ptr %9, align 8, !tbaa !5
  %unroll_iter = and i64 %14, 9223372036854775806
  br label %26

.lr.ph:                                           ; preds = %.lr.ph31, %.lr.ph
  %.01419 = phi i64 [ %13, %.lr.ph ], [ 0, %.lr.ph31 ]
  %11 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %.01419
  %12 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %11)
  %13 = add nuw nsw i64 %.01419, 1
  %14 = load i64, ptr @n, align 8, !tbaa !5
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.backedge:                                        ; preds = %._crit_edge, %54
  %.sink.in = phi ptr [ %57, %54 ], [ @a, %._crit_edge ]
  %.sink = load i64, ptr %.sink.in, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.sink)
  %17 = load i64, ptr @t, align 8, !tbaa !5
  %18 = add nsw i64 %17, -1
  store i64 %18, ptr @t, align 8, !tbaa !5
  %.not = icmp eq i64 %17, 0
  br i1 %.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !11

._crit_edge23.loopexit.unr-lcssa:                 ; preds = %26
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge23, label %._crit_edge23.loopexit.epilog-lcssa

._crit_edge23.loopexit.epilog-lcssa:              ; preds = %._crit_edge23.loopexit.unr-lcssa
  %.013.epil = add nsw i64 %.013.1, -1
  %19 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %.013.epil
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = add nsw i64 %20, %37
  %22 = add nsw i64 %21, %10
  %23 = srem i64 %22, %10
  store i64 %23, ptr %9, align 8, !tbaa !5
  br label %._crit_edge23

._crit_edge23:                                    ; preds = %._crit_edge23.loopexit.epilog-lcssa, %._crit_edge23.loopexit.unr-lcssa, %.lr.ph31, %.preheader
  %.lcssa3638 = phi i64 [ %14, %.preheader ], [ %5, %.lr.ph31 ], [ %14, %._crit_edge23.loopexit.unr-lcssa ], [ %14, %._crit_edge23.loopexit.epilog-lcssa ]
  %24 = and i64 %.lcssa3638, 1
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %38, label %52

26:                                               ; preds = %26, %.lr.ph22
  %27 = phi i64 [ %.promoted, %.lr.ph22 ], [ %37, %26 ]
  %.013.in20 = phi i64 [ %14, %.lr.ph22 ], [ %.013.1, %26 ]
  %niter = phi i64 [ 0, %.lr.ph22 ], [ %niter.next.1, %26 ]
  %.013 = add nsw i64 %.013.in20, -1
  %28 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %.013
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = add nsw i64 %29, %27
  %31 = add nsw i64 %30, %10
  %32 = srem i64 %31, %10
  store i64 %32, ptr %9, align 8, !tbaa !5
  %.013.1 = add nsw i64 %.013.in20, -2
  %33 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %.013.1
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = sub i64 %32, %34
  %36 = add nsw i64 %35, %10
  %37 = srem i64 %36, %10
  store i64 %37, ptr %9, align 8, !tbaa !5
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge23.loopexit.unr-lcssa, label %26, !llvm.loop !12

38:                                               ; preds = %._crit_edge23
  %39 = or disjoint i64 %.lcssa3638, 1
  %40 = shl nsw i64 %39, 1
  %sext = shl i64 %39, 32
  %41 = ashr exact i64 %sext, 32
  %42 = icmp sgt i64 %40, %41
  br i1 %42, label %.lr.ph26, label %._crit_edge27

.lr.ph26:                                         ; preds = %38
  %43 = load i64, ptr @m, align 8, !tbaa !5
  br label %44

._crit_edge27:                                    ; preds = %44, %38
  store i64 %40, ptr @n, align 8, !tbaa !5
  br label %54

44:                                               ; preds = %.lr.ph26, %44
  %indvars.iv = phi i64 [ %41, %.lr.ph26 ], [ %indvars.iv.next, %44 ]
  %45 = sub nsw i64 %indvars.iv, %39
  %46 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = sub i64 %43, %47
  %49 = srem i64 %48, %43
  %50 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %indvars.iv
  store i64 %49, ptr %50, align 8, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %51 = icmp sgt i64 %40, %indvars.iv.next
  br i1 %51, label %44, label %._crit_edge27, !llvm.loop !13

52:                                               ; preds = %._crit_edge23
  %53 = add nsw i64 %.lcssa3638, 1
  br label %54

54:                                               ; preds = %52, %._crit_edge27
  %.sink40 = phi i64 [ %53, %52 ], [ %40, %._crit_edge27 ]
  %55 = load i64, ptr @z, align 8, !tbaa !5
  %56 = srem i64 %55, %.sink40
  store i64 %56, ptr @z, align 8, !tbaa !5
  %57 = getelementptr inbounds [200200 x i64], ptr @a, i64 0, i64 %56
  br label %.backedge

._crit_edge32:                                    ; preds = %.backedge, %0
  ret i32 0
}

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

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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 #2 = { mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass