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

; 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::OpenGLPixelTransferParams" = type { 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 { i64, i32 } @_ZN5glimg19GetUploadFormatTypeERKNS_11ImageFormatEj(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %1) #1 {
  %3 = alloca %"struct.glimg::OpenGLPixelTransferParams", align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 1
  store i32 -1, ptr %9, align 4, !tbaa !11
  %10 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 0
  store i32 -1, ptr %10, align 4, !tbaa !13
  %11 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 2
  store i32 0, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = call noundef i32 @_ZN5glimg12_GLOBAL__N_111GetDataTypeERKNS_11ImageFormatEj(ptr noundef nonnull align 4 dereferenceable(20) %12, i32 noundef %13)
  store i32 %14, ptr %6, align 4, !tbaa !15
  %15 = load i32, ptr %6, align 4, !tbaa !15
  %16 = icmp sge i32 %15, 6
  br i1 %16, label %17, label %35

17:                                               ; preds = %2
  %18 = load i32, ptr %6, align 4, !tbaa !15
  switch i32 %18, label %21 [
    i32 6, label %19
    i32 9, label %19
    i32 10, label %19
  ]

19:                                               ; preds = %17, %17, %17
  %20 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 2
  store i32 8, ptr %20, align 4, !tbaa !14
  br label %23

21:                                               ; preds = %17
  %22 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 2
  store i32 16, ptr %22, align 4, !tbaa !14
  br label %23

23:                                               ; preds = %21, %19
  %24 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 0
  store i32 6408, ptr %24, align 4, !tbaa !13
  %25 = load i32, ptr %6, align 4, !tbaa !15
  %26 = icmp ne i32 %25, 13
  br i1 %26, label %30, label %27

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !15
  %29 = icmp ne i32 %28, 14
  br i1 %29, label %30, label %32

30:                                               ; preds = %27, %23
  %31 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 1
  store i32 5126, ptr %31, align 4, !tbaa !11
  br label %34

32:                                               ; preds = %27
  %33 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 1
  store i32 5121, ptr %33, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %32, %30
  store i32 1, ptr %7, align 4
  br label %46

35:                                               ; preds = %2
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !15
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = call noundef i32 @_ZN5glimg12_GLOBAL__N_113GetOpenGLTypeERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20) %36, i32 noundef %37, i32 noundef %38)
  %40 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 1
  store i32 %39, ptr %40, align 4, !tbaa !11
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !15
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = call noundef i32 @_ZN5glimg12_GLOBAL__N_115GetOpenGLFormatERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20) %41, i32 noundef %42, i32 noundef %43)
  %45 = getelementptr inbounds %"struct.glimg::OpenGLPixelTransferParams", ptr %3, i32 0, i32 0
  store i32 %44, ptr %45, align 4, !tbaa !13
  store i32 1, ptr %7, align 4
  br label %46

46:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 4 %3, i64 12, i1 false)
  %47 = load { i64, i32 }, ptr %8, align 8
  ret { i64, i32 } %47
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN5glimg12_GLOBAL__N_111GetDataTypeERKNS_11ImageFormatEj(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5glimg12_GLOBAL__N_113GetOpenGLTypeERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5glimg12_GLOBAL__N_115GetOpenGLFormatERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 4}
!12 = !{!"_ZTSN5glimg25OpenGLPixelTransferParamsE", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTSN5glimg13PixelDataTypeE", !7, i64 0}


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

@switch.table._ZN5glimg19GetUploadFormatTypeERKNS_11ImageFormatEj = private unnamed_addr constant [5 x i32] [i32 8, i32 16, i32 16, i32 8, i32 8], align 4

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_ZN5glimg19GetUploadFormatTypeERKNS_11ImageFormatEj(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_ZN5glimg12_GLOBAL__N_111GetDataTypeERKNS_11ImageFormatEj(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %1)
  %4 = icmp sgt i32 %3, 5
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %switch.tableidx = add nsw i32 %3, -6
  %6 = icmp ult i32 %switch.tableidx, 5
  br i1 %6, label %switch.lookup, label %15

7:                                                ; preds = %2
  %8 = tail call noundef i32 @_ZN5glimg12_GLOBAL__N_113GetOpenGLTypeERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %3, i32 noundef %1)
  %9 = tail call noundef i32 @_ZN5glimg12_GLOBAL__N_115GetOpenGLFormatERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %3, i32 noundef %1)
  %10 = zext i32 %8 to i64
  %11 = shl nuw i64 %10, 32
  %12 = zext i32 %9 to i64
  %13 = or disjoint i64 %11, %12
  br label %15

switch.lookup:                                    ; preds = %5
  %14 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [5 x i32], ptr @switch.table._ZN5glimg19GetUploadFormatTypeERKNS_11ImageFormatEj, i64 0, i64 %14
  %switch.load = load i32, ptr %switch.gep, align 4
  br label %15

15:                                               ; preds = %5, %switch.lookup, %7
  %.sroa.8.1 = phi i32 [ 0, %7 ], [ %switch.load, %switch.lookup ], [ 16, %5 ]
  %.sroa.012.0.insert.insert = phi i64 [ %13, %7 ], [ 22016002365704, %switch.lookup ], [ 22016002365704, %5 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.012.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.8.1, 1
  ret { i64, i32 } %.fca.1.insert
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN5glimg12_GLOBAL__N_111GetDataTypeERKNS_11ImageFormatEj(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5glimg12_GLOBAL__N_113GetOpenGLTypeERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5glimg12_GLOBAL__N_115GetOpenGLFormatERKNS_11ImageFormatENS_13PixelDataTypeEj(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef, i32 noundef) local_unnamed_addr #0

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

!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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass