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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Texture6load2DEPKvmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(32) %3) #1 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8
  %11 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  store i32 3553, ptr %11, align 4, !tbaa !11
  %12 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 4
  store i32 1, ptr %12, align 8, !tbaa !17
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 7
  %15 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32) %14, ptr noundef nonnull align 8 dereferenceable(32) %13)
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = trunc i64 %17 to i32
  %19 = call i32 @SOIL_load_OGL_texture_from_memory(ptr noundef %16, i32 noundef %18, i32 noundef 0, i32 noundef 0, i32 noundef 64)
  %20 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 0
  store i32 %19, ptr %20, align 8, !tbaa !18
  %21 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = icmp ule i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  br label %60

25:                                               ; preds = %4
  %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 10242, i32 noundef 10497)
  %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 10243, i32 noundef 10497)
  %30 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 5
  %31 = load i8, ptr %30, align 4, !tbaa !19, !range !20, !noundef !21
  %32 = trunc i8 %31 to i1
  br i1 %32, label %33, label %37

33:                                               ; preds = %25
  %34 = load ptr, ptr @__glewGenerateMipmap, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  call void %34(i32 noundef %36)
  br label %37

37:                                               ; preds = %33, %25
  %38 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 5
  %39 = load i8, ptr %38, align 4, !tbaa !19, !range !20, !noundef !21
  %40 = trunc i8 %39 to i1
  br i1 %40, label %41, label %46

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

46:                                               ; preds = %37
  %47 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !11
  call void @glTexParameteri(i32 noundef %48, i32 noundef 10241, i32 noundef 9729)
  %49 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !11
  call void @glTexParameteri(i32 noundef %50, i32 noundef 10240, i32 noundef 9729)
  br label %51

51:                                               ; preds = %46, %41
  %52 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 2
  call void @glGetTexLevelParameteriv(i32 noundef %53, i32 noundef 0, i32 noundef 4096, ptr noundef %54)
  %55 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 3
  call void @glGetTexLevelParameteriv(i32 noundef %56, i32 noundef 0, i32 noundef 4097, ptr noundef %57)
  %58 = getelementptr inbounds %class.Texture, ptr %10, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !11
  call void @glBindTexture(i32 noundef %59, i32 noundef 0)
  store i1 true, ptr %5, align 1
  br label %60

60:                                               ; preds = %51, %24
  %61 = load i1, ptr %5, align 1
  ret i1 %61
}

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

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


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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Texture6load2DEPKvmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(32) %3) local_unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 3553, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 1, ptr %6, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_(ptr noundef nonnull align 8 dereferenceable(32) %7, ptr noundef nonnull align 8 dereferenceable(32) %3)
  %9 = trunc i64 %2 to i32
  %10 = tail call i32 @SOIL_load_OGL_texture_from_memory(ptr noundef %1, i32 noundef %9, i32 noundef 0, i32 noundef 0, i32 noundef 64)
  store i32 %10, ptr %0, align 8, !tbaa !16
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %31

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

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

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

31:                                               ; preds = %4, %21
  ret i1 %11
}

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

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