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

; 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_enc = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.lsqpack_enc_head, ptr, %struct.anon, %struct.anon.0, %struct.anon.1, %struct.anon.2, %struct.anon.3, i32, i32, ptr, float, float, ptr, i32, i32, i32 }
%struct.lsqpack_enc_head = type { ptr, ptr }
%struct.anon = type { ptr, ptr }
%struct.anon.0 = type { ptr, ptr }
%struct.anon.1 = type { ptr, ptr }
%struct.anon.2 = type { ptr, ptr, i32, i32, i32, i32 }
%struct.anon.3 = type { %struct.lsqpack_dec_int_state, ptr }
%struct.lsqpack_dec_int_state = type { i32, i32, i32, i64 }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [36 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 willreturn memory(none)
declare ptr @__errno_location() #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @lsqpack_enc_int(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #3

; 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
declare hidden void @qenc_remove_overflow_entries(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @lsqpack_enc_set_max_capacity(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.lsqpack_enc, ptr %13, i32 0, i32 6
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp ugt i32 %12, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %4
  %18 = call ptr @__errno_location() #5
  store i32 22, ptr %18, align 4, !tbaa !9
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %109

19:                                               ; preds = %4
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.lsqpack_enc, ptr %21, i32 0, i32 5
  %23 = load i32, ptr %22, align 4, !tbaa !20
  %24 = icmp eq i32 %20, %23
  br i1 %24, label %25, label %49

25:                                               ; preds = %19
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lsqpack_enc, ptr %27, i32 0, i32 23
  %29 = load ptr, ptr %28, align 8, !tbaa !21
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %45

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lsqpack_enc, ptr %32, i32 0, i32 23
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str) #4
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lsqpack_enc, ptr %36, i32 0, i32 23
  %38 = load ptr, ptr %37, align 8, !tbaa !21
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str.32, i32 noundef %39) #4
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.lsqpack_enc, ptr %41, i32 0, i32 23
  %43 = load ptr, ptr %42, align 8, !tbaa !21
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.2) #4
  br label %45

45:                                               ; preds = %31, %26
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %48, align 8, !tbaa !22
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %109

49:                                               ; preds = %19
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %55

52:                                               ; preds = %49
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %57, label %55

55:                                               ; preds = %52, %49
  %56 = call ptr @__errno_location() #5
  store i32 22, ptr %56, align 4, !tbaa !9
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %109

57:                                               ; preds = %52
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %58, ptr %10, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 32, ptr %59, align 1, !tbaa !23
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load i64, ptr %62, align 8, !tbaa !22
  %64 = getelementptr inbounds i8, ptr %61, i64 %63
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = call ptr @lsqpack_enc_int(ptr noundef %60, ptr noundef %64, i64 noundef %66, i32 noundef 5)
  store ptr %67, ptr %10, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = icmp ule ptr %68, %69
  br i1 %70, label %71, label %73

71:                                               ; preds = %57
  %72 = call ptr @__errno_location() #5
  store i32 105, ptr %72, align 4, !tbaa !9
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %109

73:                                               ; preds = %57
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = ptrtoint ptr %74 to i64
  %77 = ptrtoint ptr %75 to i64
  %78 = sub i64 %76, %77
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %78, ptr %79, align 8, !tbaa !22
  br label %80

80:                                               ; preds = %73
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.lsqpack_enc, ptr %81, i32 0, i32 23
  %83 = load ptr, ptr %82, align 8, !tbaa !21
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %102

85:                                               ; preds = %80
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.lsqpack_enc, ptr %86, i32 0, i32 23
  %88 = load ptr, ptr %87, align 8, !tbaa !21
  %89 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str) #4
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.lsqpack_enc, ptr %90, i32 0, i32 23
  %92 = load ptr, ptr %91, align 8, !tbaa !21
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.lsqpack_enc, ptr %93, i32 0, i32 5
  %95 = load i32, ptr %94, align 4, !tbaa !20
  %96 = load i32, ptr %7, align 4, !tbaa !9
  %97 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %92, ptr noundef @.str.33, i32 noundef %95, i32 noundef %96) #4
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.lsqpack_enc, ptr %98, i32 0, i32 23
  %100 = load ptr, ptr %99, align 8, !tbaa !21
  %101 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %100, ptr noundef @.str.2) #4
  br label %102

102:                                              ; preds = %85, %80
  br label %103

103:                                              ; preds = %102
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %7, align 4, !tbaa !9
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.lsqpack_enc, ptr %106, i32 0, i32 5
  store i32 %105, ptr %107, align 4, !tbaa !20
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  call void @qenc_remove_overflow_entries(ptr noundef %108)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %109

109:                                              ; preds = %104, %71, %55, %47, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %110 = load i32, ptr %5, align 4
  ret i32 %110
}

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 willreturn memory(none) "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 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 }
attributes #5 = { nounwind willreturn memory(none) }

!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 24}
!12 = !{!"lsqpack_enc", !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, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !13, i64 56, !6, i64 72, !14, i64 80, !14, i64 96, !14, i64 112, !15, i64 128, !16, i64 160, !10, i64 192, !10, i64 196, !6, i64 200, !19, i64 208, !19, i64 212, !6, i64 216, !10, i64 224, !10, i64 228, !10, i64 232}
!13 = !{!"lsqpack_enc_head", !6, i64 0, !6, i64 8}
!14 = !{!"", !6, i64 0, !6, i64 8}
!15 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!16 = !{!"", !17, i64 0, !6, i64 24}
!17 = !{!"lsqpack_dec_int_state", !10, i64 0, !10, i64 4, !10, i64 8, !18, i64 16}
!18 = !{!"long", !7, i64 0}
!19 = !{!"float", !7, i64 0}
!20 = !{!12, !10, i64 20}
!21 = !{!12, !6, i64 200}
!22 = !{!18, !18, i64 0}
!23 = !{!7, !7, i64 0}


; 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 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [36 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 nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @lsqpack_enc_int(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @lsqpack_enc_set_max_capacity(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp ult i32 %6, %1
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = tail call ptr @__errno_location() #3
  store i32 22, ptr %9, align 4, !tbaa !18
  br label %50

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %12 = load i32, ptr %11, align 4, !tbaa !19
  %13 = icmp eq i32 %12, %1
  br i1 %13, label %14, label %24

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 200
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %.not40 = icmp eq ptr %16, null
  br i1 %.not40, label %23, label %17

17:                                               ; preds = %14
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %16, ptr noundef nonnull @.str) #4
  %19 = load ptr, ptr %15, align 8, !tbaa !20
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.32, i32 noundef %1) #4
  %21 = load ptr, ptr %15, align 8, !tbaa !20
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.2) #4
  br label %23

23:                                               ; preds = %17, %14
  store i64 0, ptr %3, align 8, !tbaa !21
  br label %50

24:                                               ; preds = %10
  %25 = icmp ne ptr %2, null
  %26 = icmp ne ptr %3, null
  %or.cond = and i1 %25, %26
  br i1 %or.cond, label %29, label %27

27:                                               ; preds = %24
  %28 = tail call ptr @__errno_location() #3
  store i32 22, ptr %28, align 4, !tbaa !18
  br label %50

29:                                               ; preds = %24
  store i8 32, ptr %2, align 1, !tbaa !22
  %30 = load i64, ptr %3, align 8, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %2, i64 %30
  %32 = zext i32 %1 to i64
  %33 = tail call ptr @lsqpack_enc_int(ptr noundef nonnull %2, ptr noundef nonnull %31, i64 noundef %32, i32 noundef 5)
  %.not = icmp ugt ptr %33, %2
  br i1 %.not, label %36, label %34

34:                                               ; preds = %29
  %35 = tail call ptr @__errno_location() #3
  store i32 105, ptr %35, align 4, !tbaa !18
  br label %50

36:                                               ; preds = %29
  %37 = ptrtoint ptr %33 to i64
  %38 = ptrtoint ptr %2 to i64
  %39 = sub i64 %37, %38
  store i64 %39, ptr %3, align 8, !tbaa !21
  %40 = getelementptr inbounds i8, ptr %0, i64 200
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  %.not39 = icmp eq ptr %41, null
  br i1 %.not39, label %49, label %42

42:                                               ; preds = %36
  %43 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %41, ptr noundef nonnull @.str) #4
  %44 = load ptr, ptr %40, align 8, !tbaa !20
  %45 = load i32, ptr %11, align 4, !tbaa !19
  %46 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef nonnull @.str.33, i32 noundef %45, i32 noundef %1) #4
  %47 = load ptr, ptr %40, align 8, !tbaa !20
  %48 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.2) #4
  br label %49

49:                                               ; preds = %42, %36
  store i32 %1, ptr %11, align 4, !tbaa !19
  tail call void @qenc_remove_overflow_entries(ptr noundef nonnull %0)
  br label %50

50:                                               ; preds = %49, %34, %27, %23, %8
  %.0 = phi i32 [ -1, %8 ], [ 0, %23 ], [ -1, %34 ], [ 0, %49 ], [ -1, %27 ]
  ret i32 %.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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 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 willreturn memory(none) }
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, !7, i64 24}
!6 = !{!"lsqpack_enc", !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, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !10, i64 56, !11, i64 72, !12, i64 80, !12, i64 96, !12, i64 112, !13, i64 128, !14, i64 160, !7, i64 192, !7, i64 196, !11, i64 200, !17, i64 208, !17, i64 212, !11, i64 216, !7, i64 224, !7, i64 228, !7, i64 232}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"lsqpack_enc_head", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 8}
!13 = !{!"", !11, i64 0, !11, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!14 = !{!"", !15, i64 0, !11, i64 24}
!15 = !{!"lsqpack_dec_int_state", !7, i64 0, !7, i64 4, !7, i64 8, !16, i64 16}
!16 = !{!"long", !8, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!6, !7, i64 20}
!20 = !{!6, !11, i64 200}
!21 = !{!16, !16, i64 0}
!22 = !{!8, !8, i64 0}


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