; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/rbdl/addons/urdfreader/urdf/boost_replacement (string_split)

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

@.str.1 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._Z9str_splitPKcS0_ = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z9str_splitPKcS0_(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef ptr @strstr(ptr noundef %17, ptr noundef %18) #5
  store ptr %19, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i64 @strlen(ptr noundef %20) #5
  store i64 %21, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  br label %22

22:                                               ; preds = %77, %2
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call noundef ptr @strstr(ptr noundef %23, ptr noundef %24) #5
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %45

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = call i64 @strlen(ptr noundef %32) #5
  %34 = call noundef ptr @_Z16str_array_appendPPcmPKcm(ptr noundef %29, i64 noundef %30, ptr noundef %31, i64 noundef %33)
  store ptr %34, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %39

37:                                               ; preds = %28
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_Z14str_array_freePPc(ptr noundef %38)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %43

39:                                               ; preds = %28
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %40, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = add i64 %41, 1
  store i64 %42, ptr %6, align 8, !tbaa !9
  store i32 2, ptr %14, align 4
  br label %43

43:                                               ; preds = %39, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %44 = load i32, ptr %14, align 4
  switch i32 %44, label %96 [
    i32 2, label %78
  ]

45:                                               ; preds = %22
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = icmp eq ptr %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %45
  store ptr @.str.2, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %57

50:                                               ; preds = %45
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %51, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = ptrtoint ptr %52 to i64
  %55 = ptrtoint ptr %53 to i64
  %56 = sub i64 %54, %55
  store i64 %56, ptr %12, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %50, %49
  br label %58

58:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = call noundef ptr @_Z16str_array_appendPPcmPKcm(ptr noundef %59, i64 noundef %60, ptr noundef %61, i64 noundef %62)
  store ptr %63, ptr %15, align 8, !tbaa !5
  %64 = load ptr, ptr %15, align 8, !tbaa !5
  %65 = icmp eq ptr %64, null
  br i1 %65, label %66, label %68

66:                                               ; preds = %58
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_Z14str_array_freePPc(ptr noundef %67)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %75

68:                                               ; preds = %58
  %69 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %69, ptr %7, align 8, !tbaa !5
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %6, align 8, !tbaa !9
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load i64, ptr %10, align 8, !tbaa !9
  %74 = getelementptr inbounds i8, ptr %72, i64 %73
  store ptr %74, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %14, align 4
  br label %75

75:                                               ; preds = %68, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %76 = load i32, ptr %14, align 4
  switch i32 %76, label %96 [
    i32 0, label %77
  ]

77:                                               ; preds = %75
  br label %22, !llvm.loop !11

78:                                               ; preds = %43
  %79 = load i64, ptr %6, align 8, !tbaa !9
  %80 = icmp eq i64 %79, 0
  br i1 %80, label %81, label %94

81:                                               ; preds = %78
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = icmp eq ptr %82, null
  br i1 %83, label %84, label %85

84:                                               ; preds = %81
  br label %87

85:                                               ; preds = %81
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 137, ptr noundef @__PRETTY_FUNCTION__._Z9str_splitPKcS0_) #6
  unreachable

86:                                               ; No predecessors!
  br label %87

87:                                               ; preds = %86, %84
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = load i64, ptr %6, align 8, !tbaa !9
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = call i64 @strlen(ptr noundef %91) #5
  %93 = call noundef ptr @_Z16str_array_appendPPcmPKcm(ptr noundef %88, i64 noundef %89, ptr noundef %90, i64 noundef %92)
  store ptr %93, ptr %7, align 8, !tbaa !5
  br label %94

94:                                               ; preds = %87, %78
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %95, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %96

96:                                               ; preds = %94, %75, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %97 = load ptr, ptr %3, align 8
  ret ptr %97
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z14str_array_freePPc(ptr noundef) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z16str_array_appendPPcmPKcm(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare noundef ptr @strstr(ptr noundef, ptr noundef) #3

attributes #0 = { noreturn nounwind "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 = { 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 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { noreturn 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 = distinct !{!11, !12}
!12 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._Z9str_splitPKcS0_ = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z9str_splitPKcS0_(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %4 = tail call noundef ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) %1) #3
  %5 = icmp eq ptr %4, null
  br i1 %5, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %14, %2
  %.051.lcssa = phi ptr [ %0, %2 ], [ %16, %14 ]
  %.047.lcssa = phi ptr [ null, %2 ], [ %13, %14 ]
  %.042.lcssa = phi i64 [ 0, %2 ], [ %15, %14 ]
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.051.lcssa) #3
  %7 = tail call noundef ptr @_Z16str_array_appendPPcmPKcm(ptr noundef %.047.lcssa, i64 noundef %.042.lcssa, ptr noundef %.051.lcssa, i64 noundef %6)
  %.not56 = icmp eq ptr %7, null
  br i1 %.not56, label %.sink.split, label %19

.lr.ph:                                           ; preds = %2, %14
  %8 = phi ptr [ %17, %14 ], [ %4, %2 ]
  %.04268 = phi i64 [ %15, %14 ], [ 0, %2 ]
  %.04767 = phi ptr [ %13, %14 ], [ null, %2 ]
  %.05166 = phi ptr [ %16, %14 ], [ %0, %2 ]
  %9 = icmp eq ptr %8, %0
  %10 = ptrtoint ptr %8 to i64
  %11 = ptrtoint ptr %.05166 to i64
  %12 = sub i64 %10, %11
  %.046 = select i1 %9, ptr @.str.2, ptr %.05166
  %.045 = select i1 %9, i64 0, i64 %12
  %13 = tail call noundef ptr @_Z16str_array_appendPPcmPKcm(ptr noundef %.04767, i64 noundef %.04268, ptr noundef %.046, i64 noundef %.045)
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %.sink.split, label %14

14:                                               ; preds = %.lr.ph
  %15 = add i64 %.04268, 1
  %16 = getelementptr inbounds i8, ptr %8, i64 %3
  %17 = tail call noundef ptr @strstr(ptr noundef nonnull dereferenceable(1) %16, ptr noundef nonnull dereferenceable(1) %1) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %._crit_edge, label %.lr.ph, !llvm.loop !5

19:                                               ; preds = %._crit_edge
  %20 = icmp eq i64 %.042.lcssa, -1
  br i1 %20, label %21, label %22

21:                                               ; preds = %19
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 137, ptr noundef nonnull @__PRETTY_FUNCTION__._Z9str_splitPKcS0_) #4
  unreachable

.sink.split:                                      ; preds = %.lr.ph, %._crit_edge
  %.04767.lcssa.sink = phi ptr [ %.047.lcssa, %._crit_edge ], [ %.04767, %.lr.ph ]
  tail call void @_Z14str_array_freePPc(ptr noundef %.04767.lcssa.sink)
  br label %22

22:                                               ; preds = %.sink.split, %19
  %.3 = phi ptr [ %7, %19 ], [ null, %.sink.split ]
  ret ptr %.3
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z14str_array_freePPc(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z16str_array_appendPPcmPKcm(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare noundef ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { noreturn nounwind "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 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 = { 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 #3 = { nounwind willreturn memory(read) }
attributes #4 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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