; LLVM IR from aap/librw :: src/image.ll (ZN2rw10ColorQuant4Node7destroyEv)

; 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.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"struct.rw::ColorQuant::Node" = type { i32, i32, i32, i32, i32, ptr, [16 x ptr], %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }

@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8

; 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
define dso_local void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %22, %1
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 16
  br i1 %7, label %8, label %25

8:                                                ; preds = %5
  %9 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %4, i32 0, i32 6
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [16 x ptr], ptr %9, i64 0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %21

15:                                               ; preds = %8
  %16 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %4, i32 0, i32 6
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [16 x ptr], ptr %16, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %20)
  br label %21

21:                                               ; preds = %15, %8
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !11

25:                                               ; preds = %5
  %26 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %4, i32 0, i32 7
  %27 = getelementptr inbounds %"struct.rw::LLLink", ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %32

30:                                               ; preds = %25
  %31 = getelementptr inbounds %"struct.rw::ColorQuant::Node", ptr %4, i32 0, i32 7
  call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %31)
  br label %32

32:                                               ; preds = %30, %25
  %33 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !16
  call void %33(ptr noundef %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 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 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 160}
!14 = !{!"_ZTSN2rw10ColorQuant4NodeE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !7, i64 32, !15, i64 160}
!15 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!16 = !{!17, !6, i64 16}
!17 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}


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

%"struct.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }

@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not5 = icmp eq ptr %3, null
  br i1 %.not5, label %5, label %4

4:                                                ; preds = %1
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %3)
  br label %5

5:                                                ; preds = %1, %4
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not5.1 = icmp eq ptr %7, null
  br i1 %.not5.1, label %9, label %8

8:                                                ; preds = %5
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %7)
  br label %9

9:                                                ; preds = %8, %5
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %.not5.2 = icmp eq ptr %11, null
  br i1 %.not5.2, label %13, label %12

12:                                               ; preds = %9
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %11)
  br label %13

13:                                               ; preds = %12, %9
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %.not5.3 = icmp eq ptr %15, null
  br i1 %.not5.3, label %17, label %16

16:                                               ; preds = %13
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %15)
  br label %17

17:                                               ; preds = %16, %13
  %18 = getelementptr inbounds i8, ptr %0, i64 64
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not5.4 = icmp eq ptr %19, null
  br i1 %.not5.4, label %21, label %20

20:                                               ; preds = %17
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %19)
  br label %21

21:                                               ; preds = %20, %17
  %22 = getelementptr inbounds i8, ptr %0, i64 72
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %.not5.5 = icmp eq ptr %23, null
  br i1 %.not5.5, label %25, label %24

24:                                               ; preds = %21
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %23)
  br label %25

25:                                               ; preds = %24, %21
  %26 = getelementptr inbounds i8, ptr %0, i64 80
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %.not5.6 = icmp eq ptr %27, null
  br i1 %.not5.6, label %29, label %28

28:                                               ; preds = %25
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %27)
  br label %29

29:                                               ; preds = %28, %25
  %30 = getelementptr inbounds i8, ptr %0, i64 88
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %.not5.7 = icmp eq ptr %31, null
  br i1 %.not5.7, label %33, label %32

32:                                               ; preds = %29
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %31)
  br label %33

33:                                               ; preds = %32, %29
  %34 = getelementptr inbounds i8, ptr %0, i64 96
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %.not5.8 = icmp eq ptr %35, null
  br i1 %.not5.8, label %37, label %36

36:                                               ; preds = %33
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %35)
  br label %37

37:                                               ; preds = %36, %33
  %38 = getelementptr inbounds i8, ptr %0, i64 104
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %.not5.9 = icmp eq ptr %39, null
  br i1 %.not5.9, label %41, label %40

40:                                               ; preds = %37
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %39)
  br label %41

41:                                               ; preds = %40, %37
  %42 = getelementptr inbounds i8, ptr %0, i64 112
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %.not5.10 = icmp eq ptr %43, null
  br i1 %.not5.10, label %45, label %44

44:                                               ; preds = %41
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %43)
  br label %45

45:                                               ; preds = %44, %41
  %46 = getelementptr inbounds i8, ptr %0, i64 120
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %.not5.11 = icmp eq ptr %47, null
  br i1 %.not5.11, label %49, label %48

48:                                               ; preds = %45
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %47)
  br label %49

49:                                               ; preds = %48, %45
  %50 = getelementptr inbounds i8, ptr %0, i64 128
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %.not5.12 = icmp eq ptr %51, null
  br i1 %.not5.12, label %53, label %52

52:                                               ; preds = %49
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %51)
  br label %53

53:                                               ; preds = %52, %49
  %54 = getelementptr inbounds i8, ptr %0, i64 136
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %.not5.13 = icmp eq ptr %55, null
  br i1 %.not5.13, label %57, label %56

56:                                               ; preds = %53
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %55)
  br label %57

57:                                               ; preds = %56, %53
  %58 = getelementptr inbounds i8, ptr %0, i64 144
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %.not5.14 = icmp eq ptr %59, null
  br i1 %.not5.14, label %61, label %60

60:                                               ; preds = %57
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %59)
  br label %61

61:                                               ; preds = %60, %57
  %62 = getelementptr inbounds i8, ptr %0, i64 152
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %.not5.15 = icmp eq ptr %63, null
  br i1 %.not5.15, label %65, label %64

64:                                               ; preds = %61
  tail call void @_ZN2rw10ColorQuant4Node7destroyEv(ptr noundef nonnull align 8 dereferenceable(176) %63)
  br label %65

65:                                               ; preds = %64, %61
  %66 = getelementptr inbounds i8, ptr %0, i64 160
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %.not = icmp eq ptr %67, null
  br i1 %.not, label %69, label %68

68:                                               ; preds = %65
  tail call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %66)
  br label %69

69:                                               ; preds = %68, %65
  %70 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !13
  tail call void %70(ptr noundef nonnull %0)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 160}
!10 = !{!"_ZTSN2rw10ColorQuant4NodeE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !7, i64 32, !12, i64 160}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass