; LLVM IR from cruppstahl/upscaledb :: 3rdparty/simdcomp (example)

; 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 = external hidden unnamed_addr constant [41 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @compress(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = udiv i64 %11, 128
  %13 = mul i64 %12, 128
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = icmp ne i64 %13, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %3
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef 128)
  br label %18

18:                                               ; preds = %16, %3
  store i32 0, ptr %7, align 4, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %19, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %55, %18
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = udiv i64 %22, 128
  %24 = icmp ult i64 %21, %23
  br i1 %24, label %25, label %58

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %26 = load i32, ptr %7, align 4, !tbaa !11
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = mul i64 %28, 128
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = call i32 @simdmaxbitsd1(i32 noundef %26, ptr noundef %30)
  store i32 %31, ptr %10, align 4, !tbaa !11
  %32 = load i32, ptr %10, align 4, !tbaa !11
  %33 = trunc i32 %32 to i8
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i32 1
  store ptr %35, ptr %6, align 8, !tbaa !5
  store i8 %33, ptr %34, align 1, !tbaa !13
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = mul i64 %38, 128
  %40 = getelementptr inbounds i32, ptr %37, i64 %39
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !11
  call void @simdpackwithoutmaskd1(i32 noundef %36, ptr noundef %40, ptr noundef %41, i32 noundef %42)
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = mul i64 %44, 128
  %46 = add i64 %45, 128
  %47 = sub i64 %46, 1
  %48 = getelementptr inbounds i32, ptr %43, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !11
  store i32 %49, ptr %7, align 4, !tbaa !11
  %50 = load i32, ptr %10, align 4, !tbaa !11
  %51 = zext i32 %50 to i64
  %52 = mul i64 %51, 16
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 %52
  store ptr %54, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %55

55:                                               ; preds = %25
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = add i64 %56, 1
  store i64 %57, ptr %9, align 8, !tbaa !9
  br label %20, !llvm.loop !14

58:                                               ; preds = %20
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = ptrtoint ptr %59 to i64
  %62 = ptrtoint ptr %60 to i64
  %63 = sub i64 %61, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i64 %63
}

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

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

declare i32 @simdmaxbitsd1(i32 noundef, ptr noundef) #2

declare void @simdpackwithoutmaskd1(i32 noundef, ptr noundef, ptr 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

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

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


; 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 [41 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @compress(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = lshr i64 %1, 7
  %5 = and i64 %1, 127
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %8, label %6

6:                                                ; preds = %3
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 128)
  br label %8

8:                                                ; preds = %6, %3
  %.not26 = icmp ult i64 %1, 128
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.025 = phi ptr [ %19, %.lr.ph ], [ %2, %8 ]
  %.02124 = phi i64 [ %20, %.lr.ph ], [ 0, %8 ]
  %.02223 = phi i32 [ %16, %.lr.ph ], [ 0, %8 ]
  %9 = shl nuw i64 %.02124, 7
  %10 = getelementptr inbounds i32, ptr %0, i64 %9
  %11 = tail call i32 @simdmaxbitsd1(i32 noundef %.02223, ptr noundef %10) #3
  %12 = trunc i32 %11 to i8
  %13 = getelementptr inbounds i8, ptr %.025, i64 1
  store i8 %12, ptr %.025, align 1, !tbaa !5
  tail call void @simdpackwithoutmaskd1(i32 noundef %.02223, ptr noundef %10, ptr noundef nonnull %13, i32 noundef %11) #3
  %14 = or disjoint i64 %9, 127
  %15 = getelementptr inbounds i32, ptr %0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !8
  %17 = zext i32 %11 to i64
  %18 = shl nuw nsw i64 %17, 4
  %19 = getelementptr inbounds i8, ptr %13, i64 %18
  %20 = add nuw nsw i64 %.02124, 1
  %exitcond.not = icmp eq i64 %20, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %8
  %.0.lcssa = phi ptr [ %2, %8 ], [ %19, %.lr.ph ]
  %21 = ptrtoint ptr %.0.lcssa to i64
  %22 = ptrtoint ptr %2 to i64
  %23 = sub i64 %21, %22
  ret i64 %23
}

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

declare i32 @simdmaxbitsd1(i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @simdpackwithoutmaskd1(i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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


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