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

; 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.Texture = type { i32, i32, i32, i32, i32, i8, i32, %"class.std::__cxx11::basic_string" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

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

declare void @glGenTextures(i32 noundef, ptr noundef) #0

declare void @glBindTexture(i32 noundef, i32 noundef) #0

declare void @glPixelStorei(i32 noundef, i32 noundef) #0

declare void @glTexImage2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Texture13createCubemapEijj(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  %11 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  store i32 34067, ptr %11, align 4, !tbaa !11
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 2
  store i32 %12, ptr %13, align 8, !tbaa !17
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 3
  store i32 %14, ptr %15, align 4, !tbaa !18
  %16 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 4
  store i32 1, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 0
  call void @glGenTextures(i32 noundef 1, ptr noundef %17)
  %18 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !20
  call void @glBindTexture(i32 noundef %19, i32 noundef %21)
  call void @glPixelStorei(i32 noundef 3317, i32 noundef 1)
  %22 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  call void @glTexParameteri(i32 noundef %23, i32 noundef 10242, i32 noundef 10497)
  %24 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  call void @glTexParameteri(i32 noundef %25, i32 noundef 10243, i32 noundef 10497)
  %26 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !11
  call void @glTexParameteri(i32 noundef %27, i32 noundef 10241, i32 noundef 9729)
  %28 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  call void @glTexParameteri(i32 noundef %29, i32 noundef 10240, i32 noundef 9729)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %43, %4
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = icmp ult i32 %31, 6
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %46

34:                                               ; preds = %30
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add i32 34069, %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !17
  %42 = load i32, ptr %7, align 4, !tbaa !9
  call void @glTexImage2D(i32 noundef %36, i32 noundef 0, i32 noundef %37, i32 noundef %39, i32 noundef %41, i32 noundef 0, i32 noundef %42, i32 noundef 5121, ptr noundef null)
  br label %43

43:                                               ; preds = %34
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = add i32 %44, 1
  store i32 %45, ptr %9, align 4, !tbaa !9
  br label %30, !llvm.loop !21

46:                                               ; preds = %33
  %47 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !11
  call void @glBindTexture(i32 noundef %48, i32 noundef 0)
  ret i1 true
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"_ZTS7Texture", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !10, i64 24, !14, i64 32}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !7, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !10, i64 8}
!18 = !{!12, !10, i64 12}
!19 = !{!12, !10, i64 16}
!20 = !{!12, !10, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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 void @glTexParameteri(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @glGenTextures(i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @glBindTexture(i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @glPixelStorei(i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @glTexImage2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Texture13createCubemapEijj(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 34067, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %1, ptr %6, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %1, ptr %7, align 4, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 1, ptr %8, align 8, !tbaa !17
  tail call void @glGenTextures(i32 noundef 1, ptr noundef nonnull %0)
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %0, align 8, !tbaa !18
  tail call void @glBindTexture(i32 noundef %9, i32 noundef %10)
  tail call void @glPixelStorei(i32 noundef 3317, i32 noundef 1)
  %11 = load i32, ptr %5, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %11, i32 noundef 10242, i32 noundef 10497)
  %12 = load i32, ptr %5, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %12, i32 noundef 10243, i32 noundef 10497)
  %13 = load i32, ptr %5, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %13, i32 noundef 10241, i32 noundef 9729)
  %14 = load i32, ptr %5, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %14, i32 noundef 10240, i32 noundef 9729)
  %15 = load i32, ptr %6, align 8, !tbaa !15
  tail call void @glTexImage2D(i32 noundef 34069, i32 noundef 0, i32 noundef %3, i32 noundef %15, i32 noundef %15, i32 noundef 0, i32 noundef %2, i32 noundef 5121, ptr noundef null)
  %16 = load i32, ptr %6, align 8, !tbaa !15
  tail call void @glTexImage2D(i32 noundef 34070, i32 noundef 0, i32 noundef %3, i32 noundef %16, i32 noundef %16, i32 noundef 0, i32 noundef %2, i32 noundef 5121, ptr noundef null)
  %17 = load i32, ptr %6, align 8, !tbaa !15
  tail call void @glTexImage2D(i32 noundef 34071, i32 noundef 0, i32 noundef %3, i32 noundef %17, i32 noundef %17, i32 noundef 0, i32 noundef %2, i32 noundef 5121, ptr noundef null)
  %18 = load i32, ptr %6, align 8, !tbaa !15
  tail call void @glTexImage2D(i32 noundef 34072, i32 noundef 0, i32 noundef %3, i32 noundef %18, i32 noundef %18, i32 noundef 0, i32 noundef %2, i32 noundef 5121, ptr noundef null)
  %19 = load i32, ptr %6, align 8, !tbaa !15
  tail call void @glTexImage2D(i32 noundef 34073, i32 noundef 0, i32 noundef %3, i32 noundef %19, i32 noundef %19, i32 noundef 0, i32 noundef %2, i32 noundef 5121, ptr noundef null)
  %20 = load i32, ptr %6, align 8, !tbaa !15
  tail call void @glTexImage2D(i32 noundef 34074, i32 noundef 0, i32 noundef %3, i32 noundef %20, i32 noundef %20, i32 noundef 0, i32 noundef %2, i32 noundef 5121, ptr noundef null)
  %21 = load i32, ptr %5, align 4, !tbaa !5
  tail call void @glBindTexture(i32 noundef %21, i32 noundef 0)
  ret i1 true
}

attributes #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 4}
!6 = !{!"_ZTS7Texture", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !7, i64 24, !11, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !14, i64 8, !8, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 12}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass