; LLVM IR from litespeedtech/ls-qpack :: lsqpack (lsqpack_dec_print_table)

; 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.ringbuf_iter = type { ptr, i32, i32 }
%struct.lsqpack_dec = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, %struct.lsqpack_ringbuf, %struct.anon.8, [8 x %struct.anon.9], i32, float, %struct.anon.10, %struct.lsqpack_dec_err }
%struct.lsqpack_ringbuf = type { i32, i32, i32, ptr }
%struct.anon.8 = type { ptr, ptr }
%struct.anon.9 = type { ptr, ptr }
%struct.anon.10 = type { i32, %union.anon }
%union.anon = type { %struct.anon.11 }
%struct.anon.11 = type { %struct.lsqpack_dec_int_state, %struct.lsqpack_huff_decode_state, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32, i8, i8 }
%struct.lsqpack_dec_int_state = type { i32, i32, i32, i64 }
%struct.lsqpack_huff_decode_state = type { i32, %struct.lsqpack_decode_status }
%struct.lsqpack_decode_status = type { i8, i8 }
%struct.lsqpack_dec_err = type { i32, i32, i64, i64 }
%struct.lsqpack_dec_table_entry = type { i32, i32, i32, i32, i32, i32, i32, [0 x i8] }

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.61 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, 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 void @lsqpack_dec_print_table(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.ringbuf_iter, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef @.str.60) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lsqpack_dec, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.lsqpack_dec, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !18
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef @.str.61, i32 noundef %13, i32 noundef %16) #3
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.lsqpack_dec, ptr %18, i32 0, i32 5
  %20 = load i32, ptr %19, align 4, !tbaa !19
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %41

22:                                               ; preds = %2
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.lsqpack_dec, ptr %23, i32 0, i32 8
  %25 = load i32, ptr %24, align 8, !tbaa !20
  %26 = add i32 %25, 1
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lsqpack_dec, ptr %27, i32 0, i32 5
  %29 = load i32, ptr %28, align 4, !tbaa !19
  %30 = mul i32 %29, 2
  %31 = add i32 %26, %30
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lsqpack_dec, ptr %32, i32 0, i32 12
  %34 = call i32 @ringbuf_count(ptr noundef %33)
  %35 = sub i32 %31, %34
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lsqpack_dec, ptr %36, i32 0, i32 5
  %38 = load i32, ptr %37, align 4, !tbaa !19
  %39 = mul i32 %38, 2
  %40 = urem i32 %35, %39
  br label %42

41:                                               ; preds = %2
  br label %42

42:                                               ; preds = %41, %22
  %43 = phi i32 [ %40, %22 ], [ 0, %41 ]
  store i32 %43, ptr %7, align 4, !tbaa !21
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.lsqpack_dec, ptr %44, i32 0, i32 12
  %46 = call ptr @ringbuf_iter_first(ptr noundef %6, ptr noundef %45)
  store ptr %46, ptr %5, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %85, %42
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %87

50:                                               ; preds = %47
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !21
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.lsqpack_dec_table_entry, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !22
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.lsqpack_dec_table_entry, ptr %56, i32 0, i32 7
  %58 = getelementptr inbounds [0 x i8], ptr %57, i64 0, i64 0
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.lsqpack_dec_table_entry, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !24
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.lsqpack_dec_table_entry, ptr %62, i32 0, i32 7
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.lsqpack_dec_table_entry, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 4, !tbaa !22
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds [0 x i8], ptr %63, i64 0, i64 %67
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str.62, i32 noundef %52, i32 noundef %55, ptr noundef %58, i32 noundef %61, ptr noundef %68) #3
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.lsqpack_dec, ptr %70, i32 0, i32 5
  %72 = load i32, ptr %71, align 4, !tbaa !19
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %82

74:                                               ; preds = %50
  %75 = load i32, ptr %7, align 4, !tbaa !21
  %76 = add i32 %75, 1
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.lsqpack_dec, ptr %77, i32 0, i32 5
  %79 = load i32, ptr %78, align 4, !tbaa !19
  %80 = mul i32 %79, 2
  %81 = urem i32 %76, %80
  br label %83

82:                                               ; preds = %50
  br label %83

83:                                               ; preds = %82, %74
  %84 = phi i32 [ %81, %74 ], [ 0, %82 ]
  store i32 %84, ptr %7, align 4, !tbaa !21
  br label %85

85:                                               ; preds = %83
  %86 = call ptr @ringbuf_iter_next(ptr noundef %6)
  store ptr %86, ptr %5, align 8, !tbaa !5
  br label %47, !llvm.loop !25

