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

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

@b = external dso_local global [101 x [101 x i64]], align 16
@res = external dso_local global [101 x [101 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multPA101_xS0_i(ptr noundef, ptr noundef, i32 noundef) #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 void @_Z3expi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %18, %1
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 101
  br i1 %9, label %11, label %10

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

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

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

21:                                               ; preds = %10
  br label %22

22:                                               ; preds = %30, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %22
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = and i32 %26, 1
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  call void @_Z4multPA101_xS0_i(ptr noundef @res, ptr noundef @b, i32 noundef 0)
  br label %30

30:                                               ; preds = %29, %25
  call void @_Z4multPA101_xS0_i(ptr noundef @b, ptr noundef @b, i32 noundef 1)
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = ashr i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !13

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

34:                                               ; preds = %61, %33
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 101
  br i1 %36, label %38, label %37

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

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

39:                                               ; preds = %57, %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = icmp slt i32 %40, 101
  br i1 %41, label %43, label %42

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

43:                                               ; preds = %39
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [101 x [101 x i64]], ptr @res, i64 0, i64 %45
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [101 x i64], ptr %46, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [101 x [101 x i64]], ptr @b, i64 0, i64 %52
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [101 x i64], ptr %53, i64 0, i64 %55
  store i64 %50, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %43
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !5
  br label %39, !llvm.loop !14

60:                                               ; preds = %42
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %4, align 4, !tbaa !5
  br label %34, !llvm.loop !15

64:                                               ; preds = %37
  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 = !{!"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}
!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"

@b = external dso_local global [101 x [101 x i64]], align 16
@res = external dso_local global [101 x [101 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multPA101_xS0_i(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3expi(i32 noundef %0) local_unnamed_addr #0 {
  br label %3

.preheader19:                                     ; preds = %3
  %2 = icmp sgt i32 %0, 0
  br i1 %2, label %.lr.ph, label %.preheader18

3:                                                ; preds = %5, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.3, %5 ]
  %4 = getelementptr inbounds [101 x [101 x i64]], ptr @res, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i64 1, ptr %4, align 16, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv, 100
  br i1 %exitcond.not, label %.preheader19, label %5, !llvm.loop !9

5:                                                ; preds = %3
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %6 = getelementptr inbounds [101 x [101 x i64]], ptr @res, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  store i64 1, ptr %6, align 16, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %7 = getelementptr inbounds [101 x [101 x i64]], ptr @res, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv.next.1
  store i64 1, ptr %7, align 16, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %8 = getelementptr inbounds [101 x [101 x i64]], ptr @res, i64 0, i64 %indvars.iv.next.2, i64 %indvars.iv.next.2
  store i64 1, ptr %8, align 16, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  br label %3

.preheader18:                                     ; preds = %11, %.preheader19
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(81608) @b, ptr noundef nonnull align 16 dereferenceable(81608) @res, i64 81608, i1 false), !tbaa !5
  ret void

.lr.ph:                                           ; preds = %.preheader19, %11
  %.01721 = phi i32 [ %12, %11 ], [ %0, %.preheader19 ]
  %9 = and i32 %.01721, 1
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %11, label %10

10:                                               ; preds = %.lr.ph
  tail call void @_Z4multPA101_xS0_i(ptr noundef nonnull @res, ptr noundef nonnull @b, i32 noundef 0)
  br label %11

11:                                               ; preds = %10, %.lr.ph
  tail call void @_Z4multPA101_xS0_i(ptr noundef nonnull @b, ptr noundef nonnull @b, i32 noundef 1)
  %12 = lshr i32 %.01721, 1
  %.not24 = icmp ult i32 %.01721, 2
  br i1 %.not24, label %.preheader18, label %.lr.ph, !llvm.loop !11
}

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


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