; LLVM IR from vmartinv/eldiego :: grafos/centroid.ll (Z5climbii)

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

@f = external dso_local global [100100 x [20 x i32]], align 16
@L = external dso_local global [100100 x i32], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5climbii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %11, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %10, ptr %3, align 4
  br label %47

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100100 x i32], ptr @L, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = call i32 @llvm.ctlz.i32(i32 %15, i1 true)
  %17 = sub nsw i32 31, %16
  %18 = add nsw i32 %17, 1
  %19 = sub nsw i32 %18, 1
  store i32 %19, ptr %6, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %42, %11
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %45

24:                                               ; preds = %20
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = shl i32 1, %25
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %29, label %41

29:                                               ; preds = %24
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100100 x [20 x i32]], ptr @f, i64 0, i64 %31
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [20 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = shl i32 1, %37
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sub nsw i32 %39, %38
  store i32 %40, ptr %5, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %29, %24
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !9

45:                                               ; preds = %23
  %46 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %46, ptr %3, align 4
  br label %47

47:                                               ; preds = %45, %9
  %48 = load i32, ptr %3, align 4
  ret i32 %48
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!9, !10}
!10 = !{!"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"

@f = external dso_local local_unnamed_addr global [100100 x [20 x i32]], align 16
@L = external dso_local local_unnamed_addr global [100100 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z5climbii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [100100 x i32], ptr @L, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %5, i1 true)
  %7 = xor i32 %6, 31
  %8 = zext nneg i32 %7 to i64
  %9 = and i64 %8, 1
  %lcmp.mod.not.not = icmp eq i64 %9, 0
  br i1 %lcmp.mod.not.not, label %.lr.ph.prol, label %.lr.ph.prol.loopexit

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %10 = shl nuw i32 1, %7
  %.not19.prol = icmp sgt i32 %10, %1
  br i1 %.not19.prol, label %.lr.ph.prol.loopexit.unr-lcssa, label %11

11:                                               ; preds = %.lr.ph.prol
  %12 = sext i32 %0 to i64
  %13 = getelementptr inbounds [100100 x [20 x i32]], ptr @f, i64 0, i64 %12, i64 %8
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sub nsw i32 %1, %10
  br label %.lr.ph.prol.loopexit.unr-lcssa

.lr.ph.prol.loopexit.unr-lcssa:                   ; preds = %11, %.lr.ph.prol
  %.115.prol = phi i32 [ %14, %11 ], [ %0, %.lr.ph.prol ]
  %.1.prol = phi i32 [ %15, %11 ], [ %1, %.lr.ph.prol ]
  %indvars.iv.next.prol = add nsw i64 %8, -1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol.loopexit.unr-lcssa, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ %8, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol.loopexit.unr-lcssa ]
  %.01321.unr = phi i32 [ %1, %.lr.ph.preheader ], [ %.1.prol, %.lr.ph.prol.loopexit.unr-lcssa ]
  %.01420.unr = phi i32 [ %0, %.lr.ph.preheader ], [ %.115.prol, %.lr.ph.prol.loopexit.unr-lcssa ]
  %.115.lcssa.unr = phi i32 [ poison, %.lr.ph.preheader ], [ %.115.prol, %.lr.ph.prol.loopexit.unr-lcssa ]
  %16 = icmp eq i32 %6, 31
  br i1 %16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %31
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %31 ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %.01321 = phi i32 [ %.1.1, %31 ], [ %.01321.unr, %.lr.ph.prol.loopexit ]
  %.01420 = phi i32 [ %.115.1, %31 ], [ %.01420.unr, %.lr.ph.prol.loopexit ]
  %17 = trunc nuw nsw i64 %indvars.iv to i32
  %18 = shl nuw i32 1, %17
  %.not19 = icmp sgt i32 %18, %.01321
  br i1 %.not19, label %.lr.ph.1, label %19

19:                                               ; preds = %.lr.ph
  %20 = sext i32 %.01420 to i64
  %21 = getelementptr inbounds [100100 x [20 x i32]], ptr @f, i64 0, i64 %20, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sub nsw i32 %.01321, %18
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %19
  %.115 = phi i32 [ %22, %19 ], [ %.01420, %.lr.ph ]
  %.1 = phi i32 [ %23, %19 ], [ %.01321, %.lr.ph ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %24 = trunc nuw nsw i64 %indvars.iv.next to i32
  %25 = shl nuw i32 1, %24
  %.not19.1 = icmp sgt i32 %25, %.1
  br i1 %.not19.1, label %31, label %26

26:                                               ; preds = %.lr.ph.1
  %27 = sext i32 %.115 to i64
  %28 = getelementptr inbounds [100100 x [20 x i32]], ptr @f, i64 0, i64 %27, i64 %indvars.iv.next
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sub nsw i32 %.1, %25
  br label %31

31:                                               ; preds = %26, %.lr.ph.1
  %.115.1 = phi i32 [ %29, %26 ], [ %.115, %.lr.ph.1 ]
  %.1.1 = phi i32 [ %30, %26 ], [ %.1, %.lr.ph.1 ]
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %32 = icmp sgt i64 %indvars.iv, 1
  br i1 %32, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %31, %2
  %.016 = phi i32 [ %0, %2 ], [ %.115.lcssa.unr, %.lr.ph.prol.loopexit ], [ %.115.1, %31 ]
  ret i32 %.016
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}


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