; LLVM IR from VastoLorde95/Competitive-Programming :: HackerEarth/Intercity Travel/inter.ll (Z4expoiii)

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

@A = external dso_local global [51 x [51 x i64]], align 16
@n = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808), ptr noundef nonnull align 8 dereferenceable(20808)) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z4expoiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [51 x [51 x i64]], align 16
  %8 = alloca [51 x [51 x i64]], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20808, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 20808, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %53, %3
  %13 = load i32, ptr %9, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

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

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

18:                                               ; preds = %49, %17
  %19 = load i32, ptr %11, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %52

23:                                               ; preds = %18
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = icmp eq i32 %24, %25
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 1, i32 0
  %29 = sext i32 %28 to i64
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [51 x [51 x i64]], ptr %7, i64 0, i64 %31
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [51 x i64], ptr %32, i64 0, i64 %34
  store i64 %29, ptr %35, align 8, !tbaa !9
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [51 x [51 x i64]], ptr @A, i64 0, i64 %37
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [51 x i64], ptr %38, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [51 x [51 x i64]], ptr %8, i64 0, i64 %44
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [51 x i64], ptr %45, i64 0, i64 %47
  store i64 %42, ptr %48, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %23
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !5
  br label %18, !llvm.loop !11

52:                                               ; preds = %22
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %9, align 4, !tbaa !5
  br label %12, !llvm.loop !13

56:                                               ; preds = %16
  br label %57

57:                                               ; preds = %71, %56
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %72

60:                                               ; preds = %57
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = srem i32 %61, 2
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %60
  call void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808) %8, ptr noundef nonnull align 8 dereferenceable(20808) %8)
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = ashr i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !5
  br label %71

67:                                               ; preds = %60
  call void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808) %7, ptr noundef nonnull align 8 dereferenceable(20808) %8)
  call void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808) %8, ptr noundef nonnull align 8 dereferenceable(20808) %8)
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = ashr i32 %69, 1
  store i32 %70, ptr %6, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %67, %64
  br label %57, !llvm.loop !14

72:                                               ; preds = %57
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [51 x [51 x i64]], ptr %7, i64 0, i64 %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [51 x i64], ptr %75, i64 0, i64 %77
  %79 = load i64, ptr %78, align 8, !tbaa !9
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 20808, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 20808, ptr %7) #2
  ret i64 %79
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

@A = external dso_local local_unnamed_addr global [51 x [51 x i64]], align 16
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808), ptr noundef nonnull align 8 dereferenceable(20808)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z4expoiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [51 x [51 x i64]], align 16
  %5 = alloca [51 x [51 x i64]], align 16
  call void @llvm.lifetime.start.p0(i64 20808, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 20808, ptr nonnull %5) #3
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not24 = icmp slt i32 %6, 1
  br i1 %.not24, label %.preheader, label %.preheader21.preheader

.preheader21.preheader:                           ; preds = %3
  %7 = zext nneg i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 3
  %9 = add nuw i32 %6, 1
  %wide.trip.count = zext i32 %9 to i64
  %10 = zext nneg i32 %6 to i64
  %min.iters.check = icmp ult i32 %6, 4
  %n.vec = and i64 %10, 2147483644
  %ind.end = or disjoint i64 %n.vec, 1
  %cmp.n = icmp eq i64 %n.vec, %10
  br label %.preheader21

.preheader21:                                     ; preds = %.preheader21.preheader, %._crit_edge
  %indvars.iv30 = phi i64 [ 1, %.preheader21.preheader ], [ %indvars.iv.next31, %._crit_edge ]
  %indvar = phi i64 [ 0, %.preheader21.preheader ], [ %indvar.next, %._crit_edge ]
  %11 = mul nuw nsw i64 %indvar, 408
  %12 = add nuw nsw i64 %11, 416
  %scevgep = getelementptr i8, ptr %5, i64 %12
  %scevgep28 = getelementptr i8, ptr @A, i64 %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %scevgep, ptr align 8 %scevgep28, i64 %8, i1 false), !tbaa !9
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader21
  %indvars.iv.ph = phi i64 [ 1, %.preheader21 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.preheader21
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %indvars.iv30, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 1, i64 2>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %offset.idx = or disjoint i64 %index, 1
  %13 = icmp eq <2 x i64> %broadcast.splat, %vec.ind
  %14 = icmp eq <2 x i64> %broadcast.splat, %step.add
  %15 = zext <2 x i1> %13 to <2 x i64>
  %16 = zext <2 x i1> %14 to <2 x i64>
  %17 = getelementptr inbounds [51 x [51 x i64]], ptr %4, i64 0, i64 %indvars.iv30, i64 %offset.idx
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store <2 x i64> %15, ptr %17, align 8, !tbaa !9
  store <2 x i64> %16, ptr %18, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

.preheader:                                       ; preds = %._crit_edge, %3
  %20 = icmp sgt i32 %2, 0
  br i1 %20, label %.lr.ph, label %._crit_edge27

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %indvar.next = add nuw nsw i64 %indvar, 1
  %exitcond34.not = icmp eq i64 %indvar.next, %7
  br i1 %exitcond34.not, label %.preheader, label %.preheader21, !llvm.loop !15

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %21 = icmp eq i64 %indvars.iv30, %indvars.iv
  %22 = zext i1 %21 to i64
  %23 = getelementptr inbounds [51 x [51 x i64]], ptr %4, i64 0, i64 %indvars.iv30, i64 %indvars.iv
  store i64 %22, ptr %23, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %29
  %.01926 = phi i32 [ %.1, %29 ], [ %2, %.preheader ]
  %24 = and i32 %.01926, 1
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %.lr.ph
  call void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808) %5, ptr noundef nonnull align 8 dereferenceable(20808) %5)
  br label %29

27:                                               ; preds = %.lr.ph
  call void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808) %4, ptr noundef nonnull align 8 dereferenceable(20808) %5)
  call void @_Z4multRA51_A51_xS1_(ptr noundef nonnull align 8 dereferenceable(20808) %5, ptr noundef nonnull align 8 dereferenceable(20808) %5)
  %28 = add nsw i32 %.01926, -1
  br label %29

29:                                               ; preds = %27, %26
  %.1.in = phi i32 [ %.01926, %26 ], [ %28, %27 ]
  %.1 = lshr exact i32 %.1.in, 1
  %.not = icmp eq i32 %.1.in, 0
  br i1 %.not, label %._crit_edge27, label %.lr.ph, !llvm.loop !17

._crit_edge27:                                    ; preds = %29, %.preheader
  %30 = sext i32 %0 to i64
  %31 = sext i32 %1 to i64
  %32 = getelementptr inbounds [51 x [51 x i64]], ptr %4, i64 0, i64 %30, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 20808, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 20808, ptr nonnull %4) #3
  ret i64 %33
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12, !14, !13}
!17 = distinct !{!17, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass