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

@.str.1 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [71 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 uwtable
declare dso_local ptr @wah_copy(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @wah_non_leading_deserialize(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %16, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %13, %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %17, align 8, !tbaa !5
  store i64 0, ptr %4, align 8
  br label %73

18:                                               ; preds = %13
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ult i64 %19, 8
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef @.str.1) #4
  unreachable

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i64 0
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds i32, ptr %27, i64 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = add i32 %26, %29
  %31 = zext i32 %30 to i64
  %32 = mul i64 %31, 1
  %33 = add i64 8, %32
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = icmp ne i64 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %22
  call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef @.str.2) #4
  unreachable

37:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %38 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 16) #6
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %39, i32 0, i32 0
  store ptr null, ptr %40, align 8, !tbaa !13
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %41, i32 0, i32 1
  store ptr null, ptr %42, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds i32, ptr %43, i64 2
  store ptr %44, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds i32, ptr %45, i64 0
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = icmp ugt i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %37
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = call ptr @wah_copy(ptr noundef %50)
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %52, i32 0, i32 0
  store ptr %51, ptr %53, align 8, !tbaa !13
  br label %54

54:                                               ; preds = %49, %37
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds i32, ptr %56, i64 0
  %58 = load i32, ptr %57, align 4, !tbaa !11
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %55, i64 %59
  store ptr %60, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds i32, ptr %61, i64 1
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = icmp ugt i32 %63, 0
  br i1 %64, label %65, label %70

65:                                               ; preds = %54
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = call ptr @wah_copy(ptr noundef %66)
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.wah_bpt_non_leading_data, ptr %68, i32 0, i32 1
  store ptr %67, ptr %69, align 8, !tbaa !15
  br label %70

70:                                               ; preds = %65, %54
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %71, ptr %72, align 8, !tbaa !5
  store i64 16, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %73

73:                                               ; preds = %70, %16
  %74 = load i64, ptr %4, align 8
  ret i64 %74
}

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

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,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 #3 = { 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 #4 = { noreturn }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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 = !{!14, !6, i64 0}
!14 = !{!"wah_bpt_non_leading_data", !6, i64 0, !6, i64 8}
!15 = !{!14, !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"

@.str.1 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @wah_copy(ptr noundef) local_unnamed_addr #0

; 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 #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 17) i64 @wah_non_leading_deserialize(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %1, 0
  %5 = icmp eq ptr %0, null
  %or.cond = or i1 %5, %4
  br i1 %or.cond, label %30, label %6

6:                                                ; preds = %3
  %7 = icmp ult i64 %1, 8
  br i1 %7, label %8, label %9

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

9:                                                ; preds = %6
  %10 = load i32, ptr %0, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = add i32 %12, %10
  %14 = zext i32 %13 to i64
  %15 = add nuw nsw i64 %14, 8
  %.not = icmp eq i64 %15, %1
  br i1 %.not, label %17, label %16

16:                                               ; preds = %9
  tail call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef nonnull @.str.2) #3
  unreachable

17:                                               ; preds = %9
  %18 = tail call noalias dereferenceable_or_null(16) ptr @calloc(i64 noundef 1, i64 noundef 16) #4
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %.not24 = icmp eq i32 %10, 0
  br i1 %.not24, label %23, label %21

21:                                               ; preds = %17
  %22 = tail call ptr @wah_copy(ptr noundef nonnull %20)
  store ptr %22, ptr %18, align 8, !tbaa !9
  %.pre = load i32, ptr %11, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %21, %17
  %24 = phi i32 [ %.pre, %21 ], [ %12, %17 ]
  %.not25 = icmp eq i32 %24, 0
  br i1 %.not25, label %30, label %25

25:                                               ; preds = %23
  %26 = load i32, ptr %0, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %20, i64 %27
  %29 = tail call ptr @wah_copy(ptr noundef nonnull %28)
  store ptr %29, ptr %19, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %23, %25, %3
  %storemerge = phi ptr [ null, %3 ], [ %18, %25 ], [ %18, %23 ]
  %.0 = phi i64 [ 0, %3 ], [ 16, %25 ], [ 16, %23 ]
  store ptr %storemerge, ptr %2, align 8, !tbaa !13
  ret i64 %.0
}

; Function Attrs: noreturn
declare void @errx(i32 noundef, ptr 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 = { 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 #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 = { noreturn nounwind }
attributes #4 = { nounwind allocsize(0,1) }

!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 = !{!10, !11, i64 0}
!10 = !{!"wah_bpt_non_leading_data", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}


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