; LLVM IR from fast-pack/simdcomp :: tests (unit)

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

@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@__func__.testlongpack = external hidden unnamed_addr constant [13 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i32 @simdpack_compressedbytes(i32 noundef, i32 noundef) #1

declare ptr @simdpack_length(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #1

declare ptr @simdunpack_length(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @rand() #3

; Function Attrs: nounwind uwtable
define dso_local i32 @testlongpack() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @srand(i32 noundef 0) #5
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef @__func__.testlongpack)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %107, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 32
  br i1 %14, label %15, label %110

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 2048, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %16 = call noalias ptr @malloc(i64 noundef 8192) #6
  store ptr %16, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %17 = call noalias ptr @malloc(i64 noundef 8192) #6
  store ptr %17, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %18 = call noalias ptr @malloc(i64 noundef 20480) #6
  store ptr %18, ptr %9, align 8, !tbaa !11
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %31, %15
  %20 = load i64, ptr %3, align 8, !tbaa !9
  %21 = icmp ult i64 %20, 2048
  br i1 %21, label %22, label %34

22:                                               ; preds = %19
  %23 = call i32 @rand() #5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = shl i32 1, %24
  %26 = sub i32 %25, 1
  %27 = and i32 %23, %26
  %28 = load ptr, ptr %7, align 8, !tbaa !11
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = getelementptr inbounds i32, ptr %28, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %22
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %3, align 8, !tbaa !9
  br label %19, !llvm.loop !13

34:                                               ; preds = %19
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %97, %34
  %36 = load i64, ptr %4, align 8, !tbaa !9
  %37 = icmp ule i64 %36, 2048
  br i1 %37, label %38, label %100

38:                                               ; preds = %35
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %46, %38
  %40 = load i64, ptr %3, align 8, !tbaa !9
  %41 = icmp ult i64 %40, 2048
  br i1 %41, label %42, label %49

42:                                               ; preds = %39
  %43 = load ptr, ptr %8, align 8, !tbaa !11
  %44 = load i64, ptr %3, align 8, !tbaa !9
  %45 = getelementptr inbounds i32, ptr %43, i64 %44
  store i32 0, ptr %45, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %42
  %47 = load i64, ptr %3, align 8, !tbaa !9
  %48 = add i64 %47, 1
  store i64 %48, ptr %3, align 8, !tbaa !9
  br label %39, !llvm.loop !15

49:                                               ; preds = %39
  %50 = load ptr, ptr %7, align 8, !tbaa !11
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = load ptr, ptr %9, align 8, !tbaa !11
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = call ptr @simdpack_length(ptr noundef %50, i64 noundef %51, ptr noundef %52, i32 noundef %53)
  store ptr %54, ptr %5, align 8, !tbaa !11
  %55 = load ptr, ptr %5, align 8, !tbaa !11
  %56 = load ptr, ptr %9, align 8, !tbaa !11
  %57 = ptrtoint ptr %55 to i64
  %58 = ptrtoint ptr %56 to i64
  %59 = sub i64 %57, %58
  %60 = sdiv exact i64 %59, 16
  %61 = mul i64 %60, 16
  %62 = load i64, ptr %4, align 8, !tbaa !9
  %63 = trunc i64 %62 to i32
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = call i32 @simdpack_compressedbytes(i32 noundef %63, i32 noundef %64)
  %66 = zext i32 %65 to i64
  %67 = icmp ne i64 %61, %66
  br i1 %67, label %68, label %70

68:                                               ; preds = %49
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %10, align 4
  br label %104

70:                                               ; preds = %49
  %71 = load ptr, ptr %9, align 8, !tbaa !11
  %72 = load i64, ptr %4, align 8, !tbaa !9
  %73 = load ptr, ptr %8, align 8, !tbaa !11
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = call ptr @simdunpack_length(ptr noundef %71, i64 noundef %72, ptr noundef %73, i32 noundef %74)
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %93, %70
  %77 = load i64, ptr %3, align 8, !tbaa !9
  %78 = load i64, ptr %4, align 8, !tbaa !9
  %79 = icmp ult i64 %77, %78
  br i1 %79, label %80, label %96

80:                                               ; preds = %76
  %81 = load ptr, ptr %7, align 8, !tbaa !11
  %82 = load i64, ptr %3, align 8, !tbaa !9
  %83 = getelementptr inbounds i32, ptr %81, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = load ptr, ptr %8, align 8, !tbaa !11
  %86 = load i64, ptr %3, align 8, !tbaa !9
  %87 = getelementptr inbounds i32, ptr %85, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = icmp ne i32 %84, %88
  br i1 %89, label %90, label %92

90:                                               ; preds = %80
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %10, align 4
  br label %104

92:                                               ; preds = %80
  br label %93

93:                                               ; preds = %92
  %94 = load i64, ptr %3, align 8, !tbaa !9
  %95 = add i64 %94, 1
  store i64 %95, ptr %3, align 8, !tbaa !9
  br label %76, !llvm.loop !16

96:                                               ; preds = %76
  br label %97

97:                                               ; preds = %96
  %98 = load i64, ptr %4, align 8, !tbaa !9
  %99 = add i64 %98, 1
  store i64 %99, ptr %4, align 8, !tbaa !9
  br label %35, !llvm.loop !17

100:                                              ; preds = %35
  %101 = load ptr, ptr %7, align 8, !tbaa !11
  call void @free(ptr noundef %101) #5
  %102 = load ptr, ptr %8, align 8, !tbaa !11
  call void @free(ptr noundef %102) #5
  %103 = load ptr, ptr %9, align 8, !tbaa !11
  call void @free(ptr noundef %103) #5
  store i32 0, ptr %10, align 4
  br label %104

104:                                              ; preds = %100, %90, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %105 = load i32, ptr %10, align 4
  switch i32 %105, label %111 [
    i32 0, label %106
  ]

106:                                              ; preds = %104
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %2, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !18

110:                                              ; preds = %12
  store i32 0, ptr %1, align 4
  store i32 1, ptr %10, align 4
  br label %111

111:                                              ; preds = %110, %104
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %112 = load i32, ptr %1, align 4
  ret i32 %112
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 allocsize(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 "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 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"int", !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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


; 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.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@__func__.testlongpack = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

declare i32 @simdpack_compressedbytes(i32 noundef, i32 noundef) local_unnamed_addr #2

declare ptr @simdpack_length(ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @simdunpack_length(ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @testlongpack() local_unnamed_addr #5 {
  tail call void @srand(i32 noundef 0) #7
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull @__func__.testlongpack)
  br label %2

2:                                                ; preds = %0, %.thread
  %.03748 = phi i32 [ 0, %0 ], [ %28, %.thread ]
  %3 = tail call noalias dereferenceable_or_null(8192) ptr @malloc(i64 noundef 8192) #8
  %4 = tail call noalias dereferenceable_or_null(8192) ptr @malloc(i64 noundef 8192) #8
  %5 = tail call noalias dereferenceable_or_null(20480) ptr @malloc(i64 noundef 20480) #8
  %notmask = shl nsw i32 -1, %.03748
  %6 = xor i32 %notmask, -1
  br label %8

.preheader43:                                     ; preds = %8
  %7 = ptrtoint ptr %5 to i64
  br label %.preheader

8:                                                ; preds = %2, %8
  %.03844 = phi i64 [ 0, %2 ], [ %12, %8 ]
  %9 = tail call i32 @rand() #7
  %10 = and i32 %9, %6
  %11 = getelementptr inbounds i32, ptr %3, i64 %.03844
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = add nuw nsw i64 %.03844, 1
  %exitcond.not = icmp eq i64 %12, 2048
  br i1 %exitcond.not, label %.preheader43, label %8, !llvm.loop !9

.preheader:                                       ; preds = %.preheader43, %._crit_edge
  %.04147 = phi i64 [ 0, %.preheader43 ], [ %27, %._crit_edge ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(8192) %4, i8 0, i64 8192, i1 false), !tbaa !5
  %13 = tail call ptr @simdpack_length(ptr noundef %3, i64 noundef %.04147, ptr noundef %5, i32 noundef %.03748) #7
  %14 = ptrtoint ptr %13 to i64
  %15 = sub i64 %14, %7
  %16 = trunc nuw nsw i64 %.04147 to i32
  %17 = tail call i32 @simdpack_compressedbytes(i32 noundef %16, i32 noundef %.03748) #7
  %18 = zext i32 %17 to i64
  %.not = icmp eq i64 %15, %18
  br i1 %.not, label %19, label %.loopexit.sink.split

19:                                               ; preds = %.preheader
  %20 = tail call ptr @simdunpack_length(ptr noundef %5, i64 noundef %.04147, ptr noundef nonnull %4, i32 noundef %.03748) #7
  %.not50 = icmp eq i64 %.04147, 0
  br i1 %.not50, label %._crit_edge, label %.lr.ph

21:                                               ; preds = %.lr.ph
  %22 = add nuw nsw i64 %.24046, 1
  %exitcond51.not = icmp eq i64 %22, %.04147
  br i1 %exitcond51.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

.lr.ph:                                           ; preds = %19, %21
  %.24046 = phi i64 [ %22, %21 ], [ 0, %19 ]
  %23 = getelementptr inbounds i32, ptr %3, i64 %.24046
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %4, i64 %.24046
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %.not42 = icmp eq i32 %24, %26
  br i1 %.not42, label %21, label %.loopexit.sink.split

._crit_edge:                                      ; preds = %21, %19
  %27 = add nuw nsw i64 %.04147, 1
  %exitcond52 = icmp eq i64 %27, 2049
  br i1 %exitcond52, label %.thread, label %.preheader, !llvm.loop !12

.thread:                                          ; preds = %._crit_edge
  tail call void @free(ptr noundef %3) #7
  tail call void @free(ptr noundef nonnull %4) #7
  tail call void @free(ptr noundef %5) #7
  %28 = add nuw nsw i32 %.03748, 1
  %exitcond53.not = icmp eq i32 %28, 32
  br i1 %exitcond53.not, label %.loopexit, label %2, !llvm.loop !13

.loopexit.sink.split:                             ; preds = %.preheader, %.lr.ph
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.loopexit

.loopexit:                                        ; preds = %.thread, %.loopexit.sink.split
  %.2 = phi i32 [ -1, %.loopexit.sink.split ], [ 0, %.thread ]
  ret i32 %.2
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

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 nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 "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 #5 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass