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

; 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.wah_bpt_non_leading_data = type { ptr, ptr }

@WAH_SIZE = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @wah_non_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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  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 %119

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %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 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %36

23:                                               ; preds = %17
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds i32, ptr %26, i64 0
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = load i32, ptr @WAH_SIZE, align 4, !tbaa !9
  %30 = udiv i32 %29, 8
  %31 = mul i32 %28, %30
  %32 = zext i32 %31 to i64
  %33 = mul i64 %32, 1
  %34 = add i64 4, %33
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %23, %17
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %54

41:                                               ; preds = %36
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = getelementptr inbounds i32, ptr %44, i64 0
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = load i32, ptr @WAH_SIZE, align 4, !tbaa !9
  %48 = udiv i32 %47, 8
  %49 = mul i32 %46, %48
  %50 = zext i32 %49 to i64
  %51 = mul i64 %50, 1
  %52 = add i64 4, %51
  %53 = trunc i64 %52 to i32
  store i32 %53, ptr %8, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %41, %36
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = add i64 8, %56
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = add i64 %57, %59
  %61 = trunc i64 %60 to i32
  store i32 %61, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = call noalias ptr @malloc(i64 noundef %63) #6
  store ptr %64, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %65, ptr %11, align 8, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = getelementptr inbounds i32, ptr %67, i64 0
  store i32 %66, ptr %68, align 4, !tbaa !9
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = getelementptr inbounds i32, ptr %70, i64 1
  store i32 %69, ptr %71, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 8, ptr %12, align 4, !tbaa !9
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %86

76:                                               ; preds = %54
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load i32, ptr %12, align 4, !tbaa !9
  %79 = zext i32 %78 to i64
  %80 = getelementptr inbounds i8, ptr %77, i64 %79
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !11
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %80, ptr align 1 %83, i64 %85, i1 false)
  br label %86

86:                                               ; preds = %76, %54
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = load i32, ptr %12, align 4, !tbaa !9
  %89 = add i32 %88, %87
  store i32 %89, ptr %12, align 4, !tbaa !9
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %90, i32 0, i32 1
  %92 = load ptr, ptr %91, align 8, !tbaa !13
  %93 = icmp ne ptr %92, null
  br i1 %93, label %94, label %104

94:                                               ; preds = %86
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  %96 = load i32, ptr %12, align 4, !tbaa !9
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %95, i64 %97
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !13
  %102 = load i32, ptr %8, align 4, !tbaa !9
  %103 = zext i32 %102 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %98, ptr align 1 %101, i64 %103, i1 false)
  br label %104

104:                                              ; preds = %94, %86
  %105 = load i32, ptr %8, align 4, !tbaa !9
  %106 = load i32, ptr %12, align 4, !tbaa !9
  %107 = add i32 %106, %105
  store i32 %107, ptr %12, align 4, !tbaa !9
  %108 = load i32, ptr %12, align 4, !tbaa !9
  %109 = load i32, ptr %9, align 4, !tbaa !9
  %110 = icmp ne i32 %108, %109
  br i1 %110, label %111, label %114

111:                                              ; preds = %104
  %112 = load i32, ptr %9, align 4, !tbaa !9
  %113 = load i32, ptr %12, align 4, !tbaa !9
  call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef @.str, i32 noundef %112, i32 noundef %113) #7
  unreachable

114:                                              ; preds = %104
  %115 = load ptr, ptr %10, align 8, !tbaa !5
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %115, ptr %116, align 8, !tbaa !5
  %117 = load i32, ptr %9, align 4, !tbaa !9
  %118 = zext i32 %117 to i64
  store i64 %118, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %119

119:                                              ; preds = %114, %15
  %120 = load i64, ptr %3, align 8
  ret i64 %120
}

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"wah_bpt_non_leading_data", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}


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

@WAH_SIZE = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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: mustprogress nofree nounwind willreturn uwtable
define dso_local range(i64 0, 4294967296) i64 @wah_non_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 %35, label %4

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

6:                                                ; preds = %4
  %7 = load i32, ptr %5, align 4, !tbaa !10
  %8 = load i32, ptr @WAH_SIZE, align 4, !tbaa !10
  %9 = lshr i32 %8, 3
  %10 = mul i32 %9, %7
  %11 = add i32 %10, 4
  br label %12

12:                                               ; preds = %6, %4
  %.036 = phi i32 [ %11, %6 ], [ 0, %4 ]
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %.not45 = icmp eq ptr %14, null
  br i1 %.not45, label %21, label %15

15:                                               ; preds = %12
  %16 = load i32, ptr %14, align 4, !tbaa !10
  %17 = load i32, ptr @WAH_SIZE, align 4, !tbaa !10
  %18 = lshr i32 %17, 3
  %19 = mul i32 %18, %16
  %20 = add i32 %19, 4
  br label %21

21:                                               ; preds = %15, %12
  %.037 = phi i32 [ %20, %15 ], [ 0, %12 ]
  %22 = add i32 %.036, 8
  %23 = zext i32 %.037 to i64
  %24 = add i32 %.037, %22
  %25 = zext i32 %24 to i64
  %26 = tail call noalias ptr @malloc(i64 noundef %25) #3
  store i32 %.036, ptr %26, align 4, !tbaa !10
  %27 = getelementptr inbounds i8, ptr %26, i64 4
  store i32 %.037, ptr %27, align 4, !tbaa !10
  br i1 %.not, label %31, label %28

28:                                               ; preds = %21
  %29 = zext i32 %.036 to i64
  %30 = getelementptr inbounds i8, ptr %26, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %30, ptr nonnull align 1 %5, i64 %29, i1 false)
  br label %31

31:                                               ; preds = %28, %21
  br i1 %.not45, label %35, label %32

32:                                               ; preds = %31
  %33 = zext i32 %22 to i64
  %34 = getelementptr inbounds i8, ptr %26, i64 %33
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %34, ptr nonnull align 1 %14, i64 %23, i1 false)
  br label %35

35:                                               ; preds = %32, %31, %2
  %storemerge = phi ptr [ null, %2 ], [ %26, %31 ], [ %26, %32 ]
  %.0 = phi i64 [ 0, %2 ], [ %25, %31 ], [ %25, %32 ]
  store ptr %storemerge, ptr %1, align 8, !tbaa !13
  ret i64 %.0
}

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

!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 = !{!"wah_bpt_non_leading_data", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass