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

; 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 @_ZNK11FrameBuffer8getWidthEv(ptr noundef nonnull align 8 dereferenceable(104)) #1 align 2

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

; 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 @_ZN11FrameBuffer20createCubemapTextureEjjji(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #6 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
  %17 = call noundef i32 @_ZNK11FrameBuffer8getWidthEv(ptr noundef nonnull align 8 dereferenceable(104) %16)
  %18 = call noundef i32 @_ZNK11FrameBuffer9getHeightEv(ptr noundef nonnull align 8 dereferenceable(104) %16)
  %19 = icmp ne i32 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  store ptr null, ptr %6, align 8
  br label %81

21:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %22 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 64) #8
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 2
  invoke void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64) %22, i1 noundef zeroext %24)
          to label %25 unwind label %37

25:                                               ; preds = %21
  store ptr %22, ptr %12, align 8, !tbaa !5
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.FrameBuffer, ptr %16, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = call noundef zeroext i1 @_ZN7Texture13createCubemapEijj(ptr noundef nonnull align 8 dereferenceable(64) %26, i32 noundef %28, i32 noundef %29, i32 noundef %30)
  br i1 %31, label %41, label %32

32:                                               ; preds = %25
  %33 = load ptr, ptr %12, 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 %6, align 8
  store i32 1, ptr %15, align 4
  br label %80

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

41:                                               ; preds = %25
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZN7Texture4bindEi(ptr noundef nonnull align 8 dereferenceable(64) %42, i32 noundef 0)
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %43)
  %45 = load i32, ptr %10, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %44, i32 noundef 10242, i32 noundef %45)
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %46)
  %48 = load i32, ptr %10, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %47, i32 noundef 10243, i32 noundef %48)
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %49)
  %51 = load i32, ptr %10, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %50, i32 noundef 32882, i32 noundef %51)
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %59

54:                                               ; preds = %41
  %55 = load ptr, ptr %12, 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 %12, 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 %11, align 4, !tbaa !9
  %61 = icmp eq i32 %60, 1
  br i1 %61, label %62, label %67

62:                                               ; preds = %59
  %63 = load ptr, ptr %12, 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 %12, 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 %11, align 4, !tbaa !9
  %69 = icmp eq i32 %68, 2
  br i1 %69, label %70, label %75

70:                                               ; preds = %67
  %71 = load ptr, ptr %12, 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 %12, 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 %12, align 8, !tbaa !5
  call void @_ZN7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(64) %78)
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %79, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %80

80:                                               ; preds = %77, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %81

81:                                               ; preds = %80, %20
  %82 = load ptr, ptr %6, align 8
  ret ptr %82

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

declare noundef zeroext i1 @_ZN7Texture13createCubemapEijj(ptr noundef nonnull align 8 dereferenceable(64), 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}


; 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 @_ZNK11FrameBuffer8getWidthEv(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #0 align 2

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

; 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 @_ZN11FrameBuffer20createCubemapTextureEjjji(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #5 align 2 personality ptr @__gxx_personality_v0 {
  %6 = tail call noundef i32 @_ZNK11FrameBuffer8getWidthEv(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %7 = tail call noundef i32 @_ZNK11FrameBuffer9getHeightEv(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %.not = icmp eq i32 %6, %7
  br i1 %.not, label %8, label %27

8:                                                ; preds = %5
  %9 = tail call noalias noundef nonnull dereferenceable(64) ptr @_Znwm(i64 noundef 64) #6
  %10 = icmp eq i32 %4, 2
  invoke void @_ZN7TextureC1Eb(ptr noundef nonnull align 8 dereferenceable(64) %9, i1 noundef zeroext %10)
          to label %11 unwind label %16

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

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

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

18:                                               ; preds = %11
  tail call void @_ZN7Texture4bindEi(ptr noundef nonnull align 8 dereferenceable(64) %9, i32 noundef 0)
  %19 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %9)
  tail call void @glTexParameteri(i32 noundef %19, i32 noundef 10242, i32 noundef %3)
  %20 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %9)
  tail call void @glTexParameteri(i32 noundef %20, i32 noundef 10243, i32 noundef %3)
  %21 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %9)
  tail call void @glTexParameteri(i32 noundef %21, i32 noundef 32882, i32 noundef %3)
  switch i32 %4, label %23 [
    i32 0, label %.sink.split
    i32 1, label %22
  ]

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

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

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

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

27:                                               ; preds = %15, %26, %5
  %.1 = phi ptr [ null, %5 ], [ %9, %26 ], [ null, %15 ]
  ret ptr %.1
}

declare noundef zeroext i1 @_ZN7Texture13createCubemapEijj(ptr noundef nonnull align 8 dereferenceable(64), 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"}


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