; LLVM IR from syby119/CG-projects :: projects/base/texture_cubemap.ll (ZN14TextureCubemapC2Eiiijj)

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

@_ZTV14TextureCubemap = external dso_local unnamed_addr constant { [9 x ptr] }, align 8
@glad_glBindTexture = external global ptr, align 8
@glad_glTexParameteri = external global ptr, align 8
@glad_glTexImage2D = external global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14TextureCubemapC2Eiiijj(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  %16 = load ptr, ptr %7, align 8
  call void @_ZN7TextureC2Ev(ptr noundef nonnull align 8 dereferenceable(12) %16)
  store ptr getelementptr inbounds inrange(-16, 56) ({ [9 x ptr] }, ptr @_ZTV14TextureCubemap, i32 0, i32 0, i32 2), ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.Texture, ptr %16, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !13
  invoke void %17(i32 noundef 34067, i32 noundef %19)
          to label %20 unwind label %35

20:                                               ; preds = %6
  %21 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  invoke void %21(i32 noundef 34067, i32 noundef 10242, i32 noundef 33071)
          to label %22 unwind label %35

22:                                               ; preds = %20
  %23 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  invoke void %23(i32 noundef 34067, i32 noundef 10243, i32 noundef 33071)
          to label %24 unwind label %35

24:                                               ; preds = %22
  %25 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  invoke void %25(i32 noundef 34067, i32 noundef 32882, i32 noundef 33071)
          to label %26 unwind label %35

26:                                               ; preds = %24
  %27 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  invoke void %27(i32 noundef 34067, i32 noundef 10241, i32 noundef 9728)
          to label %28 unwind label %35

28:                                               ; preds = %26
  %29 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !5
  invoke void %29(i32 noundef 34067, i32 noundef 10240, i32 noundef 9728)
          to label %30 unwind label %35

30:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %49, %30
  %32 = load i32, ptr %15, align 4, !tbaa !9
  %33 = icmp ult i32 %32, 6
  br i1 %33, label %39, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %56

35:                                               ; preds = %56, %28, %26, %24, %22, %20, %6
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %13, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %14, align 4
  br label %59

39:                                               ; preds = %31
  %40 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !5
  %41 = load i32, ptr %15, align 4, !tbaa !9
  %42 = add i32 34069, %41
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = load i32, ptr %12, align 4, !tbaa !9
  invoke void %40(i32 noundef %42, i32 noundef 0, i32 noundef %43, i32 noundef %44, i32 noundef %45, i32 noundef 0, i32 noundef %46, i32 noundef %47, ptr noundef null)
          to label %48 unwind label %52

48:                                               ; preds = %39
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %15, align 4, !tbaa !9
  %51 = add i32 %50, 1
  store i32 %51, ptr %15, align 4, !tbaa !9
  br label %31, !llvm.loop !15

52:                                               ; preds = %39
  %53 = landingpad { ptr, i32 }
          cleanup
  %54 = extractvalue { ptr, i32 } %53, 0
  store ptr %54, ptr %13, align 8
  %55 = extractvalue { ptr, i32 } %53, 1
  store i32 %55, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %59

56:                                               ; preds = %34
  %57 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !5
  invoke void %57(i32 noundef 34067, i32 noundef 0)
          to label %58 unwind label %35

58:                                               ; preds = %56
  ret void

59:                                               ; preds = %52, %35
  call void @_ZN7TextureD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %16) #4
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %13, align 8
  %62 = load i32, ptr %14, align 4
  %63 = insertvalue { ptr, i32 } poison, ptr %61, 0
  %64 = insertvalue { ptr, i32 } %63, i32 %62, 1
  resume { ptr, i32 } %64
}

