; LLVM IR from ryanlayer/giggle :: src (ll)

; 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.uint64_t_ll_bpt_leading_data = type { ptr }
%struct.uint64_t_ll = type { i64, ptr, ptr }
%struct.uint64_t_ll_node = type { i64, ptr }

@.str.6 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [36 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) #2

; Function Attrs: noreturn
declare void @errx(i32 noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @uint64_t_ll_leading_serialize(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i64, 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 ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %16, align 8, !tbaa !5
  store i64 0, ptr %3, align 8
  br label %86

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %18, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.uint64_t_ll_bpt_leading_data, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %17
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.uint64_t_ll_bpt_leading_data, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.uint64_t_ll, ptr %26, i32 0, i32 0
  %28 = load i64, ptr %27, align 8, !tbaa !11
  store i64 %28, ptr %7, align 8, !tbaa !14
  br label %30

29:                                               ; preds = %17
  store i64 0, ptr %7, align 8, !tbaa !14
  br label %30

30:                                               ; preds = %29, %23
  %31 = load i64, ptr %7, align 8, !tbaa !14
  %32 = add i64 1, %31
  %33 = mul i64 %32, 8
  store i64 %33, ptr %8, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %34 = load i64, ptr %7, align 8, !tbaa !14
  %35 = add i64 1, %34
  %36 = call noalias ptr @calloc(i64 noundef %35, i64 noundef 8) #5
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %40

39:                                               ; preds = %30
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.6) #6
  unreachable

40:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !14
  %41 = load i64, ptr %7, align 8, !tbaa !14
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i64, ptr %10, align 8, !tbaa !14
  %44 = add i64 %43, 1
  store i64 %44, ptr %10, align 8, !tbaa !14
  %45 = getelementptr inbounds i64, ptr %42, i64 %43
  store i64 %41, ptr %45, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.uint64_t_ll_bpt_leading_data, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %82

50:                                               ; preds = %40
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.uint64_t_ll_bpt_leading_data, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.uint64_t_ll, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  store ptr %55, ptr %12, align 8, !tbaa !5
  store i64 0, ptr %11, align 8, !tbaa !14
  br label %56

56:                                               ; preds = %59, %50
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %72

59:                                               ; preds = %56
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.uint64_t_ll_node, ptr %60, i32 0, i32 0
  %62 = load i64, ptr %61, align 8, !tbaa !16
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i64, ptr %10, align 8, !tbaa !14
  %65 = add i64 %64, 1
  store i64 %65, ptr %10, align 8, !tbaa !14
  %66 = getelementptr inbounds i64, ptr %63, i64 %64
  store i64 %62, ptr %66, align 8, !tbaa !14
  %67 = load i64, ptr %11, align 8, !tbaa !14
  %68 = add i64 %67, 1
  store i64 %68, ptr %11, align 8, !tbaa !14
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.uint64_t_ll_node, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !18
  store ptr %71, ptr %12, align 8, !tbaa !5
  br label %56, !llvm.loop !19

72:                                               ; preds = %56
  %73 = load i64, ptr %11, align 8, !tbaa !14
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.uint64_t_ll_bpt_leading_data, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.uint64_t_ll, ptr %76, i32 0, i32 0
  %78 = load i64, ptr %77, align 8, !tbaa !11
  %79 = icmp ne i64 %73, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %72
  call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef @.str.7) #6
  unreachable

81:                                               ; preds = %72
  br label %82

82:                                               ; preds = %81, %40
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %83, ptr %84, align 8, !tbaa !5
  %85 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %85, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %86

86:                                               ; preds = %82, %15
  %87 = load i64, ptr %3, align 8
  ret i64 %87
}

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

!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, !6, i64 0}
!10 = !{!"uint64_t_ll_bpt_leading_data", !6, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"uint64_t_ll", !13, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!17, !13, i64 0}
!17 = !{!"uint64_t_ll_node", !13, i64 0, !6, i64 8}
!18 = !{!17, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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.6 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [36 x i8], align 1

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

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: noreturn
declare void @errx(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @uint64_t_ll_leading_serialize(ptr noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #2 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %21, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %8, label %6

6:                                                ; preds = %4
  %7 = load i64, ptr %5, align 8, !tbaa !10
  br label %8

8:                                                ; preds = %4, %6
  %.027 = phi i64 [ %7, %6 ], [ 0, %4 ]
  %9 = add i64 %.027, 1
  %10 = shl i64 %9, 3
  %11 = tail call noalias ptr @calloc(i64 noundef %9, i64 noundef 8) #3
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.6) #4
  unreachable

14:                                               ; preds = %8
  store i64 %.027, ptr %11, align 8, !tbaa !13
  br i1 %.not, label %21, label %.preheader

.preheader:                                       ; preds = %14
  %.0.in35 = getelementptr inbounds i8, ptr %5, i64 8
  %.036 = load ptr, ptr %.0.in35, align 8, !tbaa !14
  %.not3337 = icmp eq ptr %.036, null
  br i1 %.not3337, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.040 = phi ptr [ %.0, %.lr.ph ], [ %.036, %.preheader ]
  %.02439 = phi i64 [ %18, %.lr.ph ], [ 0, %.preheader ]
  %.02538 = phi i64 [ %16, %.lr.ph ], [ 1, %.preheader ]
  %15 = load i64, ptr %.040, align 8, !tbaa !15
  %16 = add i64 %.02538, 1
  %17 = getelementptr inbounds i64, ptr %11, i64 %.02538
  store i64 %15, ptr %17, align 8, !tbaa !13
  %18 = add i64 %.02439, 1
  %.0.in = getelementptr inbounds i8, ptr %.040, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !14
  %.not33 = icmp eq ptr %.0, null
  br i1 %.not33, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.024.lcssa = phi i64 [ 0, %.preheader ], [ %18, %.lr.ph ]
  %19 = load i64, ptr %5, align 8, !tbaa !10
  %.not34 = icmp eq i64 %.024.lcssa, %19
  br i1 %.not34, label %21, label %20

20:                                               ; preds = %._crit_edge
  tail call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef nonnull @.str.7) #4
  unreachable

21:                                               ; preds = %14, %._crit_edge, %2
  %storemerge = phi ptr [ null, %2 ], [ %11, %._crit_edge ], [ %11, %14 ]
  %.026 = phi i64 [ 0, %2 ], [ %10, %._crit_edge ], [ %10, %14 ]
  store ptr %storemerge, ptr %1, align 8, !tbaa !14
  ret i64 %.026
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 = { noreturn "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 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 allocsize(0,1) }
attributes #4 = { noreturn 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 0}
!6 = !{!"uint64_t_ll_bpt_leading_data", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"uint64_t_ll", !12, i64 0, !7, i64 8, !7, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"uint64_t_ll_node", !12, i64 0, !7, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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