; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/341 Division 2/Problem E/E.ll (Z4exppx)

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

@x = external dso_local global i32, align 4
@m = external dso_local global [100 x [100 x i64]], align 16
@id = external dso_local global [100 x [100 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4mul1v() #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
declare dso_local void @_Z4mul2v() #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4exppx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %19, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = load i32, ptr @x, align 4, !tbaa !9
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %14
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100 x i64], ptr %15, i64 0, i64 %17
  store i64 1, ptr %18, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %12
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !11

22:                                               ; preds = %11
  br label %23

23:                                               ; preds = %31, %22
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %26, label %34

26:                                               ; preds = %23
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = srem i64 %27, 2
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  call void @_Z4mul1v()
  br label %31

31:                                               ; preds = %30, %26
  call void @_Z4mul2v()
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = ashr i64 %32, 1
  store i64 %33, ptr %2, align 8, !tbaa !5
  br label %23, !llvm.loop !13

34:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %64, %34
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = load i32, ptr @x, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 7, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %67

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %60, %40
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = load i32, ptr @x, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 10, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %63

46:                                               ; preds = %41
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %48
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100 x i64], ptr %49, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100 x [100 x i64]], ptr @m, i64 0, i64 %55
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100 x i64], ptr %56, i64 0, i64 %58
  store i64 %53, ptr %59, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %46
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !9
  br label %41, !llvm.loop !14

63:                                               ; preds = %45
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %4, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %4, align 4, !tbaa !9
  br label %35, !llvm.loop !15

67:                                               ; preds = %39
  ret void
}

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 = !{!"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"

@x = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global [100 x [100 x i64]], align 16
@id = external dso_local local_unnamed_addr global [100 x [100 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4mul1v() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4mul2v() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4exppx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @x, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph.preheader, label %.preheader19

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %4 = icmp ult i32 %2, 4
  br i1 %4, label %.preheader19.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.preheader19.loopexit.unr-lcssa:                  ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader19, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader19.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader19.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader19.loopexit.unr-lcssa ]
  %5 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %indvars.iv.epil, i64 %indvars.iv.epil
  store i64 1, ptr %5, align 8, !tbaa !9
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader19, label %.lr.ph.epil, !llvm.loop !11

.preheader19:                                     ; preds = %.preheader19.loopexit.unr-lcssa, %.lr.ph.epil, %1
  %6 = icmp sgt i64 %0, 0
  br i1 %6, label %.lr.ph22, label %.preheader18

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %7 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i64 1, ptr %7, align 16, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %8 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  store i64 1, ptr %8, align 8, !tbaa !9
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %9 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv.next.1
  store i64 1, ptr %9, align 16, !tbaa !9
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %10 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %indvars.iv.next.2, i64 %indvars.iv.next.2
  store i64 1, ptr %10, align 8, !tbaa !9
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader19.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

.preheader18.loopexit:                            ; preds = %25
  %.pre = load i32, ptr @x, align 4, !tbaa !5
  br label %.preheader18

.preheader18:                                     ; preds = %.preheader18.loopexit, %.preheader19
  %11 = phi i32 [ %.pre, %.preheader18.loopexit ], [ %2, %.preheader19 ]
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.preheader.us.preheader, label %._crit_edge26

.preheader.us.preheader:                          ; preds = %.preheader18
  %13 = zext nneg i32 %11 to i64
  %14 = shl nuw nsw i64 %13, 3
  %xtraiter36 = and i64 %13, 3
  %15 = icmp ult i32 %11, 4
  br i1 %15, label %._crit_edge26.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter39 = and i64 %13, 2147483644
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.us.preheader.new
  %indvar = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvar.next.3, %.preheader.us ]
  %niter40 = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter40.next.3, %.preheader.us ]
  %16 = mul nuw nsw i64 %indvar, 800
  %scevgep = getelementptr i8, ptr @m, i64 %16
  %scevgep29 = getelementptr i8, ptr @id, i64 %16
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep, ptr align 16 %scevgep29, i64 %14, i1 false), !tbaa !9
  %17 = mul nuw i64 %indvar, 800
  %18 = add nuw i64 %17, 800
  %scevgep.1 = getelementptr i8, ptr @m, i64 %18
  %scevgep29.1 = getelementptr i8, ptr @id, i64 %18
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.1, ptr align 16 %scevgep29.1, i64 %14, i1 false), !tbaa !9
  %19 = mul nuw i64 %indvar, 800
  %20 = add nuw i64 %19, 1600
  %scevgep.2 = getelementptr i8, ptr @m, i64 %20
  %scevgep29.2 = getelementptr i8, ptr @id, i64 %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.2, ptr align 16 %scevgep29.2, i64 %14, i1 false), !tbaa !9
  %21 = mul nuw i64 %indvar, 800
  %22 = add nuw i64 %21, 2400
  %scevgep.3 = getelementptr i8, ptr @m, i64 %22
  %scevgep29.3 = getelementptr i8, ptr @id, i64 %22
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.3, ptr align 16 %scevgep29.3, i64 %14, i1 false), !tbaa !9
  %indvar.next.3 = add nuw nsw i64 %indvar, 4
  %niter40.next.3 = add i64 %niter40, 4
  %niter40.ncmp.3 = icmp eq i64 %niter40.next.3, %unroll_iter39
  br i1 %niter40.ncmp.3, label %._crit_edge26.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !15

.lr.ph22:                                         ; preds = %.preheader19, %25
  %.01721 = phi i64 [ %26, %25 ], [ %0, %.preheader19 ]
  %23 = and i64 %.01721, 1
  %.not = icmp eq i64 %23, 0
  br i1 %.not, label %25, label %24

24:                                               ; preds = %.lr.ph22
  tail call void @_Z4mul1v()
  br label %25

25:                                               ; preds = %24, %.lr.ph22
  tail call void @_Z4mul2v()
  %26 = lshr i64 %.01721, 1
  %.not27 = icmp ult i64 %.01721, 2
  br i1 %.not27, label %.preheader18.loopexit, label %.lr.ph22, !llvm.loop !16

._crit_edge26.loopexit.unr-lcssa:                 ; preds = %.preheader.us, %.preheader.us.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvar.next.3, %.preheader.us ]
  %lcmp.mod38.not = icmp eq i64 %xtraiter36, 0
  br i1 %lcmp.mod38.not, label %._crit_edge26, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge26.loopexit.unr-lcssa, %.preheader.us.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader.us.epil ], [ %indvar.unr, %._crit_edge26.loopexit.unr-lcssa ]
  %epil.iter37 = phi i64 [ %epil.iter37.next, %.preheader.us.epil ], [ 0, %._crit_edge26.loopexit.unr-lcssa ]
  %27 = mul nuw nsw i64 %indvar.epil, 800
  %scevgep.epil = getelementptr i8, ptr @m, i64 %27
  %scevgep29.epil = getelementptr i8, ptr @id, i64 %27
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.epil, ptr align 16 %scevgep29.epil, i64 %14, i1 false), !tbaa !9
  %indvar.next.epil = add nuw nsw i64 %indvar.epil, 1
  %epil.iter37.next = add i64 %epil.iter37, 1
  %epil.iter37.cmp.not = icmp eq i64 %epil.iter37.next, %xtraiter36
  br i1 %epil.iter37.cmp.not, label %._crit_edge26, label %.preheader.us.epil, !llvm.loop !17

._crit_edge26:                                    ; preds = %._crit_edge26.loopexit.unr-lcssa, %.preheader.us.epil, %.preheader18
  ret void
}

; 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) #1

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 nounwind willreturn memory(argmem: readwrite) }

!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.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !12}


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