declare void @_ZN7TextureC2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: nounwind
declare void @_ZN7TextureD2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #3

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTS7Texture", !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@_ZTV14TextureCubemap = external dso_local unnamed_addr constant { [9 x ptr] }, align 8
@glad_glBindTexture = external local_unnamed_addr global ptr, align 8
@glad_glTexParameteri = external local_unnamed_addr global ptr, align 8
@glad_glTexImage2D = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14TextureCubemapC2Eiiijj(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN7TextureC2Ev(ptr noundef nonnull align 8 dereferenceable(12) %0)
  store ptr getelementptr inbounds inrange(-16, 56) (i8, ptr @_ZTV14TextureCubemap, i64 16), ptr %0, align 8, !tbaa !5
  %7 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !8
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !11
  invoke void %7(i32 noundef 34067, i32 noundef %9)
          to label %10 unwind label %21

10:                                               ; preds = %6
  %11 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !8
  invoke void %11(i32 noundef 34067, i32 noundef 10242, i32 noundef 33071)
          to label %12 unwind label %21

12:                                               ; preds = %10
  %13 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !8
  invoke void %13(i32 noundef 34067, i32 noundef 10243, i32 noundef 33071)
          to label %14 unwind label %21

14:                                               ; preds = %12
  %15 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !8
  invoke void %15(i32 noundef 34067, i32 noundef 32882, i32 noundef 33071)
          to label %16 unwind label %21

16:                                               ; preds = %14
  %17 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !8
  invoke void %17(i32 noundef 34067, i32 noundef 10241, i32 noundef 9728)
          to label %18 unwind label %21

18:                                               ; preds = %16
  %19 = load ptr, ptr @glad_glTexParameteri, align 8, !tbaa !8
  invoke void %19(i32 noundef 34067, i32 noundef 10240, i32 noundef 9728)
          to label %.preheader.preheader unwind label %21

.preheader.preheader:                             ; preds = %18
  %20 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !8
  invoke void %20(i32 noundef 34069, i32 noundef 0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef 0, i32 noundef %4, i32 noundef %5, ptr noundef null)
          to label %.preheader.1 unwind label %30

21:                                               ; preds = %28, %18, %16, %14, %12, %10, %6
  %22 = landingpad { ptr, i32 }
          cleanup
  br label %33

.preheader.1:                                     ; preds = %.preheader.preheader
  %23 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !8
  invoke void %23(i32 noundef 34070, i32 noundef 0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef 0, i32 noundef %4, i32 noundef %5, ptr noundef null)
          to label %.preheader.2 unwind label %30

.preheader.2:                                     ; preds = %.preheader.1
  %24 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !8
  invoke void %24(i32 noundef 34071, i32 noundef 0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef 0, i32 noundef %4, i32 noundef %5, ptr noundef null)
          to label %.preheader.3 unwind label %30

.preheader.3:                                     ; preds = %.preheader.2
  %25 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !8
  invoke void %25(i32 noundef 34072, i32 noundef 0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef 0, i32 noundef %4, i32 noundef %5, ptr noundef null)
          to label %.preheader.4 unwind label %30

.preheader.4:                                     ; preds = %.preheader.3
  %26 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !8
  invoke void %26(i32 noundef 34073, i32 noundef 0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef 0, i32 noundef %4, i32 noundef %5, ptr noundef null)
          to label %.preheader.5 unwind label %30

.preheader.5:                                     ; preds = %.preheader.4
  %27 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !8
  invoke void %27(i32 noundef 34074, i32 noundef 0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef 0, i32 noundef %4, i32 noundef %5, ptr noundef null)
          to label %28 unwind label %30

28:                                               ; preds = %.preheader.5
  %29 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !8
  invoke void %29(i32 noundef 34067, i32 noundef 0)
          to label %32 unwind label %21

30:                                               ; preds = %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %31 = landingpad { ptr, i32 }
          cleanup
  br label %33

32:                                               ; preds = %28
  ret void

33:                                               ; preds = %30, %21
  %.pn = phi { ptr, i32 } [ %31, %30 ], [ %22, %21 ]
  tail call void @_ZN7TextureD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %0) #3
  resume { ptr, i32 } %.pn
}

declare void @_ZN7TextureC2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN7TextureD2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #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 = { "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 "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 = !{!"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, !13, i64 8}
!12 = !{!"_ZTS7Texture", !13, i64 8}
!13 = !{!"int", !10, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass