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

; 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 }
%struct.header_block_read_ctx = type { %struct.anon.15, %struct.anon.15, ptr, i64, i64, i64, i32, i32, i32, %struct.anon.16, ptr, i32, %struct.hbrc_buf, %union.anon.17 }
%struct.anon.15 = type { ptr, ptr }
%struct.anon.16 = type { ptr, i32, i32 }
%struct.hbrc_buf = type { ptr, i64, i64 }
%union.anon.17 = type { %struct.anon.22 }
%struct.anon.22 = type { i32, i32, i32, i32, i32, %struct.lsqpack_dec_int_state, %struct.lsqpack_huff_decode_state }

@.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.40 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [48 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 i32 @lsqpack_dec_header_read(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = call ptr @find_header_block_read_ctx(ptr noundef %16, ptr noundef %17)
  store ptr %18, ptr %14, align 8, !tbaa !5
  %19 = load ptr, ptr %14, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %53

21:                                               ; preds = %6
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.lsqpack_dec, ptr %23, i32 0, i32 11
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %43

27:                                               ; preds = %22
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.lsqpack_dec, ptr %28, i32 0, i32 11
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.37) #3
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lsqpack_dec, ptr %32, i32 0, i32 11
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %14, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.header_block_read_ctx, ptr %35, i32 0, i32 3
  %37 = load i64, ptr %36, align 8, !tbaa !19
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str.40, i64 noundef %37) #3
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.lsqpack_dec, ptr %39, i32 0, i32 11
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str.2) #3
  br label %43

43:                                               ; preds = %27, %22
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = call i32 @qdec_header_process(ptr noundef %46, ptr noundef %47, ptr noundef %48, i64 noundef %49, ptr noundef %50, ptr noundef %51)
  store i32 %52, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %75

53:                                               ; preds = %6
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.lsqpack_dec, ptr %55, i32 0, i32 11
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %72

59:                                               ; preds = %54
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.lsqpack_dec, ptr %60, i32 0, i32 11
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.41) #3
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.lsqpack_dec, ptr %64, i32 0, i32 11
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %66, ptr noundef @.str.42) #3
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.lsqpack_dec, ptr %68, i32 0, i32 11
  %70 = load ptr, ptr %69, align 8, !tbaa !11
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.2) #3
  br label %72

72:                                               ; preds = %59, %54
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  store i32 3, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %75

75:                                               ; preds = %74, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %76 = load i32, ptr %7, align 4
  ret i32 %76
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @qdec_header_process(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 48}
!12 = !{!"lsqpack_dec", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !6, i64 40, !6, i64 48, !14, i64 56, !15, i64 80, !7, i64 96, !13, i64 224, !16, i64 228, !17, i64 232, !18, i64 328}
!13 = !{!"int", !7, i64 0}
!14 = !{!"lsqpack_ringbuf", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16}
!15 = !{!"", !6, i64 0, !6, i64 8}
!16 = !{!"float", !7, i64 0}
!17 = !{!"", !13, i64 0, !7, i64 8}
!18 = !{!"lsqpack_dec_err", !13, i64 0, !13, i64 4, !10, i64 8, !10, i64 16}
!19 = !{!20, !10, i64 40}
!20 = !{!"header_block_read_ctx", !15, i64 0, !15, i64 16, !6, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !13, i64 64, !13, i64 68, !13, i64 72, !21, i64 80, !6, i64 96, !13, i64 104, !22, i64 112, !7, i64 136}
!21 = !{!"", !6, i64 0, !13, i64 8, !13, i64 12}
!22 = !{!"hbrc_buf", !6, i64 0, !10, i64 8, !10, 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"

@.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.40 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [48 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: nounwind uwtable
define dso_local i32 @lsqpack_dec_header_read(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #1 {
  %7 = tail call ptr @find_header_block_read_ctx(ptr noundef %0, ptr noundef %1)
  %.not = icmp eq ptr %7, null
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not21 = icmp eq ptr %9, null
  br i1 %.not, label %21, label %10

10:                                               ; preds = %6
  br i1 %.not21, label %19, label %11

11:                                               ; preds = %10
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %9, ptr noundef nonnull @.str.37) #2
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %7, i64 40
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.40, i64 noundef %15) #2
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.2) #2
  br label %19

19:                                               ; preds = %11, %10
  %20 = tail call i32 @qdec_header_process(ptr noundef nonnull %0, ptr noundef nonnull %7, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5)
  br label %28

21:                                               ; preds = %6
  br i1 %.not21, label %28, label %22

22:                                               ; preds = %21
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %9, ptr noundef nonnull @.str.41) #2
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.42) #2
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.2) #2
  br label %28

28:                                               ; preds = %21, %22, %19
  %.0 = phi i32 [ %20, %19 ], [ 3, %22 ], [ 3, %21 ]
  ret i32 %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @qdec_header_process(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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 = { 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 #2 = { 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, !10, i64 48}
!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 = !{!18, !16, i64 40}
!18 = !{!"header_block_read_ctx", !12, i64 0, !12, i64 16, !10, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !7, i64 64, !7, i64 68, !7, i64 72, !19, i64 80, !10, i64 96, !7, i64 104, !20, i64 112, !8, i64 136}
!19 = !{!"", !10, i64 0, !7, i64 8, !7, i64 12}
!20 = !{!"hbrc_buf", !10, i64 0, !16, i64 8, !16, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass