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

; 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] }

@__glewFramebufferTexture2D = external global ptr, align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN11FrameBuffer17attachCubeMapFaceEP7Textureiii(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 align 2 {
  %6 = alloca i1, align 1
  %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
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  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
  %12 = load ptr, ptr %7, align 8
  %13 = getelementptr inbounds %class.FrameBuffer, ptr %12, i32 0, i32 3
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %5
  store i1 false, ptr %6, align 1
  br label %43

17:                                               ; preds = %5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %18)
  %20 = icmp ne i32 %19, 34067
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store i1 false, ptr %6, align 1
  br label %43

22:                                               ; preds = %17
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %28, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = icmp sgt i32 %26, 5
  br i1 %27, label %28, label %29

28:                                               ; preds = %25, %22
  store i1 false, ptr %6, align 1
  br label %43

29:                                               ; preds = %25
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.FrameBuffer, ptr %12, i32 0, i32 4
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [8 x ptr], ptr %31, i64 0, i64 %33
  store ptr %30, ptr %34, align 8, !tbaa !5
  %35 = load ptr, ptr @__glewFramebufferTexture2D, align 8, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = add nsw i32 36064, %36
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = add nsw i32 34069, %38
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call noundef i32 @_ZNK7Texture5getIdEv(ptr noundef nonnull align 8 dereferenceable(64) %40)
  %42 = load i32, ptr %11, align 4, !tbaa !9
  call void %35(i32 noundef 36160, i32 noundef %37, i32 noundef %39, i32 noundef %41, i32 noundef %42)
  store i1 true, ptr %6, align 1
  br label %43

43:                                               ; preds = %29, %28, %21, %16
  %44 = load i1, ptr %6, align 1
  ret i1 %44
}

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

!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 12}
!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"

@__glewFramebufferTexture2D = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7Texture5getIdEv(ptr noundef nonnull align 8 dereferenceable(64)) 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN11FrameBuffer17attachCubeMapFaceEP7Textureiii(ptr nocapture noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %19, label %9

9:                                                ; preds = %5
  %10 = tail call noundef i32 @_ZNK7Texture9getTargetEv(ptr noundef nonnull align 8 dereferenceable(64) %1)
  %.not = icmp ne i32 %10, 34067
  %or.cond = icmp ugt i32 %2, 5
  %or.cond12 = or i1 %or.cond, %.not
  br i1 %or.cond12, label %19, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = sext i32 %3 to i64
  %14 = getelementptr inbounds [8 x ptr], ptr %12, i64 0, i64 %13
  store ptr %1, ptr %14, align 8, !tbaa !10
  %15 = load ptr, ptr @__glewFramebufferTexture2D, align 8, !tbaa !10
  %16 = add nsw i32 %3, 36064
  %17 = add nuw nsw i32 %2, 34069
  %18 = tail call noundef i32 @_ZNK7Texture5getIdEv(ptr noundef nonnull align 8 dereferenceable(64) %1)
  tail call void %15(i32 noundef 36160, i32 noundef %16, i32 noundef %17, i32 noundef %18, i32 noundef %4)
  br label %19

19:                                               ; preds = %9, %5, %11
  %.0 = phi i1 [ true, %11 ], [ false, %5 ], [ false, %9 ]
  ret i1 %.0
}

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

!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 12}
!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 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass