; LLVM IR from steps3d/graphics-book :: Code/Core/Framebuffer.ll (ZN11FrameBuffer23createColorTextureArrayEijjji)

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64)) #1 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

declare void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64), i1 noundef zeroext) unnamed_addr #3

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

; Function Attrs: nounwind
declare void @_ZN7TextureD1Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #5

declare void @_ZN7Texture4bindEi(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) #3

declare void @glTexParameteri(i32 noundef, i32 noundef, i32 noundef) #3

declare void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64)) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN11FrameBuffer23createColorTextureArrayEijjji(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #6 align 2 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !9
  %18 = load ptr, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %19 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 64) #8
  %20 = load i32, ptr %13, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 2
  invoke void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64) %19, i1 noundef zeroext %21)
          to label %22 unwind label %37

22:                                               ; preds = %6
  store ptr %19, ptr %14, align 8, !tbaa !5
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.FrameBuffer, ptr %18, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = getelementptr inbounds %class.FrameBuffer, ptr %18, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = call noundef zeroext i1 @_ZN7Texture13createArray2DEiiijj(ptr noundef nonnull align 8 dereferenceable(64) %23, i32 noundef %25, i32 noundef %27, i32 noundef %28, i32 noundef %29, i32 noundef %30)
  br i1 %31, label %41, label %32

32:                                               ; preds = %22
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  call void @_ZN7TextureD1Ev(ptr noundef nonnull align 8 dereferenceable(64) %33) #7
  call void @_ZdlPvm(ptr noundef %33, i64 noundef 64) #9
  br label %36

36:                                               ; preds = %35, %32
  store ptr null, ptr %7, align 8
  store i32 1, ptr %17, align 4
  br label %77

37:                                               ; preds = %6
  %38 = landingpad { ptr, i32 }
          cleanup
  %39 = extractvalue { ptr, i32 } %38, 0
  store ptr %39, ptr %15, align 8
  %40 = extractvalue { ptr, i32 } %38, 1
  store i32 %40, ptr %16, align 4
  call void @_ZdlPvm(ptr noundef %19, i64 noundef 64) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  br label %79

41:                                               ; preds = %22
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN7Texture4bindEi(ptr noundef nonnull align 8 dereferenceable(64) %42, i32 noundef 0)
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %50

45:                                               ; preds = %41
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %46)
  call void @glTexParameteri(i32 noundef %47, i32 noundef 10240, i32 noundef 9728)
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %48)
  call void @glTexParameteri(i32 noundef %49, i32 noundef 10241, i32 noundef 9728)
  br label %68

50:                                               ; preds = %41
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = icmp eq i32 %51, 1
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %54)
  call void @glTexParameteri(i32 noundef %55, i32 noundef 10240, i32 noundef 9729)
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %56)
  call void @glTexParameteri(i32 noundef %57, i32 noundef 10241, i32 noundef 9729)
  br label %67

58:                                               ; preds = %50
  %59 = load i32, ptr %13, align 4, !tbaa !9
  %60 = icmp eq i32 %59, 2
  br i1 %60, label %61, label %66

61:                                               ; preds = %58
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %62)
  call void @glTexParameteri(i32 noundef %63, i32 noundef 10240, i32 noundef 9729)
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %64)
  call void @glTexParameteri(i32 noundef %65, i32 noundef 10241, i32 noundef 9987)
  br label %66

66:                                               ; preds = %61, %58
  br label %67

67:                                               ; preds = %66, %53
  br label %68

68:                                               ; preds = %67, %45
  %69 = load ptr, ptr %14, align 8, !tbaa !5
  %70 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %69)
  %71 = load i32, ptr %12, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %70, i32 noundef 10242, i32 noundef %71)
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %72)
  %74 = load i32, ptr %12, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %73, i32 noundef 10243, i32 noundef %74)
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64) %75)
  %76 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %76, ptr %7, align 8
  store i32 1, ptr %17, align 4
  br label %77

