; LLVM IR from aap/librw :: src/base.ll (ZN2rw8makePathEPc)

; 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 uwtable
declare dso_local void @_ZN2rw15correctPathCaseEPc(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw8makePathEPc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i64 @strlen(ptr noundef %5) #4
  store i64 %6, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %31, %1
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = load i64, ptr %3, align 8, !tbaa !9
  %10 = icmp ult i64 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %34

12:                                               ; preds = %7
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %17, 47
  br i1 %18, label %26, label %19

19:                                               ; preds = %12
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 92
  br i1 %25, label %26, label %30

26:                                               ; preds = %19, %12
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %27, i64 %28
  store i8 47, ptr %29, align 1, !tbaa !11
  br label %30

30:                                               ; preds = %26, %19
  br label %31

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

34:                                               ; preds = %11
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN2rw15correctPathCaseEPc(ptr noundef %35)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 willreturn memory(read) "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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

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


; 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 uwtable
declare dso_local void @_ZN2rw15correctPathCaseEPc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw8makePathEPc(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %xtraiter = and i64 %2, 3
  %3 = icmp ult i64 %2, 4
  br i1 %3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %24, %.lr.ph.preheader
  %.011.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %25, %24 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %7
  %.011.epil = phi i64 [ %8, %7 ], [ %.011.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %7 ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %4 = getelementptr inbounds i8, ptr %0, i64 %.011.epil
  %5 = load i8, ptr %4, align 1, !tbaa !5
  switch i8 %5, label %7 [
    i8 47, label %6
    i8 92, label %6
  ]

6:                                                ; preds = %.lr.ph.epil, %.lr.ph.epil
  store i8 47, ptr %4, align 1, !tbaa !5
  br label %7

7:                                                ; preds = %6, %.lr.ph.epil
  %8 = add nuw i64 %.011.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !8

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %7, %1
  tail call void @_ZN2rw15correctPathCaseEPc(ptr noundef %0)
  ret void

.lr.ph:                                           ; preds = %24, %.lr.ph.preheader.new
  %.011 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %25, %24 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %24 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 %.011
  %10 = load i8, ptr %9, align 1, !tbaa !5
  switch i8 %10, label %.lr.ph.1 [
    i8 47, label %11
    i8 92, label %11
  ]

11:                                               ; preds = %.lr.ph, %.lr.ph
  store i8 47, ptr %9, align 1, !tbaa !5
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %11
  %12 = or disjoint i64 %.011, 1
  %13 = getelementptr inbounds i8, ptr %0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  switch i8 %14, label %.lr.ph.2 [
    i8 47, label %15
    i8 92, label %15
  ]

15:                                               ; preds = %.lr.ph.1, %.lr.ph.1
  store i8 47, ptr %13, align 1, !tbaa !5
  br label %.lr.ph.2

.lr.ph.2:                                         ; preds = %15, %.lr.ph.1
  %16 = or disjoint i64 %.011, 2
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !5
  switch i8 %18, label %.lr.ph.3 [
    i8 47, label %19
    i8 92, label %19
  ]

19:                                               ; preds = %.lr.ph.2, %.lr.ph.2
  store i8 47, ptr %17, align 1, !tbaa !5
  br label %.lr.ph.3

.lr.ph.3:                                         ; preds = %19, %.lr.ph.2
  %20 = or disjoint i64 %.011, 3
  %21 = getelementptr inbounds i8, ptr %0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  switch i8 %22, label %24 [
    i8 47, label %23
    i8 92, label %23
  ]

23:                                               ; preds = %.lr.ph.3, %.lr.ph.3
  store i8 47, ptr %21, align 1, !tbaa !5
  br label %24

24:                                               ; preds = %23, %.lr.ph.3
  %25 = add nuw i64 %.011, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !10
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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.unroll.disable"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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