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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @lsqpack_enc_header_block_prefix_size(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.lsqpack_enc, ptr %5, i32 0, i32 7
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = mul i32 2, %7
  %9 = zext i32 %8 to i64
  %10 = call i32 @lsqpack_val2len(i64 noundef %9, i32 noundef 8)
  store i32 %10, ptr %3, align 4, !tbaa !19
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lsqpack_enc, ptr %11, i32 0, i32 7
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = mul i32 2, %13
  %15 = zext i32 %14 to i64
  %16 = call i32 @lsqpack_val2len(i64 noundef %15, i32 noundef 7)
  store i32 %16, ptr %4, align 4, !tbaa !19
  %17 = load i32, ptr %3, align 4, !tbaa !19
  %18 = load i32, ptr %4, align 4, !tbaa !19
  %19 = add i32 %17, %18
  %20 = zext i32 %19 to i64
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i64 %20
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 28}
!10 = !{!"lsqpack_enc", !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, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !12, i64 56, !6, i64 72, !13, i64 80, !13, i64 96, !13, i64 112, !14, i64 128, !15, i64 160, !11, i64 192, !11, i64 196, !6, i64 200, !18, i64 208, !18, i64 212, !6, i64 216, !11, i64 224, !11, i64 228, !11, i64 232}
!11 = !{!"int", !7, i64 0}
!12 = !{!"lsqpack_enc_head", !6, i64 0, !6, i64 8}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!15 = !{!"", !16, i64 0, !6, i64 24}
!16 = !{!"lsqpack_dec_int_state", !11, i64 0, !11, i64 4, !11, i64 8, !17, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = !{!11, !11, 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"

; Function Attrs: nounwind uwtable
declare hidden i32 @lsqpack_val2len(i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 4294967296) i64 @lsqpack_enc_header_block_prefix_size(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 28
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = shl i32 %3, 1
  %5 = zext i32 %4 to i64
  %6 = tail call i32 @lsqpack_val2len(i64 noundef %5, i32 noundef 8)
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = shl i32 %7, 1
  %9 = zext i32 %8 to i64
  %10 = tail call i32 @lsqpack_val2len(i64 noundef %9, i32 noundef 7)
  %11 = add i32 %10, %6
  %12 = zext i32 %11 to i64
  ret i64 %12
}

attributes #0 = { 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" }

!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 28}
!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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass