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

; 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.52 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [51 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: nounwind uwtable
declare dso_local ptr @lsqpack_enc_int(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #2

; 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 i64 @lsqpack_dec_cancel_stream_id(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.lsqpack_dec, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %100

17:                                               ; preds = %4
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %100

21:                                               ; preds = %17
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 64, ptr %22, align 1, !tbaa !19
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = call ptr @lsqpack_enc_int(ptr noundef %23, ptr noundef %26, i64 noundef %27, i32 noundef 6)
  store ptr %28, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp ugt ptr %29, %30
  br i1 %31, label %32, label %76

32:                                               ; preds = %21
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.lsqpack_dec, ptr %34, i32 0, i32 11
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %58

38:                                               ; preds = %33
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.lsqpack_dec, ptr %39, i32 0, i32 11
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str.37) #3
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.lsqpack_dec, ptr %43, i32 0, i32 11
  %45 = load ptr, ptr %44, align 8, !tbaa !20
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = ptrtoint ptr %47 to i64
  %50 = ptrtoint ptr %48 to i64
  %51 = sub i64 %49, %50
  %52 = trunc i64 %51 to i32
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.53, i64 noundef %46, i32 noundef %52) #3
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.lsqpack_dec, ptr %54, i32 0, i32 11
  %56 = load ptr, ptr %55, align 8, !tbaa !20
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef @.str.2) #3
  br label %58

58:                                               ; preds = %38, %33
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = ptrtoint ptr %61 to i64
  %64 = ptrtoint ptr %62 to i64
  %65 = sub i64 %63, %64
  %66 = trunc i64 %65 to i32
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.lsqpack_dec, ptr %67, i32 0, i32 6
  %69 = load i32, ptr %68, align 8, !tbaa !21
  %70 = add i32 %69, %66
  store i32 %70, ptr %68, align 8, !tbaa !21
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = ptrtoint ptr %71 to i64
  %74 = ptrtoint ptr %72 to i64
  %75 = sub i64 %73, %74
  store i64 %75, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %100

76:                                               ; preds = %21
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.lsqpack_dec, ptr %78, i32 0, i32 11
  %80 = load ptr, ptr %79, align 8, !tbaa !20
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %97

82:                                               ; preds = %77
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.lsqpack_dec, ptr %83, i32 0, i32 11
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %85, ptr noundef @.str.37) #3
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.lsqpack_dec, ptr %87, i32 0, i32 11
  %89 = load ptr, ptr %88, align 8, !tbaa !20
  %90 = load i64, ptr %7, align 8, !tbaa !9
  %91 = load i64, ptr %9, align 8, !tbaa !9
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %89, ptr noundef @.str.52, i64 noundef %90, i64 noundef %91) #3
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.lsqpack_dec, ptr %93, i32 0, i32 11
  %95 = load ptr, ptr %94, align 8, !tbaa !20
  %96 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %95, ptr noundef @.str.2) #3
  br label %97

97:                                               ; preds = %82, %77
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %100

100:                                              ; preds = %99, %60, %20, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %101 = load i64, ptr %5, align 8
  ret i64 %101
}

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, !13, i64 4}
!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 = !{!7, !7, i64 0}
!20 = !{!12, !6, i64 48}
!21 = !{!12, !13, i64 24}


; 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.52 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [51 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
declare dso_local ptr @lsqpack_enc_int(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @lsqpack_dec_cancel_stream_id(ptr nocapture noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %38, label %8

8:                                                ; preds = %4
  %9 = icmp eq i64 %3, 0
  br i1 %9, label %38, label %10

10:                                               ; preds = %8
  store i8 64, ptr %2, align 1, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %2, i64 %3
  %12 = tail call ptr @lsqpack_enc_int(ptr noundef nonnull %2, ptr noundef nonnull %11, i64 noundef %1, i32 noundef 6)
  %13 = icmp ugt ptr %12, %2
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %15 = load ptr, ptr %14, align 8, !tbaa !18
  %.not32 = icmp eq ptr %15, null
  br i1 %13, label %16, label %31

16:                                               ; preds = %10
  br i1 %.not32, label %._crit_edge, label %17

._crit_edge:                                      ; preds = %16
  %.pre = ptrtoint ptr %12 to i64
  %.pre33 = ptrtoint ptr %2 to i64
  %.pre35 = sub i64 %.pre, %.pre33
  %.pre37 = trunc i64 %.pre35 to i32
  br label %27

17:                                               ; preds = %16
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %15, ptr noundef nonnull @.str.37) #2
  %19 = load ptr, ptr %14, align 8, !tbaa !18
  %20 = ptrtoint ptr %12 to i64
  %21 = ptrtoint ptr %2 to i64
  %22 = sub i64 %20, %21
  %23 = trunc i64 %22 to i32
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.53, i64 noundef %1, i32 noundef %23) #2
  %25 = load ptr, ptr %14, align 8, !tbaa !18
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.2) #2
  br label %27

27:                                               ; preds = %._crit_edge, %17
  %.pre-phi38 = phi i32 [ %.pre37, %._crit_edge ], [ %23, %17 ]
  %.pre-phi36 = phi i64 [ %.pre35, %._crit_edge ], [ %22, %17 ]
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = add i32 %29, %.pre-phi38
  store i32 %30, ptr %28, align 8, !tbaa !19
  br label %38

31:                                               ; preds = %10
  br i1 %.not32, label %38, label %32

32:                                               ; preds = %31
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %15, ptr noundef nonnull @.str.37) #2
  %34 = load ptr, ptr %14, align 8, !tbaa !18
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.52, i64 noundef %1, i64 noundef %3) #2
  %36 = load ptr, ptr %14, align 8, !tbaa !18
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.2) #2
  br label %38

38:                                               ; preds = %31, %32, %8, %4, %27
  %.0 = phi i64 [ %.pre-phi36, %27 ], [ 0, %4 ], [ -1, %8 ], [ -1, %32 ], [ -1, %31 ]
  ret i64 %.0
}

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, !7, i64 4}
!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 = !{!8, !8, i64 0}
!18 = !{!6, !10, i64 48}
!19 = !{!6, !7, i64 24}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass