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

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

@__glewGenerateMipmap = external global ptr, align 8

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

declare i32 @SOIL_load_OGL_texture(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Texture6load3DERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8
  %7 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  store i32 32879, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 7
  %10 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32) %9, ptr noundef nonnull align 8 dereferenceable(32) %8)
  %11 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 7
  %12 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %11) #3
  %13 = call i32 @SOIL_load_OGL_texture(ptr noundef %12, i32 noundef 0, i32 noundef 0, i32 noundef 67)
  %14 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  store i32 %13, ptr %14, align 8, !tbaa !16
  %15 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %17 = icmp ule i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %59

19:                                               ; preds = %2
  %20 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %21, i32 noundef 10242, i32 noundef 10497)
  %22 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %23, i32 noundef 10243, i32 noundef 10497)
  %24 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %25, i32 noundef 32882, i32 noundef 10497)
  %26 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 5
  %27 = load i8, ptr %26, align 4, !tbaa !17, !range !18, !noundef !19
  %28 = trunc i8 %27 to i1
  br i1 %28, label %29, label %33

29:                                               ; preds = %19
  %30 = load ptr, ptr @__glewGenerateMipmap, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !9
  call void %30(i32 noundef %32)
  br label %33

33:                                               ; preds = %29, %19
  %34 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 5
  %35 = load i8, ptr %34, align 4, !tbaa !17, !range !18, !noundef !19
  %36 = trunc i8 %35 to i1
  br i1 %36, label %37, label %42

37:                                               ; preds = %33
  %38 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %39, i32 noundef 10241, i32 noundef 9987)
  %40 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %41, i32 noundef 10240, i32 noundef 9729)
  br label %47

42:                                               ; preds = %33
  %43 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %44, i32 noundef 10241, i32 noundef 9729)
  %45 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !9
  call void @glTexParameteri(i32 noundef %46, i32 noundef 10240, i32 noundef 9729)
  br label %47

47:                                               ; preds = %42, %37
  %48 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 2
  call void @glGetTexLevelParameteriv(i32 noundef %49, i32 noundef 0, i32 noundef 4096, ptr noundef %50)
  %51 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 3
  call void @glGetTexLevelParameteriv(i32 noundef %52, i32 noundef 0, i32 noundef 4097, ptr noundef %53)
  %54 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 4
  call void @glGetTexLevelParameteriv(i32 noundef %55, i32 noundef 0, i32 noundef 32881, ptr noundef %56)
  %57 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !9
  call void @glBindTexture(i32 noundef %58, i32 noundef 0)
  store i1 true, ptr %3, align 1
  br label %59

59:                                               ; preds = %47, %18
  %60 = load i1, ptr %3, align 1
  ret i1 %60
}

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 = { 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 #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, !11, i64 4}
!10 = !{!"_ZTS7Texture", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 20, !11, i64 24, !13, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !11, i64 0}
!17 = !{!10, !12, i64 20}
!18 = !{i8 0, i8 2}
!19 = !{}


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

@__glewGenerateMipmap = external local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

declare i32 @SOIL_load_OGL_texture(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Texture6load3DERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 32879, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32) %4, ptr noundef nonnull align 8 dereferenceable(32) %1)
  %6 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %4) #3
  %7 = tail call i32 @SOIL_load_OGL_texture(ptr noundef %6, i32 noundef 0, i32 noundef 0, i32 noundef 67)
  store i32 %7, ptr %0, align 8, !tbaa !15
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %31

9:                                                ; preds = %2
  %10 = load i32, ptr %3, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %10, i32 noundef 10242, i32 noundef 10497)
  %11 = load i32, ptr %3, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %11, i32 noundef 10243, i32 noundef 10497)
  %12 = load i32, ptr %3, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %12, i32 noundef 32882, i32 noundef 10497)
  %13 = getelementptr inbounds i8, ptr %0, i64 20
  %14 = load i8, ptr %13, align 4, !tbaa !16, !range !17, !noundef !18
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %19

16:                                               ; preds = %9
  %17 = load ptr, ptr @__glewGenerateMipmap, align 8, !tbaa !19
  %18 = load i32, ptr %3, align 4, !tbaa !5
  tail call void %17(i32 noundef %18)
  %.pre = load i8, ptr %13, align 4, !tbaa !16, !range !17
  br label %19

19:                                               ; preds = %16, %9
  %20 = phi i8 [ %.pre, %16 ], [ %14, %9 ]
  %21 = trunc nuw i8 %20 to i1
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %. = select i1 %21, i32 9987, i32 9729
  tail call void @glTexParameteri(i32 noundef %22, i32 noundef 10241, i32 noundef %.)
  %23 = load i32, ptr %3, align 4, !tbaa !5
  tail call void @glTexParameteri(i32 noundef %23, i32 noundef 10240, i32 noundef 9729)
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @glGetTexLevelParameteriv(i32 noundef %24, i32 noundef 0, i32 noundef 4096, ptr noundef nonnull %25)
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 12
  tail call void @glGetTexLevelParameteriv(i32 noundef %26, i32 noundef 0, i32 noundef 4097, ptr noundef nonnull %27)
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @glGetTexLevelParameteriv(i32 noundef %28, i32 noundef 0, i32 noundef 32881, ptr noundef nonnull %29)
  %30 = load i32, ptr %3, align 4, !tbaa !5
  tail call void @glBindTexture(i32 noundef %30, i32 noundef 0)
  br label %31

31:                                               ; preds = %2, %19
  ret i1 %8
}

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 = { 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 #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, !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 0}
!16 = !{!6, !10, i64 20}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!13, !13, i64 0}


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