; LLVM IR from aagdev/mlimgsynth :: src/ccommon (alloc_gen)

; 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.Allocator = type { ptr, ptr, ptr, ptr, i32 }
%struct.AllocGen = type { [10 x ptr], ptr }

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@__PRETTY_FUNCTION__.alloc_gen_ctx_free = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @alloc_gen_alloc(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #0

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 void @alloc_gen_ctx_free(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.Allocator, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp eq ptr %8, @alloc_gen_alloc
  br i1 %9, label %10, label %15

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.Allocator, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %10, %1
  br label %50

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Allocator, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  store ptr %19, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.AllocGen, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  store ptr %22, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  store ptr %24, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %32, %16
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %36

29:                                               ; preds = %25
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  call void @alloc_gen_seg_free(ptr noundef %30)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %29
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %33, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  store ptr %35, ptr %5, align 8, !tbaa !5
  br label %25, !llvm.loop !15

36:                                               ; preds = %28
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.AllocGen, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = icmp eq ptr %37, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  br label %44

43:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 386, ptr noundef @__PRETTY_FUNCTION__.alloc_gen_ctx_free) #5
  unreachable

44:                                               ; preds = %42
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.AllocGen, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  call void @alloc_gen_seg_free(ptr noundef %47)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Allocator, ptr %48, i32 0, i32 3
  store ptr null, ptr %49, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %50

50:                                               ; preds = %44, %15
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @alloc_gen_seg_free(ptr noundef) #3

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 = { noreturn 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 #3 = { inlinehint 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 = { 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, !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 = !{!"Allocator", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!14, !6, i64 80}
!14 = !{!"AllocGen", !7, i64 0, !6, i64 80}
!15 = distinct !{!15, !16}
!16 = !{!"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.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@__PRETTY_FUNCTION__.alloc_gen_ctx_free = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @alloc_gen_alloc(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @alloc_gen_ctx_free(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = icmp eq ptr %2, @alloc_gen_alloc
  br i1 %3, label %4, label %14

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %14, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %6, i64 80
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %.018 = load ptr, ptr %9, align 8, !tbaa !14
  %.not1719 = icmp eq ptr %.018, null
  br i1 %.not1719, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr %8, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %7
  %10 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %9, %7 ]
  %11 = icmp eq ptr %6, %10
  br i1 %11, label %13, label %12

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.020 = phi ptr [ %.0, %.lr.ph ], [ %.018, %7 ]
  tail call void @alloc_gen_seg_free(ptr noundef nonnull %.020)
  %.0 = load ptr, ptr %9, align 8, !tbaa !14
  %.not17 = icmp eq ptr %.0, null
  br i1 %.not17, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15

12:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 386, ptr noundef nonnull @__PRETTY_FUNCTION__.alloc_gen_ctx_free) #3
  unreachable

13:                                               ; preds = %._crit_edge
  tail call void @alloc_gen_seg_free(ptr noundef %10)
  store ptr null, ptr %5, align 8, !tbaa !11
  br label %14

14:                                               ; preds = %1, %4, %13
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @alloc_gen_seg_free(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 = { noreturn 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 = { inlinehint 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 = { 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 = !{!"Allocator", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!13, !7, i64 80}
!13 = !{!"AllocGen", !8, i64 0, !7, i64 80}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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