; 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 @_ZN7Texture6load2DERKNSt7__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 3553, ptr %7, align 4, !tbaa !9
  %8 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 4
  store i32 1, ptr %8, align 8, !tbaa !16
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 7
  %11 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32) %10, ptr noundef nonnull align 8 dereferenceable(32) %9)
  %12 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 7
  %13 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %12) #3
  %14 = call i32 @SOIL_load_OGL_texture(ptr noundef %13, i32 noundef 0, i32 noundef 0, i32 noundef 65)
  %15 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  store i32 %14, ptr %15, align 8, !tbaa !17
  %16 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !17
  %18 = icmp ule i32 %17, 0
  br i1 %18, label %19, label %20

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

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

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

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

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

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

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

55:                                               ; preds = %46, %19
  %56 = load i1, ptr %3, align 1
  ret i1 %56
}

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


; 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 @_ZN7Texture6load2DERKNSt7__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 3553, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 1, ptr %4, align 8, !tbaa !15
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32) %5, ptr noundef nonnull align 8 dereferenceable(32) %1)
  %7 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %5) #3
  %8 = tail call i32 @SOIL_load_OGL_texture(ptr noundef %7, i32 noundef 0, i32 noundef 0, i32 noundef 65)
  store i32 %8, ptr %0, align 8, !tbaa !16
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %29

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

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

19:                                               ; preds = %16, %10
  %20 = phi i8 [ %.pre, %16 ], [ %14, %10 ]
  %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
  tail call void @glBindTexture(i32 noundef %28, i32 noundef 0)
  br label %29

29:                                               ; preds = %2, %19
  ret i1 %9
}

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


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