; LLVM IR from seppo0010/rlite :: src (hyperloglog)

; 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.hllhdr = type { [4 x i8], i8, [3 x i8], [8 x i8], [0 x i8] }

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

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

; 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 @hllSparseToDense(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_str_pfdebug_getreg(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i8, align 1
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = alloca i64, align 8
  %23 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = call i32 @isHLLObject(ptr noundef %24, i64 noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %6
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %108

29:                                               ; preds = %6
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %14, align 8, !tbaa !5
  %31 = load ptr, ptr %14, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.hllhdr, ptr %31, i32 0, i32 1
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %43

36:                                               ; preds = %29
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = call i32 @hllSparseToDense(ptr noundef %37, i64 noundef %38, ptr noundef %8, ptr noundef %9)
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i32 -2, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %108

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42, %29
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %44, ptr %14, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 16384, ptr %45, align 4, !tbaa !12
  %46 = call noalias ptr @malloc(i64 noundef 131072) #4
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %46, ptr %47, align 8, !tbaa !5
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %52, label %51

51:                                               ; preds = %43
  store i32 -3, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %108

52:                                               ; preds = %43
  store i32 0, ptr %15, align 4, !tbaa !12
  br label %53

53:                                               ; preds = %100, %52
  %54 = load i32, ptr %15, align 4, !tbaa !12
  %55 = icmp slt i32 %54, 16384
  br i1 %55, label %56, label %103

56:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 1, ptr %17) #3
  br label %57

57:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.hllhdr, ptr %58, i32 0, i32 4
  %60 = getelementptr inbounds [0 x i8], ptr %59, i64 0, i64 0
  store ptr %60, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %61 = load i32, ptr %15, align 4, !tbaa !12
  %62 = mul nsw i32 %61, 6
  %63 = sdiv i32 %62, 8
  %64 = sext i32 %63 to i64
  store i64 %64, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %65 = load i32, ptr %15, align 4, !tbaa !12
  %66 = mul nsw i32 %65, 6
  %67 = and i32 %66, 7
  %68 = sext i32 %67 to i64
  store i64 %68, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %69 = load i64, ptr %20, align 8, !tbaa !9
  %70 = sub i64 8, %69
  store i64 %70, ptr %21, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  %71 = load ptr, ptr %18, align 8, !tbaa !5
  %72 = load i64, ptr %19, align 8, !tbaa !9
  %73 = getelementptr inbounds i8, ptr %71, i64 %72
  %74 = load i8, ptr %73, align 1, !tbaa !11
  %75 = zext i8 %74 to i64
  store i64 %75, ptr %22, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  %76 = load ptr, ptr %18, align 8, !tbaa !5
  %77 = load i64, ptr %19, align 8, !tbaa !9
  %78 = add i64 %77, 1
  %79 = getelementptr inbounds i8, ptr %76, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !11
  %81 = zext i8 %80 to i64
  store i64 %81, ptr %23, align 8, !tbaa !9
  %82 = load i64, ptr %22, align 8, !tbaa !9
  %83 = load i64, ptr %20, align 8, !tbaa !9
  %84 = lshr i64 %82, %83
  %85 = load i64, ptr %23, align 8, !tbaa !9
  %86 = load i64, ptr %21, align 8, !tbaa !9
  %87 = shl i64 %85, %86
  %88 = or i64 %84, %87
  %89 = and i64 %88, 63
  %90 = trunc i64 %89 to i8
  store i8 %90, ptr %17, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %91

91:                                               ; preds = %57
  br label %92

92:                                               ; preds = %91
  %93 = load i8, ptr %17, align 1, !tbaa !11
  %94 = zext i8 %93 to i64
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  %96 = load ptr, ptr %95, align 8, !tbaa !5
  %97 = load i32, ptr %15, align 4, !tbaa !12
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i64, ptr %96, i64 %98
  store i64 %94, ptr %99, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %17) #3
  br label %100

100:                                              ; preds = %92
  %101 = load i32, ptr %15, align 4, !tbaa !12
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %15, align 4, !tbaa !12
  br label %53, !llvm.loop !14

103:                                              ; preds = %53
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %104, ptr %105, align 8, !tbaa !5
  %106 = load i64, ptr %9, align 8, !tbaa !9
  %107 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %106, ptr %107, align 8, !tbaa !9
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %108

108:                                              ; preds = %103, %51, %41, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %109 = load i32, ptr %7, align 4
  ret i32 %109
}

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

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 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 }
attributes #4 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -3, 1) i32 @rl_str_pfdebug_getreg(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  %9 = tail call i32 @isHLLObject(ptr noundef %0, i64 noundef %1)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %50

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = icmp eq i8 %12, 1
  br i1 %13, label %14, label %17

14:                                               ; preds = %10
  %15 = call i32 @hllSparseToDense(ptr noundef nonnull %0, i64 noundef %1, ptr noundef nonnull %7, ptr noundef nonnull %8)
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %50, label %._crit_edge

._crit_edge:                                      ; preds = %14
  %.pre = load ptr, ptr %7, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %._crit_edge, %10
  %18 = phi ptr [ %.pre, %._crit_edge ], [ %0, %10 ]
  store i32 16384, ptr %2, align 4, !tbaa !12
  %19 = call noalias dereferenceable_or_null(131072) ptr @malloc(i64 noundef 131072) #3
  store ptr %19, ptr %3, align 8, !tbaa !5
  %.not24 = icmp eq ptr %19, null
  br i1 %.not24, label %50, label %.preheader

.preheader:                                       ; preds = %17
  %20 = getelementptr inbounds i8, ptr %18, i64 16
  br label %21

21:                                               ; preds = %21, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.1, %21 ]
  %22 = trunc i64 %indvars.iv to i32
  %23 = mul nuw nsw i32 %22, 6
  %24 = lshr i32 %23, 3
  %25 = zext nneg i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %20, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %26, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = trunc i32 %23 to i8
  %31 = call i8 @llvm.fshr.i8(i8 %29, i8 %27, i8 %30)
  %32 = and i8 %31, 63
  %33 = zext nneg i8 %32 to i64
  %34 = getelementptr inbounds i64, ptr %19, i64 %indvars.iv
  store i64 %33, ptr %34, align 8, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %35 = trunc i64 %indvars.iv.next to i32
  %36 = mul nuw nsw i32 %35, 6
  %37 = lshr i32 %36, 3
  %38 = zext nneg i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %20, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = getelementptr inbounds i8, ptr %39, i64 1
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = trunc i32 %36 to i8
  %44 = call i8 @llvm.fshr.i8(i8 %42, i8 %40, i8 %43)
  %45 = and i8 %44, 63
  %46 = zext nneg i8 %45 to i64
  %47 = getelementptr inbounds i64, ptr %19, i64 %indvars.iv.next
  store i64 %46, ptr %47, align 8, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 16384
  br i1 %exitcond.not.1, label %48, label %21, !llvm.loop !14

48:                                               ; preds = %21
  store ptr %18, ptr %4, align 8, !tbaa !5
  %49 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %49, ptr %5, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %17, %14, %6, %48
  %.0 = phi i32 [ 0, %48 ], [ -1, %6 ], [ -2, %14 ], [ -3, %17 ]
  ret i32 %.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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.fshr.i8(i8, i8, i8) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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