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

; 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.45 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [50 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_write_ici(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lsqpack_dec, ptr %11, i32 0, i32 8
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.lsqpack_dec, ptr %14, i32 0, i32 9
  %16 = load i32, ptr %15, align 4, !tbaa !19
  %17 = icmp ne i32 %13, %16
  br i1 %17, label %18, label %103

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

21:                                               ; preds = %18
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %125

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.lsqpack_dec, ptr %23, i32 0, i32 5
  %25 = load i32, ptr %24, align 4, !tbaa !20
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %45

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.lsqpack_dec, ptr %28, i32 0, i32 8
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.lsqpack_dec, ptr %31, i32 0, i32 5
  %33 = load i32, ptr %32, align 4, !tbaa !20
  %34 = mul i32 %33, 2
  %35 = add i32 %30, %34
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lsqpack_dec, ptr %36, i32 0, i32 9
  %38 = load i32, ptr %37, align 4, !tbaa !19
  %39 = sub i32 %35, %38
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.lsqpack_dec, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 4, !tbaa !20
  %43 = mul i32 %42, 2
  %44 = urem i32 %39, %43
  br label %46

45:                                               ; preds = %22
  br label %46

46:                                               ; preds = %45, %27
  %47 = phi i32 [ %44, %27 ], [ 0, %45 ]
  store i32 %47, ptr %9, align 4, !tbaa !21
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %48, align 1, !tbaa !22
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load i64, ptr %7, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load i32, ptr %9, align 4, !tbaa !21
  %54 = zext i32 %53 to i64
  %55 = call ptr @lsqpack_enc_int(ptr noundef %49, ptr noundef %52, i64 noundef %54, i32 noundef 6)
  store ptr %55, ptr %8, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = icmp ugt ptr %56, %57
  br i1 %58, label %59, label %102

59:                                               ; preds = %46
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.lsqpack_dec, ptr %61, i32 0, i32 11
  %63 = load ptr, ptr %62, align 8, !tbaa !23
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %79

65:                                               ; preds = %60
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.lsqpack_dec, ptr %66, i32 0, i32 11
  %68 = load ptr, ptr %67, align 8, !tbaa !23
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str.37) #3
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.lsqpack_dec, ptr %70, i32 0, i32 11
  %72 = load ptr, ptr %71, align 8, !tbaa !23
  %73 = load i32, ptr %9, align 4, !tbaa !21
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str.45, i32 noundef %73) #3
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.lsqpack_dec, ptr %75, i32 0, i32 11
  %77 = load ptr, ptr %76, align 8, !tbaa !23
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef @.str.2) #3
  br label %79

79:                                               ; preds = %65, %60
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.lsqpack_dec, ptr %82, i32 0, i32 8
  %84 = load i32, ptr %83, align 8, !tbaa !11
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.lsqpack_dec, ptr %85, i32 0, i32 9
  store i32 %84, ptr %86, align 4, !tbaa !19
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = ptrtoint ptr %87 to i64
  %90 = ptrtoint ptr %88 to i64
  %91 = sub i64 %89, %90
  %92 = trunc i64 %91 to i32
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.lsqpack_dec, ptr %93, i32 0, i32 6
  %95 = load i32, ptr %94, align 8, !tbaa !24
  %96 = add i32 %95, %92
  store i32 %96, ptr %94, align 8, !tbaa !24
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = ptrtoint ptr %97 to i64
  %100 = ptrtoint ptr %98 to i64
  %101 = sub i64 %99, %100
  store i64 %101, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %125

102:                                              ; preds = %46
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %125

103:                                              ; preds = %3
  br label %104

104:                                              ; preds = %103
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.lsqpack_dec, ptr %105, i32 0, i32 11
  %107 = load ptr, ptr %106, align 8, !tbaa !23
  %108 = icmp ne ptr %107, null
  br i1 %108, label %109, label %122

109:                                              ; preds = %104
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.lsqpack_dec, ptr %110, i32 0, i32 11
  %112 = load ptr, ptr %111, align 8, !tbaa !23
  %113 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %112, ptr noundef @.str.37) #3
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.lsqpack_dec, ptr %114, i32 0, i32 11
  %116 = load ptr, ptr %115, align 8, !tbaa !23
  %117 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %116, ptr noundef @.str.46) #3
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.lsqpack_dec, ptr %118, i32 0, i32 11
  %120 = load ptr, ptr %119, align 8, !tbaa !23
  %121 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %120, ptr noundef @.str.2) #3
  br label %122

122:                                              ; preds = %109, %104
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %125

125:                                              ; preds = %124, %102, %81, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %126 = load i64, ptr %4, align 8
  ret i64 %126
}

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 32}
!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 = !{!12, !13, i64 36}
!20 = !{!12, !13, i64 20}
!21 = !{!13, !13, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!12, !6, i64 48}
!24 = !{!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.45 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [50 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_write_ici(ptr nocapture noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 36
  %7 = load i32, ptr %6, align 4, !tbaa !17
  %.not = icmp eq i32 %5, %7
  br i1 %.not, label %42, label %8

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

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %12 = load i32, ptr %11, align 4, !tbaa !18
  %.not40 = icmp eq i32 %12, 0
  br i1 %.not40, label %18, label %13

13:                                               ; preds = %10
  %14 = shl i32 %12, 1
  %15 = sub i32 %5, %7
  %16 = add i32 %15, %14
  %17 = urem i32 %16, %14
  br label %18

18:                                               ; preds = %10, %13
  %19 = phi i32 [ %17, %13 ], [ 0, %10 ]
  store i8 0, ptr %1, align 1, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %1, i64 %2
  %21 = zext i32 %19 to i64
  %22 = tail call ptr @lsqpack_enc_int(ptr noundef nonnull %1, ptr noundef nonnull %20, i64 noundef %21, i32 noundef 6)
  %23 = icmp ugt ptr %22, %1
  br i1 %23, label %24, label %51

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %.not41 = icmp eq ptr %26, null
  br i1 %.not41, label %33, label %27

27:                                               ; preds = %24
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %26, ptr noundef nonnull @.str.37) #2
  %29 = load ptr, ptr %25, align 8, !tbaa !20
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.45, i32 noundef %19) #2
  %31 = load ptr, ptr %25, align 8, !tbaa !20
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.2) #2
  br label %33

33:                                               ; preds = %27, %24
  %34 = load i32, ptr %4, align 8, !tbaa !5
  store i32 %34, ptr %6, align 4, !tbaa !17
  %35 = ptrtoint ptr %22 to i64
  %36 = ptrtoint ptr %1 to i64
  %37 = sub i64 %35, %36
  %38 = trunc i64 %37 to i32
  %39 = getelementptr inbounds i8, ptr %0, i64 24
  %40 = load i32, ptr %39, align 8, !tbaa !21
  %41 = add i32 %40, %38
  store i32 %41, ptr %39, align 8, !tbaa !21
  br label %51

42:                                               ; preds = %3
  %43 = getelementptr inbounds i8, ptr %0, i64 48
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %.not39 = icmp eq ptr %44, null
  br i1 %.not39, label %51, label %45

45:                                               ; preds = %42
  %46 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %44, ptr noundef nonnull @.str.37) #2
  %47 = load ptr, ptr %43, align 8, !tbaa !20
  %48 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.46) #2
  %49 = load ptr, ptr %43, align 8, !tbaa !20
  %50 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef nonnull @.str.2) #2
  br label %51

51:                                               ; preds = %42, %45, %18, %8, %33
  %.0 = phi i64 [ %37, %33 ], [ -1, %8 ], [ -1, %18 ], [ 0, %45 ], [ 0, %42 ]
  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 32}
!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, !7, i64 36}
!18 = !{!6, !7, i64 20}
!19 = !{!8, !8, i64 0}
!20 = !{!6, !10, i64 48}
!21 = !{!6, !7, i64 24}


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