; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/373 Division 1/Problem C/C.ll (Z4fastPA2_xx)

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

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

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

14:                                               ; preds = %24, %2
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %29

17:                                               ; preds = %14
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = and i64 %18, 1
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %17
  %22 = getelementptr inbounds [2 x [2 x i64]], ptr %5, i64 0, i64 0
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z3mulPA2_xS0_(ptr noundef %22, ptr noundef %23)
  br label %24

24:                                               ; preds = %21, %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z3mulPA2_xS0_(ptr noundef %25, ptr noundef %26)
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = ashr i64 %27, 1
  store i64 %28, ptr %4, align 8, !tbaa !9
  br label %14, !llvm.loop !11

29:                                               ; preds = %14
  %30 = getelementptr inbounds [2 x [2 x i64]], ptr %5, i64 0, i64 0
  %31 = getelementptr inbounds [2 x i64], ptr %30, i64 0, i64 0
  %32 = load i64, ptr %31, align 16, !tbaa !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds [2 x i64], ptr %33, i64 0
  %35 = getelementptr inbounds [2 x i64], ptr %34, i64 0, i64 0
  store i64 %32, ptr %35, align 8, !tbaa !9
  %36 = getelementptr inbounds [2 x [2 x i64]], ptr %5, i64 0, i64 0
  %37 = getelementptr inbounds [2 x i64], ptr %36, i64 0, i64 1
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds [2 x i64], ptr %39, i64 0
  %41 = getelementptr inbounds [2 x i64], ptr %40, i64 0, i64 1
  store i64 %38, ptr %41, align 8, !tbaa !9
  %42 = getelementptr inbounds [2 x [2 x i64]], ptr %5, i64 0, i64 1
  %43 = getelementptr inbounds [2 x i64], ptr %42, i64 0, i64 0
  %44 = load i64, ptr %43, align 16, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds [2 x i64], ptr %45, i64 1
  %47 = getelementptr inbounds [2 x i64], ptr %46, i64 0, i64 0
  store i64 %44, ptr %47, align 8, !tbaa !9
  %48 = getelementptr inbounds [2 x [2 x i64]], ptr %5, i64 0, i64 1
  %49 = getelementptr inbounds [2 x i64], ptr %48, i64 0, i64 1
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds [2 x i64], ptr %51, i64 1
  %53 = getelementptr inbounds [2 x i64], ptr %52, i64 0, i64 1
  store i64 %50, ptr %53, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #2
  ret void
}

; 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

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 = !{!"any pointer", !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"}


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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4fastPA2_xx(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [2 x [2 x i64]], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = getelementptr inbounds i8, ptr %3, i64 24
  store i64 1, ptr %5, align 8, !tbaa !5
  store i64 1, ptr %3, align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  %.not10 = icmp eq i64 %1, 0
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %9
  %.011 = phi i64 [ %10, %9 ], [ %1, %2 ]
  %7 = and i64 %.011, 1
  %.not9 = icmp eq i64 %7, 0
  br i1 %.not9, label %9, label %8

8:                                                ; preds = %.lr.ph
  call void @_Z3mulPA2_xS0_(ptr noundef nonnull %3, ptr noundef %0)
  br label %9

9:                                                ; preds = %8, %.lr.ph
  call void @_Z3mulPA2_xS0_(ptr noundef %0, ptr noundef %0)
  %10 = ashr i64 %.011, 1
  %.not = icmp ult i64 %.011, 2
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %9
  %11 = load <2 x i64>, ptr %3, align 16, !tbaa !5
  %12 = load <2 x i64>, ptr %4, align 16, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %13 = phi <2 x i64> [ %11, %._crit_edge.loopexit ], [ <i64 1, i64 0>, %2 ]
  %14 = phi <2 x i64> [ %12, %._crit_edge.loopexit ], [ <i64 0, i64 1>, %2 ]
  store <2 x i64> %13, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x i64> %14, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  ret void
}

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, 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: write) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass