; LLVM IR from rcliftonharvey/dspfilters4juce :: DSPFilters4JUCEDemo/JuceLibraryCode/juce_opengl.ll (ZN4juce13OpenGLTexture6createEiiPKvjb)

; 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.juce::OpenGLTexture" = type { i32, i32, i32, ptr }

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4juce13OpenGLContext17getCurrentContextEv() #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4juce13OpenGLTexture6createEiiPKvjb(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i1 noundef zeroext %5) #3 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  %14 = zext i1 %5 to i8
  store i8 %14, ptr %12, align 1, !tbaa !11
  %15 = load ptr, ptr %7, align 8
  %16 = call noundef ptr @_ZN4juce13OpenGLContext17getCurrentContextEv()
  %17 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 3
  store ptr %16, ptr %17, align 8, !tbaa !13
  br label %18

18:                                               ; preds = %6
  br label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 0
  call void @glGenTextures(i32 noundef 1, ptr noundef %24)
  %25 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !15
  call void @glBindTexture(i32 noundef 3553, i32 noundef %26)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9729)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9729)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10242, i32 noundef 33071)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10243, i32 noundef 33071)
  br label %30

27:                                               ; preds = %19
  %28 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !15
  call void @glBindTexture(i32 noundef 3553, i32 noundef %29)
  br label %30

30:                                               ; preds = %27, %23
  call void @glPixelStorei(i32 noundef 3317, i32 noundef 1)
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = call noundef i32 @_ZN4juceL21getAllowedTextureSizeEi(i32 noundef %31)
  %33 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 1
  store i32 %32, ptr %33, align 4, !tbaa !16
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = call noundef i32 @_ZN4juceL21getAllowedTextureSizeEi(i32 noundef %34)
  %36 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 2
  store i32 %35, ptr %36, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 6406
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 6406, i32 6408
  store i32 %40, ptr %13, align 4, !tbaa !9
  %41 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !16
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = icmp ne i32 %42, %43
  br i1 %44, label %50, label %45

45:                                               ; preds = %30
  %46 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !17
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = icmp ne i32 %47, %48
  br i1 %49, label %50, label %71

50:                                               ; preds = %45, %30
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = load i32, ptr %11, align 4, !tbaa !9
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef %51, i32 noundef %53, i32 noundef %55, i32 noundef 0, i32 noundef %56, i32 noundef 5121, ptr noundef null)
  %57 = load i8, ptr %12, align 1, !tbaa !11, !range !18, !noundef !19
  %58 = trunc i8 %57 to i1
  br i1 %58, label %59, label %64

59:                                               ; preds = %50
  %60 = getelementptr inbounds %"class.juce::OpenGLTexture", ptr %15, i32 0, i32 2
  %61 = load i32, ptr %60, align 8, !tbaa !17
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = sub nsw i32 %61, %62
  br label %65

64:                                               ; preds = %50
  br label %65

65:                                               ; preds = %64, %59
  %66 = phi i32 [ %63, %59 ], [ 0, %64 ]
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  call void @glTexSubImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 0, i32 noundef %66, i32 noundef %67, i32 noundef %68, i32 noundef %69, i32 noundef 5121, ptr noundef %70)
  br label %77

71:                                               ; preds = %45
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = load i32, ptr %11, align 4, !tbaa !9
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef 0, i32 noundef %75, i32 noundef 5121, ptr noundef %76)
  br label %77

77:                                               ; preds = %71, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN4juceL21getAllowedTextureSizeEi(i32 noundef) #2

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

declare void @glTexSubImage2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #4 = { 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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTSN4juce13OpenGLTextureE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 4}
!17 = !{!14, !10, i64 8}
!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"

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4juce13OpenGLContext17getCurrentContextEv() local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4juce13OpenGLTexture6createEiiPKvjb(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i1 noundef zeroext %5) local_unnamed_addr #2 align 2 {
  %7 = tail call noundef ptr @_ZN4juce13OpenGLContext17getCurrentContextEv()
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %7, ptr %8, align 8, !tbaa !5
  %9 = load i32, ptr %0, align 8, !tbaa !11
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %6
  tail call void @glGenTextures(i32 noundef 1, ptr noundef nonnull %0)
  %12 = load i32, ptr %0, align 8, !tbaa !11
  tail call void @glBindTexture(i32 noundef 3553, i32 noundef %12)
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9729)
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9729)
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10242, i32 noundef 33071)
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10243, i32 noundef 33071)
  br label %14

13:                                               ; preds = %6
  tail call void @glBindTexture(i32 noundef 3553, i32 noundef %9)
  br label %14

14:                                               ; preds = %13, %11
  tail call void @glPixelStorei(i32 noundef 3317, i32 noundef 1)
  %15 = tail call noundef i32 @_ZN4juceL21getAllowedTextureSizeEi(i32 noundef %1)
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %15, ptr %16, align 4, !tbaa !12
  %17 = tail call noundef i32 @_ZN4juceL21getAllowedTextureSizeEi(i32 noundef %2)
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %17, ptr %18, align 8, !tbaa !13
  %19 = icmp eq i32 %4, 6406
  %20 = select i1 %19, i32 6406, i32 6408
  %21 = load i32, ptr %16, align 4, !tbaa !12
  %.not = icmp eq i32 %21, %1
  %.not20 = icmp eq i32 %17, %2
  %or.cond = and i1 %.not20, %.not
  br i1 %or.cond, label %26, label %22

22:                                               ; preds = %14
  tail call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef %20, i32 noundef %21, i32 noundef %17, i32 noundef 0, i32 noundef %4, i32 noundef 5121, ptr noundef null)
  %23 = load i32, ptr %18, align 8
  %24 = sub nsw i32 %23, %2
  %25 = select i1 %5, i32 %24, i32 0
  tail call void @glTexSubImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 0, i32 noundef %25, i32 noundef %1, i32 noundef %2, i32 noundef %4, i32 noundef 5121, ptr noundef %3)
  br label %27

26:                                               ; preds = %14
  tail call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef %20, i32 noundef %1, i32 noundef %2, i32 noundef 0, i32 noundef %4, i32 noundef 5121, ptr noundef %3)
  br label %27

27:                                               ; preds = %26, %22
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN4juceL21getAllowedTextureSizeEi(i32 noundef) local_unnamed_addr #1

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

declare void @glTexSubImage2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr 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 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 #2 = { 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, !10, i64 16}
!6 = !{!"_ZTSN4juce13OpenGLTextureE", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass