; LLVM IR from fast-pack/simdcomp :: example (varying_bit_width_demo)

; 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 [13 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [5 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

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

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

; 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 i32 @rand() #3

; Function Attrs: nounwind uwtable
declare dso_local i64 @varying_bit_width_compress(ptr noundef, i64 noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @varying_bit_width_demo() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 256, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = mul i64 %11, 4
  %13 = call noalias ptr @malloc(i64 noundef %12) #6
  store ptr %13, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = mul i64 %14, 4
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = udiv i64 %16, 128
  %18 = add i64 %15, %17
  %19 = call noalias ptr @malloc(i64 noundef %18) #6
  store ptr %19, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %20, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = mul i64 %21, 4
  %23 = call noalias ptr @malloc(i64 noundef %22) #6
  store ptr %23, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %39, %0
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %29, label %42

29:                                               ; preds = %25
  %30 = call i32 @rand() #5
  %31 = sext i32 %30 to i64
  %32 = load i64, ptr %7, align 8, !tbaa !5
  %33 = add i64 %32, 1
  %34 = urem i64 %31, %33
  %35 = trunc i64 %34 to i32
  %36 = load ptr, ptr %3, align 8, !tbaa !9
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds i32, ptr %36, i64 %37
  store i32 %35, ptr %38, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %29
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = add i64 %40, 1
  store i64 %41, ptr %7, align 8, !tbaa !5
  br label %25, !llvm.loop !13

42:                                               ; preds = %25
  %43 = load ptr, ptr %3, align 8, !tbaa !9
  %44 = load i64, ptr %2, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = call i64 @varying_bit_width_compress(ptr noundef %43, i64 noundef %44, ptr noundef %45)
  store i64 %46, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !5
  %48 = trunc i64 %47 to i32
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = mul i64 %49, 4
  %51 = trunc i64 %50 to i32
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, i32 noundef %48, i32 noundef %51)
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %75, %42
  %54 = load i64, ptr %7, align 8, !tbaa !5
  %55 = mul i64 %54, 128
  %56 = load i64, ptr %2, align 8, !tbaa !5
  %57 = icmp ult i64 %55, %56
  br i1 %57, label %58, label %78

58:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = load i8, ptr %59, align 1, !tbaa !15
  %61 = zext i8 %60 to i32
  store i32 %61, ptr %9, align 4, !tbaa !11
  %62 = load ptr, ptr %4, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %62, i32 1
  store ptr %63, ptr %4, align 8, !tbaa !9
  %64 = load ptr, ptr %4, align 8, !tbaa !9
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  %66 = load i64, ptr %7, align 8, !tbaa !5
  %67 = mul i64 %66, 128
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %9, align 4, !tbaa !11
  call void @simdunpack(ptr noundef %64, ptr noundef %68, i32 noundef %69)
  %70 = load i32, ptr %9, align 4, !tbaa !11
  %71 = zext i32 %70 to i64
  %72 = mul i64 %71, 16
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  %74 = getelementptr inbounds i8, ptr %73, i64 %72
  store ptr %74, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %75

75:                                               ; preds = %58
  %76 = load i64, ptr %7, align 8, !tbaa !5
  %77 = add i64 %76, 1
  store i64 %77, ptr %7, align 8, !tbaa !5
  br label %53, !llvm.loop !16

78:                                               ; preds = %53
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %96, %78
  %80 = load i64, ptr %7, align 8, !tbaa !5
  %81 = load i64, ptr %2, align 8, !tbaa !5
  %82 = icmp ult i64 %80, %81
  br i1 %82, label %83, label %99

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

93:                                               ; preds = %83
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.15)
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %10, align 4
  br label %104

95:                                               ; preds = %83
  br label %96

96:                                               ; preds = %95
  %97 = load i64, ptr %7, align 8, !tbaa !5
  %98 = add i64 %97, 1
  store i64 %98, ptr %7, align 8, !tbaa !5
  br label %79, !llvm.loop !17

99:                                               ; preds = %79
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %101 = load ptr, ptr %3, align 8, !tbaa !9
  call void @free(ptr noundef %101) #5
  %102 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %102) #5
  %103 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %103) #5
  store i32 0, ptr %1, align 4
  store i32 1, ptr %10, align 4
  br label %104

104:                                              ; preds = %99, %93
  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
  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 8, ptr %2) #5
  %105 = load i32, ptr %1, align 4
  ret i32 %105
}

declare void @simdunpack(ptr noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !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 [13 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [5 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @varying_bit_width_compress(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @varying_bit_width_demo() local_unnamed_addr #4 {
  %1 = tail call noalias dereferenceable_or_null(1024) ptr @malloc(i64 noundef 1024) #6
  %2 = tail call noalias dereferenceable_or_null(1026) ptr @malloc(i64 noundef 1026) #6
  %3 = tail call noalias dereferenceable_or_null(1024) ptr @malloc(i64 noundef 1024) #6
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  br label %5

5:                                                ; preds = %0, %5
  %.03840 = phi i64 [ 0, %0 ], [ %8, %5 ]
  %6 = tail call i32 @rand() #7
  %7 = sext i32 %6 to i64
  %8 = add nuw nsw i64 %.03840, 1
  %9 = urem i64 %7, %8
  %10 = trunc nuw nsw i64 %9 to i32
  %11 = getelementptr inbounds i32, ptr %1, i64 %.03840
  store i32 %10, ptr %11, align 4, !tbaa !5
  %exitcond.not = icmp eq i64 %8, 256
  br i1 %exitcond.not, label %.preheader.preheader, label %5, !llvm.loop !9

.preheader.preheader:                             ; preds = %5
  %12 = tail call i64 @varying_bit_width_compress(ptr noundef nonnull %1, i64 noundef 256, ptr noundef %2)
  %13 = trunc i64 %12 to i32
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, i32 noundef %13, i32 noundef 1024)
  %15 = load i8, ptr %2, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = getelementptr inbounds i8, ptr %2, i64 1
  tail call void @simdunpack(ptr noundef nonnull %17, ptr noundef %3, i32 noundef %16) #7
  %18 = zext i8 %15 to i64
  %19 = shl nuw nsw i64 %18, 4
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = getelementptr inbounds i8, ptr %20, i64 1
  %24 = getelementptr inbounds i8, ptr %3, i64 512
  tail call void @simdunpack(ptr noundef nonnull %23, ptr noundef nonnull %24, i32 noundef %22) #7
  br label %.preheader

.preheader.1:                                     ; preds = %.preheader
  %25 = or disjoint i64 %.243, 1
  %26 = getelementptr inbounds i32, ptr %3, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = getelementptr inbounds i32, ptr %1, i64 %25
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %27, %29
  br i1 %.not.1, label %.preheader.2, label %46

.preheader.2:                                     ; preds = %.preheader.1
  %30 = or disjoint i64 %.243, 2
  %31 = getelementptr inbounds i32, ptr %3, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = getelementptr inbounds i32, ptr %1, i64 %30
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %.not.2 = icmp eq i32 %32, %34
  br i1 %.not.2, label %.preheader.3, label %46

.preheader.3:                                     ; preds = %.preheader.2
  %35 = or disjoint i64 %.243, 3
  %36 = getelementptr inbounds i32, ptr %3, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds i32, ptr %1, i64 %35
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %.not.3 = icmp eq i32 %37, %39
  br i1 %.not.3, label %40, label %46

40:                                               ; preds = %.preheader.3
  %41 = add nuw nsw i64 %.243, 4
  %exitcond45.not.3 = icmp eq i64 %41, 256
  br i1 %exitcond45.not.3, label %48, label %.preheader, !llvm.loop !12

.preheader:                                       ; preds = %40, %.preheader.preheader
  %.243 = phi i64 [ 0, %.preheader.preheader ], [ %41, %40 ]
  %42 = getelementptr inbounds i32, ptr %3, i64 %.243
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = getelementptr inbounds i32, ptr %1, i64 %.243
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %.not = icmp eq i32 %43, %45
  br i1 %.not, label %.preheader.1, label %46

46:                                               ; preds = %.preheader.3, %.preheader.2, %.preheader.1, %.preheader
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15)
  br label %50

48:                                               ; preds = %40
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  tail call void @free(ptr noundef nonnull %1) #7
  tail call void @free(ptr noundef %2) #7
  tail call void @free(ptr noundef nonnull %3) #7
  br label %50

50:                                               ; preds = %48, %46
  %.0 = phi i32 [ -1, %46 ], [ 0, %48 ]
  ret i32 %.0
}

declare void @simdunpack(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #5

attributes #0 = { 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 #1 = { 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 #2 = { 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 #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 = { "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 = { nounwind allocsize(0) }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass