; LLVM IR from erwincoumans/tiny-differentiable-simulator :: src/visualizer/opengl/tiny_font_stash.ll (Z10sth_deleteP9sth_stash)

; 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.sth_stash = type { i32, i32, float, float, ptr, ptr, i32, ptr }
%struct.sth_texture = type { %union.anon, ptr, [128 x %struct.sth_row], i32, i32, [2048 x %struct.Vertex], ptr }
%union.anon = type { ptr }
%struct.sth_row = type { i16, i16, i16 }
%struct.Vertex = type { %struct.vec4, %struct.vec4, %struct.vec2 }
%struct.vec4 = type { [4 x float] }
%struct.vec2 = type { [2 x float] }
%struct.sth_font = type { i32, i32, %struct.stbtt_fontinfo, ptr, ptr, [256 x i32], i32, float, float, float, ptr }
%struct.stbtt_fontinfo = type { ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, 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
declare void @free(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10sth_deleteP9sth_stash(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store i32 1, ptr %7, align 4
  br label %74

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.sth_stash, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %3, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %18, %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %36

18:                                               ; preds = %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %19, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.sth_texture, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  call void @free(ptr noundef %22) #3
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.sth_texture, ptr %23, i32 0, i32 1
  store ptr null, ptr %24, align 8, !tbaa !13
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.sth_texture, ptr %25, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  store ptr %27, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.sth_stash, ptr %28, i32 0, i32 7
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %30, align 8, !tbaa !17
  %33 = getelementptr inbounds ptr, ptr %32, i64 5
  %34 = load ptr, ptr %33, align 8
  call void %34(ptr noundef nonnull align 8 dereferenceable(8) %30, ptr noundef %31, ptr noundef null, i32 noundef 0, i32 noundef 0)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %35) #3
  br label %15, !llvm.loop !19

36:                                               ; preds = %15
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.sth_stash, ptr %37, i32 0, i32 5
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  store ptr %39, ptr %5, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %70, %36
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %72

43:                                               ; preds = %40
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %44, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.sth_font, ptr %45, i32 0, i32 10
  %47 = load ptr, ptr %46, align 8, !tbaa !22
  store ptr %47, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.sth_font, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !25
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %56

52:                                               ; preds = %43
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.sth_font, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !25
  call void @free(ptr noundef %55) #3
  br label %56

56:                                               ; preds = %52, %43
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.sth_font, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !26
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %70

61:                                               ; preds = %56
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sth_font, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !27
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %70

66:                                               ; preds = %61
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.sth_font, ptr %67, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !27
  call void @free(ptr noundef %69) #3
  br label %70

70:                                               ; preds = %66, %61, %56
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %71) #3
  br label %40, !llvm.loop !28

72:                                               ; preds = %40
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %73) #3
  store i32 0, ptr %7, align 4
  br label %74

74:                                               ; preds = %72, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %75 = load i32, ptr %7, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 1, label %76
  ]

76:                                               ; preds = %74, %74
  ret void

77:                                               ; preds = %74
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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, !6, i64 16}
!10 = !{!"_ZTS9sth_stash", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 12, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTS11sth_texture", !7, i64 0, !6, i64 8, !7, i64 16, !11, i64 784, !11, i64 788, !7, i64 792, !6, i64 82712}
!15 = !{!14, !6, i64 82712}
!16 = !{!10, !6, i64 40}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !6, i64 24}
!22 = !{!23, !6, i64 1120}
!23 = !{!"_ZTS8sth_font", !11, i64 0, !11, i64 4, !24, i64 8, !6, i64 64, !6, i64 72, !7, i64 80, !11, i64 1104, !12, i64 1108, !12, i64 1112, !12, i64 1116, !6, i64 1120}
!24 = !{!"_ZTS14stbtt_fontinfo", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52}
!25 = !{!23, !6, i64 72}
!26 = !{!23, !11, i64 4}
!27 = !{!23, !6, i64 64}
!28 = distinct !{!28, !20}


; 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 willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10sth_deleteP9sth_stash(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %31, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not2529 = icmp eq ptr %4, null
  br i1 %.not2529, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %.02130 = phi ptr [ %4, %.lr.ph ], [ %10, %6 ]
  %7 = getelementptr inbounds i8, ptr %.02130, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  tail call void @free(ptr noundef %8) #2
  store ptr null, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %.02130, i64 82712
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = load ptr, ptr %5, align 8, !tbaa !15
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %12, i64 40
  %14 = load ptr, ptr %13, align 8
  tail call void %14(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull %.02130, ptr noundef null, i32 noundef 0, i32 noundef 0)
  tail call void @free(ptr noundef nonnull %.02130) #2
  %.not25 = icmp eq ptr %10, null
  br i1 %.not25, label %._crit_edge, label %6, !llvm.loop !18

._crit_edge:                                      ; preds = %6, %2
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %.not2631 = icmp eq ptr %16, null
  br i1 %.not2631, label %._crit_edge35, label %.lr.ph34

.lr.ph34:                                         ; preds = %._crit_edge, %30
  %.032 = phi ptr [ %18, %30 ], [ %16, %._crit_edge ]
  %17 = getelementptr inbounds i8, ptr %.032, i64 1120
  %18 = load ptr, ptr %17, align 8, !tbaa !21
  %19 = getelementptr inbounds i8, ptr %.032, i64 72
  %20 = load ptr, ptr %19, align 8, !tbaa !24
  %.not27 = icmp eq ptr %20, null
  br i1 %.not27, label %22, label %21

21:                                               ; preds = %.lr.ph34
  tail call void @free(ptr noundef nonnull %20) #2
  br label %22

22:                                               ; preds = %21, %.lr.ph34
  %23 = getelementptr inbounds i8, ptr %.032, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !25
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %30

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %.032, i64 64
  %28 = load ptr, ptr %27, align 8, !tbaa !26
  %.not28 = icmp eq ptr %28, null
  br i1 %.not28, label %30, label %29

29:                                               ; preds = %26
  tail call void @free(ptr noundef nonnull %28) #2
  br label %30

30:                                               ; preds = %29, %26, %22
  tail call void @free(ptr noundef nonnull %.032) #2
  %.not26 = icmp eq ptr %18, null
  br i1 %.not26, label %._crit_edge35, label %.lr.ph34, !llvm.loop !27

._crit_edge35:                                    ; preds = %30, %._crit_edge
  tail call void @free(ptr noundef %0) #2
  br label %31

31:                                               ; preds = %1, %._crit_edge35
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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, !11, i64 16}
!6 = !{!"_ZTS9sth_stash", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 12, !11, i64 16, !11, i64 24, !7, i64 32, !11, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"_ZTS11sth_texture", !8, i64 0, !11, i64 8, !8, i64 16, !7, i64 784, !7, i64 788, !8, i64 792, !11, i64 82712}
!14 = !{!13, !11, i64 82712}
!15 = !{!6, !11, i64 40}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !9, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !11, i64 24}
!21 = !{!22, !11, i64 1120}
!22 = !{!"_ZTS8sth_font", !7, i64 0, !7, i64 4, !23, i64 8, !11, i64 64, !11, i64 72, !8, i64 80, !7, i64 1104, !10, i64 1108, !10, i64 1112, !10, i64 1116, !11, i64 1120}
!23 = !{!"_ZTS14stbtt_fontinfo", !11, i64 0, !11, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52}
!24 = !{!22, !11, i64 72}
!25 = !{!22, !7, i64 4}
!26 = !{!22, !11, i64 64}
!27 = distinct !{!27, !19}


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