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

; 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.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 }

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @lsqpack_dec_init(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) #3 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 352, i1 false)
  %15 = load i32, ptr %12, align 4, !tbaa !9
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.lsqpack_dec, ptr %16, i32 0, i32 0
  store i32 %15, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.lsqpack_dec, ptr %19, i32 0, i32 11
  store ptr %18, ptr %20, align 8, !tbaa !19
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lsqpack_dec, ptr %22, i32 0, i32 1
  store i32 %21, ptr %23, align 4, !tbaa !20
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.lsqpack_dec, ptr %25, i32 0, i32 2
  store i32 %24, ptr %26, align 8, !tbaa !21
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lsqpack_dec, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !20
  %30 = udiv i32 %29, 32
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.lsqpack_dec, ptr %31, i32 0, i32 5
  store i32 %30, ptr %32, align 4, !tbaa !22
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.lsqpack_dec, ptr %33, i32 0, i32 5
  %35 = load i32, ptr %34, align 4, !tbaa !22
  %36 = mul i32 %35, 2
  %37 = sub i32 %36, 1
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.lsqpack_dec, ptr %38, i32 0, i32 8
  store i32 %37, ptr %39, align 8, !tbaa !23
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.lsqpack_dec, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 4, !tbaa !22
  %43 = mul i32 %42, 2
  %44 = sub i32 %43, 1
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.lsqpack_dec, ptr %45, i32 0, i32 9
  store i32 %44, ptr %46, align 4, !tbaa !24
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.lsqpack_dec, ptr %48, i32 0, i32 4
  store i32 %47, ptr %49, align 8, !tbaa !25
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.lsqpack_dec, ptr %51, i32 0, i32 10
  store ptr %50, ptr %52, align 8, !tbaa !26
  br label %53

53:                                               ; preds = %6
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.lsqpack_dec, ptr %54, i32 0, i32 13
  %56 = getelementptr inbounds %struct.anon.8, ptr %55, i32 0, i32 0
  store ptr null, ptr %56, align 8, !tbaa !27
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.lsqpack_dec, ptr %57, i32 0, i32 13
  %59 = getelementptr inbounds %struct.anon.8, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.lsqpack_dec, ptr %60, i32 0, i32 13
  %62 = getelementptr inbounds %struct.anon.8, ptr %61, i32 0, i32 1
  store ptr %59, ptr %62, align 8, !tbaa !28
  br label %63

63:                                               ; preds = %53
  br label %64

64:                                               ; preds = %63
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %90, %64
  %66 = load i32, ptr %13, align 4, !tbaa !9
  %67 = icmp ult i32 %66, 8
  br i1 %67, label %68, label %93

68:                                               ; preds = %65
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.lsqpack_dec, ptr %70, i32 0, i32 14
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds [8 x %struct.anon.9], ptr %71, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.anon.9, ptr %74, i32 0, i32 0
  store ptr null, ptr %75, align 8, !tbaa !29
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.lsqpack_dec, ptr %76, i32 0, i32 14
  %78 = load i32, ptr %13, align 4, !tbaa !9
  %79 = zext i32 %78 to i64
  %80 = getelementptr inbounds [8 x %struct.anon.9], ptr %77, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.anon.9, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.lsqpack_dec, ptr %82, i32 0, i32 14
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds [8 x %struct.anon.9], ptr %83, i64 0, i64 %85
  %87 = getelementptr inbounds %struct.anon.9, ptr %86, i32 0, i32 1
  store ptr %81, ptr %87, align 8, !tbaa !30
  br label %88

88:                                               ; preds = %69
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %13, align 4, !tbaa !9
  %92 = add i32 %91, 1
  store i32 %92, ptr %13, align 4, !tbaa !9
  br label %65, !llvm.loop !31

93:                                               ; preds = %65
  br label %94

94:                                               ; preds = %93
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.lsqpack_dec, ptr %95, i32 0, i32 11
  %97 = load ptr, ptr %96, align 8, !tbaa !19
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %118

99:                                               ; preds = %94
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.lsqpack_dec, ptr %100, i32 0, i32 11
  %102 = load ptr, ptr %101, align 8, !tbaa !19
  %103 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %102, ptr noundef @.str.37) #4
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.lsqpack_dec, ptr %104, i32 0, i32 11
  %106 = load ptr, ptr %105, align 8, !tbaa !19
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.lsqpack_dec, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !20
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.lsqpack_dec, ptr %110, i32 0, i32 4
  %112 = load i32, ptr %111, align 8, !tbaa !25
  %113 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %106, ptr noundef @.str.38, i32 noundef %109, i32 noundef %112) #4
  %114 = load ptr, ptr %7, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.lsqpack_dec, ptr %114, i32 0, i32 11
  %116 = load ptr, ptr %115, align 8, !tbaa !19
  %117 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %116, ptr noundef @.str.2) #4
  br label %118

118:                                              ; preds = %99, %94
  br label %119

119:                                              ; preds = %118
  br label %120

120:                                              ; preds = %119
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  ret void
}

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

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @lsqpack_dec_init(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) local_unnamed_addr #2 {
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(352) %7, i8 0, i64 344, i1 false)
  store i32 %5, ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %1, ptr %8, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %9, align 4, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %2, ptr %10, align 8, !tbaa !19
  %11 = lshr i32 %2, 5
  %12 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %11, ptr %12, align 4, !tbaa !20
  %13 = shl nuw nsw i32 %11, 1
  %14 = add nsw i32 %13, -1
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %14, ptr %15, align 8, !tbaa !21
  %16 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %14, ptr %16, align 4, !tbaa !22
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %3, ptr %17, align 8, !tbaa !23
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %4, ptr %18, align 8, !tbaa !24
  %19 = getelementptr inbounds i8, ptr %0, i64 80
  %20 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr %19, ptr %20, align 8, !tbaa !25
  %21 = getelementptr inbounds i8, ptr %0, i64 96
  %22 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %21, ptr %22, align 8, !tbaa !26
  %23 = getelementptr inbounds i8, ptr %0, i64 112
  %24 = getelementptr inbounds i8, ptr %0, i64 120
  store ptr %23, ptr %24, align 8, !tbaa !26
  %25 = getelementptr inbounds i8, ptr %0, i64 128
  %26 = getelementptr inbounds i8, ptr %0, i64 136
  store ptr %25, ptr %26, align 8, !tbaa !26
  %27 = getelementptr inbounds i8, ptr %0, i64 144
  %28 = getelementptr inbounds i8, ptr %0, i64 152
  store ptr %27, ptr %28, align 8, !tbaa !26
  %29 = getelementptr inbounds i8, ptr %0, i64 160
  %30 = getelementptr inbounds i8, ptr %0, i64 168
  store ptr %29, ptr %30, align 8, !tbaa !26
  %31 = getelementptr inbounds i8, ptr %0, i64 176
  %32 = getelementptr inbounds i8, ptr %0, i64 184
  store ptr %31, ptr %32, align 8, !tbaa !26
  %33 = getelementptr inbounds i8, ptr %0, i64 192
  %34 = getelementptr inbounds i8, ptr %0, i64 200
  store ptr %33, ptr %34, align 8, !tbaa !26
  %35 = getelementptr inbounds i8, ptr %0, i64 208
  %36 = getelementptr inbounds i8, ptr %0, i64 216
  store ptr %35, ptr %36, align 8, !tbaa !26
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %45, label %37

37:                                               ; preds = %6
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %1, ptr noundef nonnull @.str.37) #3
  %39 = load ptr, ptr %8, align 8, !tbaa !17
  %40 = load i32, ptr %9, align 4, !tbaa !18
  %41 = load i32, ptr %17, align 8, !tbaa !23
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str.38, i32 noundef %40, i32 noundef %41) #3
  %43 = load ptr, ptr %8, align 8, !tbaa !17
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str.2) #3
  br label %45

45:                                               ; preds = %37, %6
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 #2 = { nofree 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 0}
!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, !10, i64 48}
!18 = !{!6, !7, i64 4}
!19 = !{!6, !7, i64 8}
!20 = !{!6, !7, i64 20}
!21 = !{!6, !7, i64 32}
!22 = !{!6, !7, i64 36}
!23 = !{!6, !7, i64 16}
!24 = !{!6, !10, i64 40}
!25 = !{!6, !10, i64 88}
!26 = !{!12, !10, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass