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

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

%class.TinyGLPrimitiveRenderer = type { ptr, i32, i32, ptr, ptr }
%struct.PrimInternalData = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@_ZTV23TinyGLPrimitiveRenderer = external dso_local unnamed_addr constant { [4 x ptr] }, align 8
@glad_glBindTexture = external global ptr, align 8
@glad_glUseProgram = external global ptr, align 8
@glad_glDeleteProgram = external global ptr, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN23TinyGLPrimitiveRendererD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV23TinyGLPrimitiveRenderer, i32 0, i32 0, i32 2), ptr %3, align 8, !tbaa !9
  %4 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !5
  invoke void %4(i32 noundef 3553, i32 noundef 0)
          to label %5 unwind label %26

5:                                                ; preds = %1
  %6 = load ptr, ptr @glad_glUseProgram, align 8, !tbaa !5
  invoke void %6(i32 noundef 0)
          to label %7 unwind label %26

7:                                                ; preds = %5
  %8 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !5
  invoke void %8(i32 noundef 3553, i32 noundef 0)
          to label %9 unwind label %26

9:                                                ; preds = %7
  %10 = load ptr, ptr @glad_glDeleteProgram, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.TinyGLPrimitiveRenderer, ptr %3, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.PrimInternalData, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !14
  invoke void %10(i32 noundef %14)
          to label %15 unwind label %26

15:                                               ; preds = %9
  %16 = getelementptr inbounds %class.TinyGLPrimitiveRenderer, ptr %3, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @_ZdlPvm(ptr noundef %17, i64 noundef 56) #3
  br label %20

20:                                               ; preds = %19, %15
  %21 = getelementptr inbounds %class.TinyGLPrimitiveRenderer, ptr %3, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = icmp eq ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @_ZdlPvm(ptr noundef %22, i64 noundef 655368) #3
  br label %25

25:                                               ; preds = %24, %20
  ret void

26:                                               ; preds = %9, %7, %5, %1
  %27 = landingpad { ptr, i32 }
          catch ptr null
  %28 = extractvalue { ptr, i32 } %27, 0
  call void @__clang_call_terminate(ptr %28) #4
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

attributes #0 = { nobuiltin 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 = { noinline noreturn nounwind uwtable "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 = { builtin nounwind }
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 = !{!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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS23TinyGLPrimitiveRenderer", !13, i64 8, !13, i64 12, !6, i64 16, !6, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTS16PrimInternalData", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52}
!16 = !{!12, !6, i64 24}


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

@_ZTV23TinyGLPrimitiveRenderer = external dso_local unnamed_addr constant { [4 x ptr] }, align 8
@glad_glBindTexture = external local_unnamed_addr global ptr, align 8
@glad_glUseProgram = external local_unnamed_addr global ptr, align 8
@glad_glDeleteProgram = external local_unnamed_addr global ptr, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN23TinyGLPrimitiveRendererD2Ev(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  store ptr getelementptr inbounds inrange(-16, 16) (i8, ptr @_ZTV23TinyGLPrimitiveRenderer, i64 16), ptr %0, align 8, !tbaa !5
  %2 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !8
  invoke void %2(i32 noundef 3553, i32 noundef 0)
          to label %3 unwind label %22

3:                                                ; preds = %1
  %4 = load ptr, ptr @glad_glUseProgram, align 8, !tbaa !8
  invoke void %4(i32 noundef 0)
          to label %5 unwind label %22

5:                                                ; preds = %3
  %6 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !8
  invoke void %6(i32 noundef 3553, i32 noundef 0)
          to label %7 unwind label %22

7:                                                ; preds = %5
  %8 = load ptr, ptr @glad_glDeleteProgram, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %10, align 4, !tbaa !14
  invoke void %8(i32 noundef %11)
          to label %12 unwind label %22

12:                                               ; preds = %7
  %13 = load ptr, ptr %9, align 8, !tbaa !11
  %14 = icmp eq ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  tail call void @_ZdlPvm(ptr noundef nonnull %13, i64 noundef 56) #3
  br label %16

16:                                               ; preds = %15, %12
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = icmp eq ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  tail call void @_ZdlPvm(ptr noundef nonnull %18, i64 noundef 655368) #3
  br label %21

21:                                               ; preds = %20, %16
  ret void

22:                                               ; preds = %7, %5, %3, %1
  %23 = landingpad { ptr, i32 }
          catch ptr null
  %24 = extractvalue { ptr, i32 } %23, 0
  tail call void @__clang_call_terminate(ptr %24) #4
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #2

attributes #0 = { nobuiltin 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 = { noinline noreturn nounwind uwtable "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 = { builtin nounwind }
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 = !{!6, !6, i64 0}
!6 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !9, i64 16}
!12 = !{!"_ZTS23TinyGLPrimitiveRenderer", !13, i64 8, !13, i64 12, !9, i64 16, !9, i64 24}
!13 = !{!"int", !10, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTS16PrimInternalData", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52}
!16 = !{!12, !9, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass