; LLVM IR from dmr-goncalves/HumanAwareRobotNavigation :: src/husky/husky_base/src/horizon_legacy/Number.ll (ZN9clearpath4btoiEPvm)

; 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: 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 i64 @_ZN9clearpath4btoiEPvm(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 8, ptr %7, align 8, !tbaa !9
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp ne i64 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %52

12:                                               ; preds = %2
  br label %13

13:                                               ; preds = %32, %12
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp uge i64 %14, %15
  br i1 %16, label %17, label %35

17:                                               ; preds = %13
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = shl i64 %18, 8
  store i64 %19, ptr %6, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = sub i64 %21, 1
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = and i32 %25, 128
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %17
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = or i64 %29, 255
  store i64 %30, ptr %6, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %28, %17
  br label %32

32:                                               ; preds = %31
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = add i64 %33, -1
  store i64 %34, ptr %7, align 8, !tbaa !9
  br label %13, !llvm.loop !12

35:                                               ; preds = %13
  br label %36

36:                                               ; preds = %46, %35
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = shl i64 %37, 8
  store i64 %38, ptr %6, align 8, !tbaa !9
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i64
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = or i64 %44, %43
  store i64 %45, ptr %6, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %36
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = add i64 %47, -1
  store i64 %48, ptr %7, align 8, !tbaa !9
  %49 = icmp ne i64 %47, 0
  br i1 %49, label %36, label %50, !llvm.loop !14

50:                                               ; preds = %46
  %51 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %51, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %52

52:                                               ; preds = %50, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %53 = load i64, ptr %3, align 8
  ret i64 %53
}

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 = { 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", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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(argmem: read) uwtable
define dso_local noundef i64 @_ZN9clearpath4btoiEPvm(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.loopexit, label %.preheader22

.preheader22:                                     ; preds = %2
  %.not1823 = icmp ugt i64 %1, 8
  br i1 %.not1823, label %.preheader.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader22
  %3 = getelementptr i8, ptr %0, i64 %1
  %4 = getelementptr i8, ptr %3, i64 -1
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %.fr = freeze i8 %5
  %.not2021 = icmp slt i8 %.fr, 0
  %6 = add nsw i64 %1, -1
  br i1 %.not2021, label %.lr.ph.split.us, label %.preheader.preheader

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %.not18.us = icmp eq i64 %1, 8
  br i1 %.not18.us, label %.preheader.loopexit, label %.lr.ph.split.us.1, !llvm.loop !8

.lr.ph.split.us.1:                                ; preds = %.lr.ph.split.us
  %.not18.us.1 = icmp ugt i64 %1, 6
  br i1 %.not18.us.1, label %.preheader.loopexit, label %.lr.ph.split.us.2, !llvm.loop !8

.lr.ph.split.us.2:                                ; preds = %.lr.ph.split.us.1
  %.not18.us.2 = icmp eq i64 %1, 6
  br i1 %.not18.us.2, label %.preheader.loopexit, label %.lr.ph.split.us.3, !llvm.loop !8

.lr.ph.split.us.3:                                ; preds = %.lr.ph.split.us.2
  %.not18.us.3 = icmp ugt i64 %1, 4
  br i1 %.not18.us.3, label %.preheader.loopexit, label %.lr.ph.split.us.4, !llvm.loop !8

.lr.ph.split.us.4:                                ; preds = %.lr.ph.split.us.3
  %.not18.us.4 = icmp eq i64 %1, 4
  br i1 %.not18.us.4, label %.preheader.loopexit, label %.lr.ph.split.us.5, !llvm.loop !8

.lr.ph.split.us.5:                                ; preds = %.lr.ph.split.us.4
  %.not18.us.5 = icmp ugt i64 %1, 2
  br i1 %.not18.us.5, label %.preheader.loopexit, label %.lr.ph.split.us.6, !llvm.loop !8

.lr.ph.split.us.6:                                ; preds = %.lr.ph.split.us.5
  %.not18.us.6.not = icmp eq i64 %1, 1
  %spec.select = select i1 %.not18.us.6.not, i64 -1, i64 72057594037927935
  br label %.preheader.loopexit, !llvm.loop !8

.preheader.loopexit:                              ; preds = %.lr.ph.split.us.6, %.lr.ph.split.us.5, %.lr.ph.split.us.4, %.lr.ph.split.us.3, %.lr.ph.split.us.2, %.lr.ph.split.us.1, %.lr.ph.split.us
  %.lcssa35 = phi i64 [ 255, %.lr.ph.split.us ], [ 65535, %.lr.ph.split.us.1 ], [ 16777215, %.lr.ph.split.us.2 ], [ 4294967295, %.lr.ph.split.us.3 ], [ 1099511627775, %.lr.ph.split.us.4 ], [ 281474976710655, %.lr.ph.split.us.5 ], [ %spec.select, %.lr.ph.split.us.6 ]
  %umin32 = tail call i64 @llvm.umin.i64(i64 %6, i64 7)
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph, %.preheader.loopexit, %.preheader22
  %.2.ph = phi i64 [ 0, %.lr.ph ], [ %.lcssa35, %.preheader.loopexit ], [ 0, %.preheader22 ]
  %.1.ph = phi i64 [ %6, %.lr.ph ], [ %umin32, %.preheader.loopexit ], [ 8, %.preheader22 ]
  %7 = add nsw i64 %.1.ph, 1
  %xtraiter = and i64 %7, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.prol.loopexit, label %.preheader.prol

.preheader.prol:                                  ; preds = %.preheader.preheader, %.preheader.prol
  %.2.prol = phi i64 [ %12, %.preheader.prol ], [ %.2.ph, %.preheader.preheader ]
  %.1.prol = phi i64 [ %13, %.preheader.prol ], [ %.1.ph, %.preheader.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.preheader.prol ], [ 0, %.preheader.preheader ]
  %8 = shl i64 %.2.prol, 8
  %9 = getelementptr inbounds i8, ptr %0, i64 %.1.prol
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = zext i8 %10 to i64
  %12 = or disjoint i64 %8, %11
  %13 = add nsw i64 %.1.prol, -1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.preheader.prol.loopexit, label %.preheader.prol, !llvm.loop !10

.preheader.prol.loopexit:                         ; preds = %.preheader.prol, %.preheader.preheader
  %.lcssa.unr = phi i64 [ poison, %.preheader.preheader ], [ %12, %.preheader.prol ]
  %.2.unr = phi i64 [ %.2.ph, %.preheader.preheader ], [ %12, %.preheader.prol ]
  %.1.unr = phi i64 [ %.1.ph, %.preheader.preheader ], [ %13, %.preheader.prol ]
  %14 = icmp ult i64 %.1.ph, 3
  br i1 %14, label %.loopexit, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %0, i64 -1
  %invariant.gep39 = getelementptr i8, ptr %0, i64 -2
  br label %.preheader

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %.2 = phi i64 [ %.2.unr, %.preheader.preheader.new ], [ %33, %.preheader ]
  %.1 = phi i64 [ %.1.unr, %.preheader.preheader.new ], [ %34, %.preheader ]
  %15 = getelementptr inbounds i8, ptr %0, i64 %.1
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = zext i8 %16 to i64
  %18 = shl i64 %.2, 16
  %19 = shl nuw nsw i64 %17, 8
  %20 = or disjoint i64 %18, %19
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.1
  %21 = load i8, ptr %gep, align 1, !tbaa !5
  %22 = zext i8 %21 to i64
  %23 = or disjoint i64 %20, %22
  %gep40 = getelementptr i8, ptr %invariant.gep39, i64 %.1
  %24 = load i8, ptr %gep40, align 1, !tbaa !5
  %25 = zext i8 %24 to i64
  %26 = add nsw i64 %.1, -3
  %27 = shl i64 %23, 16
  %28 = shl nuw nsw i64 %25, 8
  %29 = or disjoint i64 %27, %28
  %30 = getelementptr inbounds i8, ptr %0, i64 %26
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = zext i8 %31 to i64
  %33 = or disjoint i64 %29, %32
  %34 = add nsw i64 %.1, -4
  %.not19.3 = icmp eq i64 %26, 0
  br i1 %.not19.3, label %.loopexit, label %.preheader, !llvm.loop !12

.loopexit:                                        ; preds = %.preheader.prol.loopexit, %.preheader, %2
  %.016 = phi i64 [ 0, %2 ], [ %.lcssa.unr, %.preheader.prol.loopexit ], [ %33, %.preheader ]
  ret i64 %.016
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.unroll.disable"}
!12 = distinct !{!12, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass