; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/tbbproxy (tbbproxy)

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

10:                                               ; preds = %27, %4
  %11 = load i64, ptr %9, align 8, !tbaa !9
  %12 = load i64, ptr %8, align 8, !tbaa !9
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %14, label %18

14:                                               ; preds = %10
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = icmp ne i8 %16, 0
  br label %18

18:                                               ; preds = %14, %10
  %19 = phi i1 [ false, %10 ], [ %17, %14 ]
  br i1 %19, label %20, label %32

20:                                               ; preds = %18
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = call noundef signext i8 @_ZN3tbb10interface68internal14runtime_loader13char_or_slashEc(i8 noundef signext %22)
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  store i8 %23, ptr %26, align 1, !tbaa !11
  br label %27

27:                                               ; preds = %20
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = add i64 %28, 1
  store i64 %29, ptr %9, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i32 1
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !12

32:                                               ; preds = %18
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = icmp ugt i64 %33, 0
  br i1 %34, label %35, label %52

35:                                               ; preds = %32
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = icmp ult i64 %36, %37
  br i1 %38, label %39, label %52

39:                                               ; preds = %35
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = sub i64 %41, 1
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = icmp ne i32 %45, 47
  br i1 %46, label %47, label %52

47:                                               ; preds = %39
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %9, align 8, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %48, i64 %49
  store i8 47, ptr %51, align 1, !tbaa !11
  br label %52

52:                                               ; preds = %47, %39, %35, %32
  br label %53

53:                                               ; preds = %69, %52
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = icmp ult i64 %54, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %53
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = icmp ne i8 %59, 0
  br label %61

61:                                               ; preds = %57, %53
  %62 = phi i1 [ false, %53 ], [ %60, %57 ]
  br i1 %62, label %63, label %74

63:                                               ; preds = %61
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load i8, ptr %64, align 1, !tbaa !11
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  store i8 %65, ptr %68, align 1, !tbaa !11
  br label %69

69:                                               ; preds = %63
  %70 = load i64, ptr %9, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %9, align 8, !tbaa !9
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i32 1
  store ptr %73, ptr %6, align 8, !tbaa !5
  br label %53, !llvm.loop !14

74:                                               ; preds = %61
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load i64, ptr %9, align 8, !tbaa !9
  %77 = load i64, ptr %8, align 8, !tbaa !9
  %78 = icmp ult i64 %76, %77
  br i1 %78, label %79, label %81

79:                                               ; preds = %74
  %80 = load i64, ptr %9, align 8, !tbaa !9
  br label %84

81:                                               ; preds = %74
  %82 = load i64, ptr %8, align 8, !tbaa !9
  %83 = sub i64 %82, 1
  br label %84

84:                                               ; preds = %81, %79
  %85 = phi i64 [ %80, %79 ], [ %83, %81 ]
  %86 = getelementptr inbounds i8, ptr %75, i64 %85
  store i8 0, ptr %86, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN3tbb10interface68internal14runtime_loader13char_or_slashEc(i8 noundef signext) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = !{!"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 nounwind uwtable
define dso_local void @_ZN3tbb10interface68internal14runtime_loader8cat_fileEPKcS4_Pcm(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i64 %3, 0
  br i1 %5, label %.critedge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %4, %7
  %.042 = phi i64 [ %10, %7 ], [ 0, %4 ]
  %.02941 = phi ptr [ %11, %7 ], [ %0, %4 ]
  %6 = load i8, ptr %.02941, align 1, !tbaa !5
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %.critedge, label %7

7:                                                ; preds = %.lr.ph
  %8 = tail call noundef signext i8 @_ZN3tbb10interface68internal14runtime_loader13char_or_slashEc(i8 noundef signext %6)
  %9 = getelementptr inbounds i8, ptr %2, i64 %.042
  store i8 %8, ptr %9, align 1, !tbaa !5
  %10 = add nuw i64 %.042, 1
  %11 = getelementptr inbounds i8, ptr %.02941, i64 1
  %exitcond.not = icmp eq i64 %10, %3
  br i1 %exitcond.not, label %.critedge2.thread, label %.lr.ph, !llvm.loop !8

.critedge:                                        ; preds = %.lr.ph
  %.not33 = icmp eq i64 %.042, 0
  br i1 %.not33, label %.critedge.thread, label %12

12:                                               ; preds = %.critedge
  %13 = getelementptr i8, ptr %2, i64 %.042
  %14 = getelementptr i8, ptr %13, i64 -1
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %.not34 = icmp eq i8 %15, 47
  br i1 %.not34, label %.critedge.thread, label %16

16:                                               ; preds = %12
  %17 = add nuw i64 %.042, 1
  store i8 47, ptr %13, align 1, !tbaa !5
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %4, %.critedge, %16, %12
  %.1 = phi i64 [ %17, %16 ], [ %.042, %12 ], [ 0, %.critedge ], [ 0, %4 ]
  %.1.fr = freeze i64 %.1
  %18 = icmp ult i64 %.1.fr, %3
  br i1 %18, label %.lr.ph45.preheader, label %.critedge2.thread

.lr.ph45.preheader:                               ; preds = %.critedge.thread
  %19 = load i8, ptr %1, align 1, !tbaa !5
  %.not3561 = icmp eq i8 %19, 0
  br i1 %.not3561, label %.critedge2, label %.lr.ph64

.lr.ph45:                                         ; preds = %.lr.ph64
  %20 = getelementptr inbounds i8, ptr %.0304363, i64 1
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %.not35 = icmp eq i8 %21, 0
  br i1 %.not35, label %.critedge2.loopexit, label %.lr.ph64, !llvm.loop !10

.lr.ph64:                                         ; preds = %.lr.ph45.preheader, %.lr.ph45
  %22 = phi i8 [ %21, %.lr.ph45 ], [ %19, %.lr.ph45.preheader ]
  %.0304363 = phi ptr [ %20, %.lr.ph45 ], [ %1, %.lr.ph45.preheader ]
  %.24462 = phi i64 [ %24, %.lr.ph45 ], [ %.1.fr, %.lr.ph45.preheader ]
  %23 = getelementptr inbounds i8, ptr %2, i64 %.24462
  store i8 %22, ptr %23, align 1, !tbaa !5
  %24 = add i64 %.24462, 1
  %exitcond54.not = icmp eq i64 %24, %3
  br i1 %exitcond54.not, label %.critedge2.loopexit, label %.lr.ph45, !llvm.loop !10

.critedge2.thread:                                ; preds = %7, %.critedge.thread
  %25 = add i64 %3, -1
  br label %28

.critedge2.loopexit:                              ; preds = %.lr.ph45, %.lr.ph64
  %.2.lcssa.ph = phi i64 [ %3, %.lr.ph64 ], [ %24, %.lr.ph45 ]
  %26 = icmp ult i64 %24, %3
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.lr.ph45.preheader
  %.2.lcssa = phi i64 [ %.1.fr, %.lr.ph45.preheader ], [ %.2.lcssa.ph, %.critedge2.loopexit ]
  %.lcssa = phi i1 [ true, %.lr.ph45.preheader ], [ %26, %.critedge2.loopexit ]
  %27 = add i64 %3, -1
  %spec.select = select i1 %.lcssa, i64 %.2.lcssa, i64 %27
  br label %28

28:                                               ; preds = %.critedge2, %.critedge2.thread
  %29 = phi i64 [ %25, %.critedge2.thread ], [ %spec.select, %.critedge2 ]
  %30 = getelementptr inbounds i8, ptr %2, i64 %29
  store i8 0, ptr %30, align 1, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN3tbb10interface68internal14runtime_loader13char_or_slashEc(i8 noundef signext) local_unnamed_addr #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 = { inlinehint 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" }

!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, !9}


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