; LLVM IR from Overload-Technologies/Overload :: Dependencies/assimp/code/PostProcessing (ValidateDataStructure)

; 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.aiString = type { i32, [1024 x i8] }

@.str.117 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.118 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.119 = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: mustprogress noreturn uwtable
declare dso_local void @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ...) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Assimp17ValidateDSProcess8ValidateEPK8aiString(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.aiString, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = icmp ugt i64 %10, 1024
  br i1 %11, label %12, label %16

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.aiString, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !9
  call void (ptr, ptr, ...) @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef @.str.117, i32 noundef %15, i64 noundef 1024) #3
  unreachable

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.aiString, ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds [1024 x i8], ptr %18, i64 0, i64 0
  store ptr %19, ptr %5, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %49, %16
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !12
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 0, %24
  br i1 %25, label %26, label %41

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.aiString, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.aiString, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds [1024 x i8], ptr %32, i64 0, i64 0
  %34 = ptrtoint ptr %30 to i64
  %35 = ptrtoint ptr %33 to i64
  %36 = sub i64 %34, %35
  %37 = trunc i64 %36 to i32
  %38 = icmp ne i32 %29, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %26
  call void (ptr, ptr, ...) @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef @.str.118) #3
  unreachable

40:                                               ; preds = %26
  br label %52

41:                                               ; preds = %21
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.aiString, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds [1024 x i8], ptr %44, i64 0, i64 1024
  %46 = icmp uge ptr %42, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  call void (ptr, ptr, ...) @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef @.str.119) #3
  unreachable

48:                                               ; preds = %41
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %5, align 8, !tbaa !5
  br label %20, !llvm.loop !13

52:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

attributes #0 = { mustprogress noreturn 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 = { 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 #3 = { noreturn }
attributes #4 = { 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, !11, i64 0}
!10 = !{!"_ZTS8aiString", !11, i64 0, !7, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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.117 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.118 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.119 = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: mustprogress noreturn uwtable
declare dso_local void @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ...) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Assimp17ValidateDSProcess8ValidateEPK8aiString(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 align 2 {
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp ugt i32 %3, 1024
  br i1 %4, label %7, label %.preheader

.preheader:                                       ; preds = %2
  %.0.ptr14 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i8, ptr %.0.ptr14, align 1, !tbaa !10
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %._crit_edge, label %.lr.ph

7:                                                ; preds = %2
  tail call void (ptr, ptr, ...) @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull @.str.117, i32 noundef %3, i64 noundef 1024) #2
  unreachable

._crit_edge.loopexit:                             ; preds = %20, %.lr.ph.3, %.lr.ph.2, %.lr.ph.1, %.lr.ph
  %.0.add.lcssa = phi i64 [ %.0.add, %.lr.ph ], [ %.0.add.1, %.lr.ph.1 ], [ %.0.add.2, %.lr.ph.2 ], [ %.0.add.3, %.lr.ph.3 ], [ %.0.add.4, %20 ]
  %8 = trunc i64 %.0.add.lcssa to i32
  %9 = add nsw i32 %8, -4
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.0.idx.lcssa = phi i32 [ 0, %.preheader ], [ %9, %._crit_edge.loopexit ]
  %.not12 = icmp eq i32 %3, %.0.idx.lcssa
  br i1 %.not12, label %23, label %10

10:                                               ; preds = %._crit_edge
  tail call void (ptr, ptr, ...) @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull @.str.118) #2
  unreachable

.lr.ph:                                           ; preds = %.preheader, %20
  %.0.idx15 = phi i64 [ %.0.add.4, %20 ], [ 4, %.preheader ]
  %.0.add = add nuw nsw i64 %.0.idx15, 1
  %.0.ptr = getelementptr inbounds i8, ptr %1, i64 %.0.add
  %11 = load i8, ptr %.0.ptr, align 1, !tbaa !10
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %._crit_edge.loopexit, label %.lr.ph.1, !llvm.loop !11

13:                                               ; preds = %.lr.ph.4
  tail call void (ptr, ptr, ...) @_ZN6Assimp17ValidateDSProcess11ReportErrorEPKcz(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull @.str.119) #2
  unreachable

.lr.ph.1:                                         ; preds = %.lr.ph
  %.0.add.1 = add nuw nsw i64 %.0.idx15, 2
  %.0.ptr.1 = getelementptr inbounds i8, ptr %1, i64 %.0.add.1
  %14 = load i8, ptr %.0.ptr.1, align 1, !tbaa !10
  %15 = icmp eq i8 %14, 0
  br i1 %15, label %._crit_edge.loopexit, label %.lr.ph.2, !llvm.loop !11

.lr.ph.2:                                         ; preds = %.lr.ph.1
  %.0.add.2 = add nuw nsw i64 %.0.idx15, 3
  %.0.ptr.2 = getelementptr inbounds i8, ptr %1, i64 %.0.add.2
  %16 = load i8, ptr %.0.ptr.2, align 1, !tbaa !10
  %17 = icmp eq i8 %16, 0
  br i1 %17, label %._crit_edge.loopexit, label %.lr.ph.3, !llvm.loop !11

.lr.ph.3:                                         ; preds = %.lr.ph.2
  %.0.add.3 = add nuw nsw i64 %.0.idx15, 4
  %.0.ptr.3 = getelementptr inbounds i8, ptr %1, i64 %.0.add.3
  %18 = load i8, ptr %.0.ptr.3, align 1, !tbaa !10
  %19 = icmp eq i8 %18, 0
  br i1 %19, label %._crit_edge.loopexit, label %.lr.ph.4, !llvm.loop !11

.lr.ph.4:                                         ; preds = %.lr.ph.3
  %exitcond.not.4 = icmp eq i64 %.0.add.3, 1028
  br i1 %exitcond.not.4, label %13, label %20

20:                                               ; preds = %.lr.ph.4
  %.0.add.4 = add nuw nsw i64 %.0.idx15, 5
  %.0.ptr.4 = getelementptr inbounds i8, ptr %1, i64 %.0.add.4
  %21 = load i8, ptr %.0.ptr.4, align 1, !tbaa !10
  %22 = icmp eq i8 %21, 0
  br i1 %22, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11

23:                                               ; preds = %._crit_edge
  ret void
}

attributes #0 = { mustprogress noreturn 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 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 = { noreturn }

!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, !7, i64 0}
!6 = !{!"_ZTS8aiString", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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