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

; 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 @_ZN11FrameBuffer15create3DTextureEijjji(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 @_ZN7Texture8create3DEiiijj(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 %80

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 %82

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 ptr, ptr %14, align 8, !tbaa !5
  %44 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %43)
  %45 = load i32, ptr %12, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %44, i32 noundef 10242, i32 noundef %45)
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %46)
  %48 = load i32, ptr %12, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %47, i32 noundef 10243, i32 noundef %48)
  %49 = load ptr, ptr %14, align 8, !tbaa !5
  %50 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %49)
  %51 = load i32, ptr %12, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %50, i32 noundef 32882, i32 noundef %51)
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %59

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

59:                                               ; preds = %41
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = icmp eq i32 %60, 1
  br i1 %61, label %62, label %67

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

67:                                               ; preds = %59
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = icmp eq i32 %68, 2
  br i1 %69, label %70, label %75

70:                                               ; preds = %67
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %71)
  call void @glTexParameteri(i32 noundef %72, i32 noundef 10240, i32 noundef 9729)
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  %74 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %73)
  call void @glTexParameteri(i32 noundef %74, i32 noundef 10241, i32 noundef 9987)
  br label %75

75:                                               ; preds = %70, %67
  br label %76

76:                                               ; preds = %75, %62
  br label %77

77:                                               ; preds = %76, %54
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64) %78)
  %79 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %79, ptr %7, align 8
  store i32 1, ptr %17, align 4
  br label %80

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

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

declare noundef zeroext i1 @_ZN7Texture8create3DEiiijj(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 @_ZN11FrameBuffer15create3DTextureEijjji(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 @_ZN7Texture8create3DEiiijj(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 %27

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)
  %19 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %19, i32 noundef 10242, i32 noundef %4)
  %20 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %20, i32 noundef 10243, i32 noundef %4)
  %21 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %21, i32 noundef 32882, i32 noundef %4)
  switch i32 %5, label %23 [
    i32 0, label %.sink.split
    i32 1, label %22
  ]

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

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

.sink.split:                                      ; preds = %23, %18, %22
  %.sink29 = phi i32 [ 9729, %22 ], [ 9728, %18 ], [ 9729, %23 ]
  %.sink28 = phi i32 [ 9729, %22 ], [ 9728, %18 ], [ 9987, %23 ]
  %24 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %24, i32 noundef 10240, i32 noundef %.sink29)
  %25 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  tail call void @glTexParameteri(i32 noundef %25, i32 noundef 10241, i32 noundef %.sink28)
  br label %26

26:                                               ; preds = %.sink.split, %23
  tail call void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  br label %27

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

declare noundef zeroext i1 @_ZN7Texture8create3DEiiijj(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