87:                                               ; preds = %47
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str.2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ringbuf_count(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @ringbuf_iter_first(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @ringbuf_iter_next(ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"lsqpack_dec", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !6, i64 48, !12, i64 56, !13, i64 80, !7, i64 96, !11, i64 224, !14, i64 228, !15, i64 232, !16, i64 328}
!11 = !{!"int", !7, i64 0}
!12 = !{!"lsqpack_ringbuf", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!"", !11, i64 0, !7, i64 8}
!16 = !{!"lsqpack_dec_err", !11, i64 0, !11, i64 4, !17, i64 8, !17, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!10, !11, i64 12}
!19 = !{!10, !11, i64 20}
!20 = !{!10, !11, i64 32}
!21 = !{!11, !11, i64 0}
!22 = !{!23, !11, i64 0}
!23 = !{!"lsqpack_dec_table_entry", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !7, i64 28}
!24 = !{!23, !11, i64 4}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.61 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

; Function Attrs: mustprogress 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 void @lsqpack_dec_print_table(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.ringbuf_iter, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  %4 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.60) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !17
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.61, i32 noundef %6, i32 noundef %8) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 20
  %11 = load i32, ptr %10, align 4, !tbaa !18
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %24, label %12

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = load i32, ptr %13, align 8, !tbaa !19
  %15 = shl i32 %11, 1
  %16 = getelementptr inbounds i8, ptr %0, i64 56
  %17 = tail call i32 @ringbuf_count(ptr noundef nonnull %16)
  %18 = or disjoint i32 %15, 1
  %19 = add i32 %18, %14
  %20 = sub i32 %19, %17
  %21 = load i32, ptr %10, align 4, !tbaa !18
  %22 = shl i32 %21, 1
  %23 = urem i32 %20, %22
  br label %24

24:                                               ; preds = %2, %12
  %25 = phi i32 [ %23, %12 ], [ 0, %2 ]
  %26 = getelementptr inbounds i8, ptr %0, i64 56
  %27 = call ptr @ringbuf_iter_first(ptr noundef nonnull %3, ptr noundef nonnull %26)
  %.not2426 = icmp eq ptr %27, null
  br i1 %.not2426, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %24, %40
  %.028 = phi i32 [ %41, %40 ], [ %25, %24 ]
  %.02127 = phi ptr [ %42, %40 ], [ %27, %24 ]
  %28 = load i32, ptr %.02127, align 4, !tbaa !20
  %29 = getelementptr inbounds i8, ptr %.02127, i64 28
  %30 = getelementptr inbounds i8, ptr %.02127, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !22
  %32 = zext i32 %28 to i64
  %33 = getelementptr inbounds [0 x i8], ptr %29, i64 0, i64 %32
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.62, i32 noundef %.028, i32 noundef %28, ptr noundef nonnull %29, i32 noundef %31, ptr noundef nonnull %33) #3
  %35 = load i32, ptr %10, align 4, !tbaa !18
  %.not25 = icmp eq i32 %35, 0
  br i1 %.not25, label %40, label %36

36:                                               ; preds = %.lr.ph
  %37 = add nuw i32 %.028, 1
  %38 = shl i32 %35, 1
  %39 = urem i32 %37, %38
  br label %40

40:                                               ; preds = %.lr.ph, %36
  %41 = phi i32 [ %39, %36 ], [ 0, %.lr.ph ]
  %42 = call ptr @ringbuf_iter_next(ptr noundef nonnull %3)
  %.not24 = icmp eq ptr %42, null
  br i1 %.not24, label %._crit_edge, label %.lr.ph, !llvm.loop !23

._crit_edge:                                      ; preds = %40, %24
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ringbuf_count(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @ringbuf_iter_first(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @ringbuf_iter_next(ptr noundef) local_unnamed_addr #2

attributes #0 = { nofree 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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, !7, i64 8}
!6 = !{!"lsqpack_dec", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !10, i64 40, !10, i64 48, !11, i64 56, !12, i64 80, !8, i64 96, !7, i64 224, !13, i64 228, !14, i64 232, !15, i64 328}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"lsqpack_ringbuf", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!12 = !{!"", !10, i64 0, !10, i64 8}
!13 = !{!"float", !8, i64 0}
!14 = !{!"", !7, i64 0, !8, i64 8}
!15 = !{!"lsqpack_dec_err", !7, i64 0, !7, i64 4, !16, i64 8, !16, i64 16}
!16 = !{!"long", !8, i64 0}
!17 = !{!6, !7, i64 12}
!18 = !{!6, !7, i64 20}
!19 = !{!6, !7, i64 32}
!20 = !{!21, !7, i64 0}
!21 = !{!"lsqpack_dec_table_entry", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !8, i64 28}
!22 = !{!21, !7, i64 4}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass