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

; 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: mustprogress uwtable
define dso_local noundef ptr @_ZN11FrameBuffer18createColorTextureEjjji(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %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 ptr, align 8
  %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
  %16 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %17 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 64) #8
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 2
  invoke void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64) %17, i1 noundef zeroext %19)
          to label %20 unwind label %34

20:                                               ; preds = %5
  store ptr %17, ptr %12, align 8, !tbaa !5
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.FrameBuffer, ptr %16, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = getelementptr inbounds %class.FrameBuffer, ptr %16, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = call noundef zeroext i1 @_ZN7Texture8create2DEiijj(ptr noundef nonnull align 8 dereferenceable(64) %21, i32 noundef %23, i32 noundef %25, i32 noundef %26, i32 noundef %27)
  br i1 %28, label %38, label %29

29:                                               ; preds = %20
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %32, %29
  store ptr null, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %74

34:                                               ; preds = %5
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %13, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %14, align 4
  call void @_ZdlPvm(ptr noundef %17, i64 noundef 64) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %76

38:                                               ; preds = %20
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZN7Texture4bindEi(ptr noundef nonnull align 8 dereferenceable(64) %39, i32 noundef 0)
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %47

42:                                               ; preds = %38
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %43)
  call void @glTexParameteri(i32 noundef %44, i32 noundef 10240, i32 noundef 9728)
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %45)
  call void @glTexParameteri(i32 noundef %46, i32 noundef 10241, i32 noundef 9728)
  br label %65

47:                                               ; preds = %38
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = icmp eq i32 %48, 1
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %51)
  call void @glTexParameteri(i32 noundef %52, i32 noundef 10240, i32 noundef 9729)
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %53)
  call void @glTexParameteri(i32 noundef %54, i32 noundef 10241, i32 noundef 9729)
  br label %64

55:                                               ; preds = %47
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 2
  br i1 %57, label %58, label %63

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

63:                                               ; preds = %58, %55
  br label %64

64:                                               ; preds = %63, %50
  br label %65

65:                                               ; preds = %64, %42
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %66)
  %68 = load i32, ptr %10, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %67, i32 noundef 10242, i32 noundef %68)
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %69)
  %71 = load i32, ptr %10, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %70, i32 noundef 10243, i32 noundef %71)
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64) %72)
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %73, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %74

74:                                               ; preds = %65, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  %75 = load ptr, ptr %6, align 8
  ret ptr %75

76:                                               ; preds = %34
  %77 = load ptr, ptr %13, align 8
  %78 = load i32, ptr %14, align 4
  %79 = insertvalue { ptr, i32 } poison, ptr %77, 0
  %80 = insertvalue { ptr, i32 } %79, i32 %78, 1
  resume { ptr, i32 } %80
}

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

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

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

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

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

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

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

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

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 = { 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 #3 = { 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 #4 = { "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 = { 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 #6 = { 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 #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: mustprogress uwtable
define dso_local noundef ptr @_ZN11FrameBuffer18createColorTextureEjjji(ptr nocapture noundef nonnull readonly align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %6 = tail call noalias noundef nonnull dereferenceable(64) ptr @_Znwm(i64 noundef 64) #6
  %7 = icmp eq i32 %4, 2
  invoke void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64) %6, i1 noundef zeroext %7)
          to label %8 unwind label %15

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

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

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

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

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

19:                                               ; preds = %17
  br i1 %7, label %.sink.split, label %22

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

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

25:                                               ; preds = %22, %14
  %.0 = phi ptr [ %6, %22 ], [ null, %14 ]
  ret ptr %.0
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #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) local_unnamed_addr #4

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

; 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) local_unnamed_addr #3

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

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

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 = { 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 = { 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 = { 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