77:                                               ; preds = %68, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  %78 = load ptr, ptr %7, align 8
  ret ptr %78

79:                                               ; preds = %37
  %80 = load ptr, ptr %15, align 8
  %81 = load i32, ptr %16, align 4
  %82 = insertvalue { ptr, i32 } poison, ptr %80, 0
  %83 = insertvalue { ptr, i32 } %82, i32 %81, 1
  resume { ptr, i32 } %83
}

declare noundef zeroext i1 @_ZN7Texture13createArray2DEiiijj(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nobuiltin allocsize(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 = { "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 = { 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 #5 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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, !10, i64 4}
!12 = !{!"_ZTS11FrameBuffer", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !10, i64 80, !10, i64 84, !7, i64 88}
!13 = !{!12, !10, i64 8}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #0 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

declare void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64), i1 noundef zeroext) unnamed_addr #2

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

; Function Attrs: nounwind
declare void @_ZN7TextureD1Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #4

declare void @_ZN7Texture4bindEi(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) local_unnamed_addr #2

declare void @glTexParameteri(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN11FrameBuffer23createColorTextureArrayEijjji(ptr nocapture noundef nonnull readonly align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #5 align 2 personality ptr @__gxx_personality_v0 {
  %7 = tail call noalias noundef nonnull dereferenceable(64) ptr @_Znwm(i64 noundef 64) #6
  %8 = icmp eq i32 %5, 2
  invoke void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64) %7, i1 noundef zeroext %8)
          to label %9 unwind label %16

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !10
  %14 = tail call noundef zeroext i1 @_ZN7Texture13createArray2DEiiijj(ptr noundef nonnull align 8 dereferenceable(64) %7, i32 noundef %11, i32 noundef %13, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br i1 %14, label %18, label %15

15:                                               ; preds = %9
  tail call void @_ZN7TextureD1Ev(ptr noundef nonnull align 8 dereferenceable(64) %7) #7
  tail call void @_ZdlPvm(ptr noundef nonnull %7, i64 noundef 64) #8
  br label %26

16:                                               ; preds = %6
  %17 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %7, i64 noundef 64) #8
  resume { ptr, i32 } %17

18:                                               ; preds = %9
  tail call void @_ZN7Texture4bindEi(ptr noundef nonnull align 8 dereferenceable(64) %7, i32 noundef 0)
  switch i32 %5, label %20 [
    i32 0, label %.sink.split
    i32 1, label %19
  ]

19:                                               ; preds = %18
  br label %.sink.split

20:                                               ; preds = %18
  br i1 %8, label %.sink.split, label %23

.sink.split:                                      ; preds = %20, %18, %19
  %.sink27 = phi i32 [ 9729, %19 ], [ 9728, %18 ], [ 9729, %20 ]
  %.sink26 = phi i32 [ 9729, %19 ], [ 9728, %18 ], [ 9987, %20 ]
  %21 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %21, i32 noundef 10240, i32 noundef %.sink27)
  %22 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %22, i32 noundef 10241, i32 noundef %.sink26)
  br label %23

23:                                               ; preds = %.sink.split, %20
  %24 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %24, i32 noundef 10242, i32 noundef %4)
  %25 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %25, i32 noundef 10243, i32 noundef %4)
  tail call void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  br label %26

26:                                               ; preds = %23, %15
  %.0 = phi ptr [ %7, %23 ], [ null, %15 ]
  ret ptr %.0
}

declare noundef zeroext i1 @_ZN7Texture13createArray2DEiiijj(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { nobuiltin allocsize(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 = { "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 = { 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 #4 = { 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 #5 = { 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 #6 = { builtin allocsize(0) }
attributes #7 = { nounwind }
attributes #8 = { builtin 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, !7, i64 4}
!6 = !{!"_ZTS11FrameBuffer", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !7, i64 80, !7, i64 84, !8, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}


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