; LLVM IR from litespeedtech/ls-qpack :: test (test_huff_dec)

; 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.test_huff_dec = type { i32, ptr, i64, ptr, i64 }

@tests = external dso_local constant [3 x %struct.test_huff_dec], align 16
@verbose = external hidden global i32, align 4
@.str.16 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @run_test(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %19, %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = call i32 @getopt(i32 noundef %10, ptr noundef %11, ptr noundef @.str.16) #4
  store i32 %12, ptr %7, align 4, !tbaa !5
  %13 = icmp ne i32 -1, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %9
  %15 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %15, label %18 [
    i32 118, label %16
    i32 101, label %17
  ]

16:                                               ; preds = %14
  store i32 1, ptr @verbose, align 4, !tbaa !5
  br label %19

17:                                               ; preds = %14
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %19

18:                                               ; preds = %14
  call void @exit(i32 noundef 1) #5
  unreachable

19:                                               ; preds = %17, %16
  br label %9, !llvm.loop !11

20:                                               ; preds = %9
  store ptr @tests, ptr %6, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %39, %20
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = icmp ult ptr %22, getelementptr inbounds (%struct.test_huff_dec, ptr @tests, i64 3)
  br i1 %23, label %24, label %42

24:                                               ; preds = %21
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %36, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.test_huff_dec, ptr %28, i32 0, i32 2
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.test_huff_dec, ptr %31, i32 0, i32 4
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = mul i64 %30, %33
  %35 = icmp ult i64 %34, 150000
  br i1 %35, label %36, label %38

36:                                               ; preds = %27, %24
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  call void @run_test(ptr noundef %37)
  br label %38

38:                                               ; preds = %36, %27
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.test_huff_dec, ptr %40, i32 1
  store ptr %41, ptr %6, align 8, !tbaa !9
  br label %21, !llvm.loop !17

42:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = { noreturn nounwind "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 }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 16}
!14 = !{!"test_huff_dec", !6, i64 0, !10, i64 8, !15, i64 16, !10, i64 24, !15, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 32}
!17 = distinct !{!17, !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"

%struct.test_huff_dec = type { i32, ptr, i64, ptr, i64 }

@tests = external dso_local constant [3 x %struct.test_huff_dec], align 16
@verbose = external hidden local_unnamed_addr global i32, align 4
@.str.16 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @run_test(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  br label %.outer

.outer:                                           ; preds = %3, %2
  %.not10 = phi i1 [ true, %2 ], [ false, %3 ]
  br label %3

3:                                                ; preds = %.outer, %19
  %4 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str.16) #3
  switch i32 %4, label %20 [
    i32 -1, label %.preheader
    i32 118, label %19
    i32 101, label %.outer
  ], !llvm.loop !5

.preheader:                                       ; preds = %3
  br i1 %.not10, label %.preheader.split.us.preheader, label %.preheader.split.preheader

.preheader.split.preheader:                       ; preds = %.preheader
  tail call void @run_test(ptr noundef nonnull @tests)
  tail call void @run_test(ptr noundef nonnull getelementptr inbounds (i8, ptr @tests, i64 40))
  br label %.split.us.sink.split

.preheader.split.us.preheader:                    ; preds = %.preheader
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @tests, i64 16), align 16, !tbaa !7
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @tests, i64 32), align 16, !tbaa !14
  %7 = mul i64 %6, %5
  %8 = icmp ult i64 %7, 150000
  br i1 %8, label %9, label %.preheader.split.us.1

9:                                                ; preds = %.preheader.split.us.preheader
  tail call void @run_test(ptr noundef nonnull @tests)
  br label %.preheader.split.us.1

.preheader.split.us.1:                            ; preds = %9, %.preheader.split.us.preheader
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @tests, i64 56), align 8, !tbaa !7
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @tests, i64 72), align 8, !tbaa !14
  %12 = mul i64 %11, %10
  %13 = icmp ult i64 %12, 150000
  br i1 %13, label %14, label %.preheader.split.us.2

14:                                               ; preds = %.preheader.split.us.1
  tail call void @run_test(ptr noundef nonnull getelementptr inbounds (i8, ptr @tests, i64 40))
  br label %.preheader.split.us.2

.preheader.split.us.2:                            ; preds = %14, %.preheader.split.us.1
  %15 = load i64, ptr getelementptr inbounds (i8, ptr @tests, i64 96), align 16, !tbaa !7
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @tests, i64 112), align 16, !tbaa !14
  %17 = mul i64 %16, %15
  %18 = icmp ult i64 %17, 150000
  br i1 %18, label %.split.us.sink.split, label %.split.us

19:                                               ; preds = %3
  store i32 1, ptr @verbose, align 4, !tbaa !15
  br label %3, !llvm.loop !5

20:                                               ; preds = %3
  tail call void @exit(i32 noundef 1) #4
  unreachable

.split.us.sink.split:                             ; preds = %.preheader.split.us.2, %.preheader.split.preheader
  tail call void @run_test(ptr noundef nonnull getelementptr inbounds (i8, ptr @tests, i64 80))
  br label %.split.us

.split.us:                                        ; preds = %.split.us.sink.split, %.preheader.split.us.2
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

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" }
attributes #1 = { nounwind "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 = { noreturn nounwind "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 }
attributes #4 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !13, i64 16}
!8 = !{!"test_huff_dec", !9, i64 0, !12, i64 8, !13, i64 16, !12, i64 24, !13, i64 32}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!"long", !10, i64 0}
!14 = !{!8, !13, i64 32}
!15 = !{!9, !9, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass