; LLVM IR from Mohammed-Shoaib/Coding-Problems :: Gulf Programming Contest/2017/amicable/amicable.ll (Z8amicableii)

; 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
define dso_local noundef zeroext i1 @_Z8amicableii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %24, %2
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = srem i32 %15, %16
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %14
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %19, %14
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %7, align 4, !tbaa !5
  br label %9, !llvm.loop !9

27:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %43, %27
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %28
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = srem i32 %34, %35
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %33
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %6, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %38, %33
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %8, align 4, !tbaa !5
  br label %28, !llvm.loop !11

46:                                               ; preds = %32
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp eq i32 %47, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %46
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = icmp eq i32 %51, %52
  br label %54

54:                                               ; preds = %50, %46
  %55 = phi i1 [ false, %46 ], [ %53, %50 ]
  %56 = zext i1 %55 to i64
  %57 = select i1 %55, i1 true, i1 false
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i1 %57
}

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


; 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef zeroext i1 @_Z8amicableii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 1
  br i1 %3, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %2
  %4 = add nsw i32 %0, -1
  %xtraiter = and i32 %4, 1
  %5 = icmp eq i32 %0, 2
  br i1 %5, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %4, -2
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %spec.select.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %spec.select.1, %.lr.ph ]
  %.01828.unr = phi i32 [ 1, %.lr.ph.preheader ], [ %19, %.lr.ph ]
  %.02027.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %spec.select.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa
  %6 = urem i32 %0, %.01828.unr
  %7 = icmp eq i32 %6, 0
  %8 = select i1 %7, i32 %.01828.unr, i32 0
  %spec.select.epil = add nuw nsw i32 %8, %.02027.unr
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.epil, %.preheader.loopexit.unr-lcssa, %2
  %.020.lcssa = phi i32 [ 0, %2 ], [ %spec.select.lcssa.ph, %.preheader.loopexit.unr-lcssa ], [ %spec.select.epil, %.lr.ph.epil ]
  %9 = icmp sgt i32 %1, 1
  br i1 %9, label %.lr.ph31.preheader, label %._crit_edge

.lr.ph31.preheader:                               ; preds = %.preheader
  %10 = add nsw i32 %1, -1
  %xtraiter35 = and i32 %10, 1
  %11 = icmp eq i32 %1, 2
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph31.preheader.new

.lr.ph31.preheader.new:                           ; preds = %.lr.ph31.preheader
  %unroll_iter38 = and i32 %10, -2
  br label %.lr.ph31

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01828 = phi i32 [ 1, %.lr.ph.preheader.new ], [ %19, %.lr.ph ]
  %.02027 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %spec.select.1, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %12 = urem i32 %0, %.01828
  %13 = icmp eq i32 %12, 0
  %14 = select i1 %13, i32 %.01828, i32 0
  %spec.select = add nuw nsw i32 %14, %.02027
  %15 = add nuw nsw i32 %.01828, 1
  %16 = urem i32 %0, %15
  %17 = icmp eq i32 %16, 0
  %18 = select i1 %17, i32 %15, i32 0
  %spec.select.1 = add nuw nsw i32 %18, %spec.select
  %19 = add nuw nsw i32 %.01828, 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !5

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph31, %.lr.ph31.preheader
  %spec.select26.lcssa.ph = phi i32 [ poison, %.lr.ph31.preheader ], [ %spec.select26.1, %.lr.ph31 ]
  %.030.unr = phi i32 [ 1, %.lr.ph31.preheader ], [ %33, %.lr.ph31 ]
  %.01929.unr = phi i32 [ 0, %.lr.ph31.preheader ], [ %spec.select26.1, %.lr.ph31 ]
  %lcmp.mod36.not = icmp eq i32 %xtraiter35, 0
  br i1 %lcmp.mod36.not, label %._crit_edge, label %.lr.ph31.epil

.lr.ph31.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %20 = urem i32 %1, %.030.unr
  %21 = icmp eq i32 %20, 0
  %22 = select i1 %21, i32 %.030.unr, i32 0
  %spec.select26.epil = add nuw nsw i32 %22, %.01929.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph31.epil, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %.019.lcssa = phi i32 [ 0, %.preheader ], [ %spec.select26.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select26.epil, %.lr.ph31.epil ]
  %23 = icmp eq i32 %.020.lcssa, %1
  %24 = icmp eq i32 %.019.lcssa, %0
  %25 = select i1 %23, i1 %24, i1 false
  ret i1 %25

.lr.ph31:                                         ; preds = %.lr.ph31, %.lr.ph31.preheader.new
  %.030 = phi i32 [ 1, %.lr.ph31.preheader.new ], [ %33, %.lr.ph31 ]
  %.01929 = phi i32 [ 0, %.lr.ph31.preheader.new ], [ %spec.select26.1, %.lr.ph31 ]
  %niter39 = phi i32 [ 0, %.lr.ph31.preheader.new ], [ %niter39.next.1, %.lr.ph31 ]
  %26 = urem i32 %1, %.030
  %27 = icmp eq i32 %26, 0
  %28 = select i1 %27, i32 %.030, i32 0
  %spec.select26 = add nuw nsw i32 %28, %.01929
  %29 = add nuw nsw i32 %.030, 1
  %30 = urem i32 %1, %29
  %31 = icmp eq i32 %30, 0
  %32 = select i1 %31, i32 %29, i32 0
  %spec.select26.1 = add nuw nsw i32 %32, %spec.select26
  %33 = add nuw nsw i32 %.030, 2
  %niter39.next.1 = add i32 %niter39, 2
  %niter39.ncmp.1 = icmp eq i32 %niter39.next.1, %unroll_iter38
  br i1 %niter39.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph31, !llvm.loop !7
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass