; LLVM IR from logicchains/LPATHBench :: c (max_distance_branchless)

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

%struct.node_t = type { i32, [0 x %struct.path_t] }
%struct.path_t = type { i32, i32 }

; 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: nounwind uwtable
define dso_local i32 @max_distance_branchless(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [100 x ptr], align 16
  %6 = alloca [100 x i32], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 800, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 400, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.node_t, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.node_t, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = or i32 %20, -2147483648
  store i32 %21, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.node_t, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [0 x %struct.path_t], ptr %23, i64 0, i64 0
  store ptr %24, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %54, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.path_t, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %26, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  store ptr %32, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [100 x ptr], ptr %5, i64 0, i64 %35
  store ptr %33, ptr %36, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.path_t, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [100 x i32], ptr %6, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !9
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.node_t, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = and i32 %45, -2147483648
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %51, label %48

48:                                               ; preds = %25
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = add i32 %49, 1
  store i32 %50, ptr %8, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %48, %25
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.path_t, ptr %52, i64 1
  store ptr %53, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %54

54:                                               ; preds = %51
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = add i32 %55, -1
  store i32 %56, ptr %7, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %25, label %58, !llvm.loop !14

58:                                               ; preds = %54
  br label %59

59:                                               ; preds = %82, %58
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = add i32 %60, -1
  store i32 %61, ptr %8, align 4, !tbaa !9
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %83

63:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [100 x ptr], ptr %5, i64 0, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  store ptr %67, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = call i32 @max_distance_branchless(ptr noundef %68, ptr noundef %69)
  store i32 %70, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds [100 x i32], ptr %6, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = load i32, ptr %13, align 4, !tbaa !9
  %76 = add i32 %74, %75
  store i32 %76, ptr %14, align 4, !tbaa !9
  %77 = load i32, ptr %14, align 4, !tbaa !9
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = icmp ugt i32 %77, %78
  br i1 %79, label %80, label %82

80:                                               ; preds = %63
  %81 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %81, ptr %10, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %80, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %59, !llvm.loop !16

83:                                               ; preds = %59
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.node_t, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 4, !tbaa !9
  %87 = and i32 %86, 2147483647
  store i32 %87, ptr %85, align 4, !tbaa !9
  %88 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 400, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 800, ptr %5) #2
  ret i32 %88
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @max_distance_branchless(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = alloca [100 x ptr], align 16
  %4 = alloca [100 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 400, ptr nonnull %4) #3
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = or i32 %5, -2147483648
  store i32 %6, ptr %1, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %xtraiter = and i32 %5, 1
  %8 = icmp eq i32 %5, 1
  br i1 %8, label %.preheader.unr-lcssa, label %.new

.new:                                             ; preds = %2
  %unroll_iter = and i32 %5, -2
  br label %9

9:                                                ; preds = %9, %.new
  %.024 = phi ptr [ %7, %.new ], [ %33, %9 ]
  %.023 = phi i32 [ 1, %.new ], [ %spec.select.1, %9 ]
  %niter = phi i32 [ 0, %.new ], [ %niter.next.1, %9 ]
  %10 = load i32, ptr %.024, align 4, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds ptr, ptr %0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = zext i32 %.023 to i64
  %15 = getelementptr inbounds [100 x ptr], ptr %3, i64 0, i64 %14
  store ptr %13, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %.024, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !13
  %18 = getelementptr inbounds [100 x i32], ptr %4, i64 0, i64 %14
  store i32 %17, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %13, align 4, !tbaa !5
  %.not33 = icmp sgt i32 %19, -1
  %20 = zext i1 %.not33 to i32
  %spec.select = add i32 %.023, %20
  %21 = getelementptr inbounds i8, ptr %.024, i64 8
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = zext i32 %spec.select to i64
  %27 = getelementptr inbounds [100 x ptr], ptr %3, i64 0, i64 %26
  store ptr %25, ptr %27, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %.024, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = getelementptr inbounds [100 x i32], ptr %4, i64 0, i64 %26
  store i32 %29, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %25, align 4, !tbaa !5
  %.not33.1 = icmp sgt i32 %31, -1
  %32 = zext i1 %.not33.1 to i32
  %spec.select.1 = add i32 %spec.select, %32
  %33 = getelementptr inbounds i8, ptr %.024, i64 16
  %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.unr-lcssa, label %9, !llvm.loop !14

.preheader.unr-lcssa:                             ; preds = %9, %2
  %spec.select.lcssa.ph = phi i32 [ poison, %2 ], [ %spec.select.1, %9 ]
  %.024.unr = phi ptr [ %7, %2 ], [ %33, %9 ]
  %.023.unr = phi i32 [ 1, %2 ], [ %spec.select.1, %9 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.epilog-lcssa

.preheader.epilog-lcssa:                          ; preds = %.preheader.unr-lcssa
  %34 = load i32, ptr %.024.unr, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = zext i32 %.023.unr to i64
  %39 = getelementptr inbounds [100 x ptr], ptr %3, i64 0, i64 %38
  store ptr %37, ptr %39, align 8, !tbaa !11
  %40 = getelementptr inbounds i8, ptr %.024.unr, i64 4
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = getelementptr inbounds [100 x i32], ptr %4, i64 0, i64 %38
  store i32 %41, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr %37, align 4, !tbaa !5
  %.not33.epil = icmp sgt i32 %43, -1
  %44 = zext i1 %.not33.epil to i32
  %spec.select.epil = add i32 %.023.unr, %44
  br label %.preheader

.preheader:                                       ; preds = %.preheader.unr-lcssa, %.preheader.epilog-lcssa
  %spec.select.lcssa = phi i32 [ %spec.select.lcssa.ph, %.preheader.unr-lcssa ], [ %spec.select.epil, %.preheader.epilog-lcssa ]
  %45 = add i32 %spec.select.lcssa, -1
  %.not3134 = icmp eq i32 %45, 0
  br i1 %.not3134, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %46 = zext i32 %45 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %46, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.02535 = phi i32 [ 0, %.lr.ph.preheader ], [ %spec.select32, %.lr.ph ]
  %47 = getelementptr inbounds [100 x ptr], ptr %3, i64 0, i64 %indvars.iv
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = tail call i32 @max_distance_branchless(ptr noundef %0, ptr noundef %48)
  %50 = getelementptr inbounds [100 x i32], ptr %4, i64 0, i64 %indvars.iv
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = add i32 %51, %49
  %spec.select32 = tail call i32 @llvm.umax.i32(i32 %52, i32 %.02535)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %53 = and i64 %indvars.iv.next, 4294967295
  %.not31 = icmp eq i64 %53, 0
  br i1 %.not31, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %54 = phi i32 [ %6, %.preheader ], [ %.pre, %._crit_edge.loopexit ]
  %.025.lcssa = phi i32 [ 0, %.preheader ], [ %spec.select32, %._crit_edge.loopexit ]
  %55 = and i32 %54, 2147483647
  store i32 %55, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 400, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %3) #3
  ret i32 %.025.lcssa
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nosync nounwind memory(readwrite, 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 #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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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