; LLVM IR from paroj/gltut :: glsdk/glimg/source/TextureGenerator.ll (ZN5glimg14GetTextureTypeEPKNS_8ImageSetEj)

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

%"struct.glimg::Dimensions" = type { i32, i32, i32, i32 }

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5glimg14GetTextureTypeEPKNS_8ImageSetEj(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %"struct.glimg::Dimensions", align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call { i64, i64 } @_ZNK5glimg8ImageSet13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  %10 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %11 = extractvalue { i64, i64 } %9, 0
  store i64 %11, ptr %10, align 4
  %12 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %13 = extractvalue { i64, i64 } %9, 1
  store i64 %13, ptr %12, align 4
  %14 = getelementptr inbounds %"struct.glimg::Dimensions", ptr %6, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !11
  switch i32 %15, label %39 [
    i32 1, label %16
    i32 2, label %22
    i32 3, label %38
  ]

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = call noundef zeroext i1 @_ZN5glimg12_GLOBAL__N_114IsArrayTextureEPKNS_8ImageSetEj(ptr noundef %17, i32 noundef %18)
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i32 35864, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

21:                                               ; preds = %16
  store i32 3552, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = call noundef zeroext i1 @_ZN5glimg12_GLOBAL__N_114IsArrayTextureEPKNS_8ImageSetEj(ptr noundef %23, i32 noundef %24)
  br i1 %25, label %26, label %32

26:                                               ; preds = %22
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call noundef i32 @_ZNK5glimg8ImageSet12GetFaceCountEv(ptr noundef nonnull align 8 dereferenceable(16) %27)
  %29 = icmp sgt i32 %28, 1
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  store i32 36873, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

31:                                               ; preds = %26
  store i32 35866, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

32:                                               ; preds = %22
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call noundef i32 @_ZNK5glimg8ImageSet12GetFaceCountEv(ptr noundef nonnull align 8 dereferenceable(16) %33)
  %35 = icmp sgt i32 %34, 1
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i32 34067, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

37:                                               ; preds = %32
  store i32 3553, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

38:                                               ; preds = %2
  store i32 32879, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

39:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

40:                                               ; preds = %39, %38, %37, %36, %31, %30, %21, %20
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  %41 = load i32, ptr %3, align 4
  ret i32 %41
}

declare { i64, i64 } @_ZNK5glimg8ImageSet13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(16)) #2

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN5glimg12_GLOBAL__N_114IsArrayTextureEPKNS_8ImageSetEj(ptr noundef, i32 noundef) #1

declare noundef i32 @_ZNK5glimg8ImageSet12GetFaceCountEv(ptr noundef nonnull align 8 dereferenceable(16)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN5glimg10DimensionsE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1, 36874) i32 @_ZN5glimg14GetTextureTypeEPKNS_8ImageSetEj(ptr noundef nonnull %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call { i64, i64 } @_ZNK5glimg8ImageSet13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %4 = extractvalue { i64, i64 } %3, 0
  %.sroa.0.0.extract.trunc = trunc i64 %4 to i32
  switch i32 %.sroa.0.0.extract.trunc, label %13 [
    i32 1, label %5
    i32 2, label %7
    i32 3, label %14
  ]

5:                                                ; preds = %2
  %6 = tail call noundef zeroext i1 @_ZN5glimg12_GLOBAL__N_114IsArrayTextureEPKNS_8ImageSetEj(ptr noundef nonnull %0, i32 noundef %1)
  %. = select i1 %6, i32 35864, i32 3552
  br label %14

7:                                                ; preds = %2
  %8 = tail call noundef zeroext i1 @_ZN5glimg12_GLOBAL__N_114IsArrayTextureEPKNS_8ImageSetEj(ptr noundef nonnull %0, i32 noundef %1)
  %9 = tail call noundef i32 @_ZNK5glimg8ImageSet12GetFaceCountEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %10 = icmp sgt i32 %9, 1
  br i1 %8, label %11, label %12

11:                                               ; preds = %7
  %.7 = select i1 %10, i32 36873, i32 35866
  br label %14

12:                                               ; preds = %7
  %.8 = select i1 %10, i32 34067, i32 3553
  br label %14

13:                                               ; preds = %2
  br label %14

14:                                               ; preds = %2, %12, %11, %5, %13
  %.0 = phi i32 [ -1, %13 ], [ %., %5 ], [ %.7, %11 ], [ %.8, %12 ], [ 32879, %2 ]
  ret i32 %.0
}

declare { i64, i64 } @_ZNK5glimg8ImageSet13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN5glimg12_GLOBAL__N_114IsArrayTextureEPKNS_8ImageSetEj(ptr noundef, i32 noundef) local_unnamed_addr #0

declare noundef i32 @_ZNK5glimg8ImageSet12GetFaceCountEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

attributes #0 = { 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 #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" }

!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)"}


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