; LLVM IR from indygreg/python-zstandard :: zstd (zstd)

; 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.ZSTD_DCtx_s = type { ptr, ptr, ptr, ptr, %struct.ZSTD_entropyDTables_t, [640 x i32], ptr, ptr, ptr, ptr, i64, %struct.ZSTD_frameHeader, i64, i64, i32, i32, i32, i32, %struct.XXH_NAMESPACEXXH64_state_s, i64, i32, i32, i32, ptr, %struct.ZSTD_customMem, i64, i64, i64, i32, i32, ptr, ptr, i32, i32, i32, ptr, i32, i32, i32, i32, ptr, i64, i64, i64, ptr, i64, i64, i64, i64, i32, i32, i32, %struct.ZSTD_outBuffer_s, ptr, ptr, i32, [65568 x i8], [18 x i8], i64 }
%struct.ZSTD_entropyDTables_t = type { [513 x %struct.ZSTD_seqSymbol], [257 x %struct.ZSTD_seqSymbol], [513 x %struct.ZSTD_seqSymbol], [4097 x i32], [3 x i32], [157 x i32] }
%struct.ZSTD_seqSymbol = type { i16, i8, i8, i32 }
%struct.ZSTD_frameHeader = type { i64, i64, i32, i32, i32, i32, i32, i32, i32 }
%struct.XXH_NAMESPACEXXH64_state_s = type { i64, [4 x i64], [4 x i64], i32, i32, i64 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }
%struct.ZSTD_outBuffer_s = type { ptr, i64, i64 }

; Function Attrs: nounwind uwtable
define dso_local i32 @ZSTD_nextInputType(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %4, i32 0, i32 15
  %6 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %6, label %7 [
    i32 0, label %8
    i32 1, label %9
    i32 2, label %10
    i32 3, label %11
    i32 4, label %12
    i32 5, label %13
    i32 6, label %14
    i32 7, label %15
  ]

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %7, %1
  br label %9

9:                                                ; preds = %8, %1
  store i32 0, ptr %2, align 4
  br label %16

10:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  br label %16

11:                                               ; preds = %1
  store i32 2, ptr %2, align 4
  br label %16

12:                                               ; preds = %1
  store i32 3, ptr %2, align 4
  br label %16

13:                                               ; preds = %1
  store i32 4, ptr %2, align 4
  br label %16

14:                                               ; preds = %1
  br label %15

15:                                               ; preds = %14, %1
  store i32 5, ptr %2, align 4
  br label %16

16:                                               ; preds = %15, %13, %12, %11, %10, %9
  %17 = load i32, ptr %2, align 4
  ret i32 %17
}

attributes #0 = { 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !15, i64 29996}
!10 = !{!"ZSTD_DCtx_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !7, i64 27324, !6, i64 29888, !6, i64 29896, !6, i64 29904, !6, i64 29912, !12, i64 29920, !13, i64 29928, !12, i64 29976, !12, i64 29984, !15, i64 29992, !15, i64 29996, !15, i64 30000, !15, i64 30004, !16, i64 30008, !12, i64 30096, !15, i64 30104, !15, i64 30108, !15, i64 30112, !6, i64 30120, !17, i64 30128, !12, i64 30152, !12, i64 30160, !12, i64 30168, !15, i64 30176, !15, i64 30180, !6, i64 30184, !6, i64 30192, !15, i64 30200, !15, i64 30204, !15, i64 30208, !6, i64 30216, !15, i64 30224, !15, i64 30228, !15, i64 30232, !15, i64 30236, !6, i64 30240, !12, i64 30248, !12, i64 30256, !12, i64 30264, !6, i64 30272, !12, i64 30280, !12, i64 30288, !12, i64 30296, !12, i64 30304, !15, i64 30312, !15, i64 30316, !15, i64 30320, !18, i64 30328, !6, i64 30352, !6, i64 30360, !15, i64 30368, !7, i64 30372, !7, i64 95940, !12, i64 95960}
!11 = !{!"", !7, i64 0, !7, i64 4104, !7, i64 6160, !7, i64 10264, !7, i64 26652, !7, i64 26664}
!12 = !{!"long", !7, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 8, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !15, i64 40}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"XXH_NAMESPACEXXH64_state_s", !12, i64 0, !7, i64 8, !7, i64 40, !15, i64 72, !15, i64 76, !12, i64 80}
!17 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"ZSTD_outBuffer_s", !6, i64 0, !12, i64 8, !12, i64 16}


; 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.ZSTD_nextInputType = private unnamed_addr constant [6 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 5], align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local range(i32 0, 6) i32 @ZSTD_nextInputType(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 29996
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %switch.tableidx = add i32 %3, -2
  %4 = icmp ult i32 %switch.tableidx, 6
  br i1 %4, label %switch.lookup, label %6

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

6:                                                ; preds = %switch.lookup, %1
  %.0 = phi i32 [ 0, %1 ], [ %switch.load, %switch.lookup ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !14, i64 29996}
!6 = !{!"ZSTD_DCtx_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !8, i64 27324, !7, i64 29888, !7, i64 29896, !7, i64 29904, !7, i64 29912, !11, i64 29920, !12, i64 29928, !11, i64 29976, !11, i64 29984, !14, i64 29992, !14, i64 29996, !14, i64 30000, !14, i64 30004, !15, i64 30008, !11, i64 30096, !14, i64 30104, !14, i64 30108, !14, i64 30112, !7, i64 30120, !16, i64 30128, !11, i64 30152, !11, i64 30160, !11, i64 30168, !14, i64 30176, !14, i64 30180, !7, i64 30184, !7, i64 30192, !14, i64 30200, !14, i64 30204, !14, i64 30208, !7, i64 30216, !14, i64 30224, !14, i64 30228, !14, i64 30232, !14, i64 30236, !7, i64 30240, !11, i64 30248, !11, i64 30256, !11, i64 30264, !7, i64 30272, !11, i64 30280, !11, i64 30288, !11, i64 30296, !11, i64 30304, !14, i64 30312, !14, i64 30316, !14, i64 30320, !17, i64 30328, !7, i64 30352, !7, i64 30360, !14, i64 30368, !8, i64 30372, !8, i64 95940, !11, i64 95960}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !8, i64 0, !8, i64 4104, !8, i64 6160, !8, i64 10264, !8, i64 26652, !8, i64 26664}
!11 = !{!"long", !8, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!"XXH_NAMESPACEXXH64_state_s", !11, i64 0, !8, i64 8, !8, i64 40, !14, i64 72, !14, i64 76, !11, i64 80}
!16 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!"ZSTD_outBuffer_s", !7, i64 0, !11, i64 8, !11, i64 16}


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