; LLVM IR from ponylang/ponyc :: src/libponyc/pkg (buildflagset)

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

@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@_user_flags = external hidden global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.remove_build_flags = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @flagtab_init(ptr noundef, i64 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

declare noalias ptr @ponyint_pool_alloc(i64 noundef) #2

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

declare ptr @stringtab(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @remove_build_flags(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.flag_t, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %11

10:                                               ; preds = %1
  call void @ponyint_assert_fail(ptr noundef @.str.11, ptr noundef @.str.1, i64 noundef 608, ptr noundef @__func__.remove_build_flags)
  br label %11

11:                                               ; preds = %10, %9
  %12 = load ptr, ptr @_user_flags, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  %15 = call noalias ptr @ponyint_pool_alloc(i64 noundef 0)
  store ptr %15, ptr @_user_flags, align 8, !tbaa !5
  %16 = load ptr, ptr @_user_flags, align 8, !tbaa !5
  call void @flagtab_init(ptr noundef %16, i64 noundef 8)
  br label %17

17:                                               ; preds = %14, %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %18, ptr %4, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %39, %17
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %42

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  %25 = getelementptr inbounds %struct.flag_t, ptr %5, i32 0, i32 0
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = call ptr @stringtab(ptr noundef %27)
  store ptr %28, ptr %25, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.flag_t, ptr %5, i32 0, i32 1
  store i8 0, ptr %29, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %30 = load ptr, ptr @_user_flags, align 8, !tbaa !5
  %31 = call ptr @flagtab_remove(ptr noundef %30, ptr noundef %5)
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %38

34:                                               ; preds = %24
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  call void @flag_free(ptr noundef %35)
  %36 = load i64, ptr %3, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %3, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %34, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds ptr, ptr %40, i64 1
  store ptr %41, ptr %4, align 8, !tbaa !5
  br label %19, !llvm.loop !15

42:                                               ; preds = %23
  %43 = load i64, ptr %3, align 8, !tbaa !9
  %44 = icmp ugt i64 %43, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i1 %44
}

; Function Attrs: nounwind uwtable
declare hidden void @flag_free(ptr noundef) #0

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 = { "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 }

!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, !6, i64 0}
!12 = !{!"flag_t", !6, i64 0, !13, i64 8}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !13, i64 8}
!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"

%struct.flag_t = type { ptr, i8 }

@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@_user_flags = external hidden local_unnamed_addr global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.remove_build_flags = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @flagtab_init(ptr noundef, i64 noundef) local_unnamed_addr #0

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

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

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

declare noalias ptr @ponyint_pool_alloc(i64 noundef) local_unnamed_addr #2

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare ptr @stringtab(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @remove_build_flags(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca %struct.flag_t, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %1
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.1, i64 noundef 608, ptr noundef nonnull @__func__.remove_build_flags) #3
  br label %4

4:                                                ; preds = %1, %3
  %5 = load ptr, ptr @_user_flags, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %4
  %8 = tail call noalias ptr @ponyint_pool_alloc(i64 noundef 0) #3
  store ptr %8, ptr @_user_flags, align 8, !tbaa !5
  tail call void @flagtab_init(ptr noundef %8, i64 noundef 8)
  br label %9

9:                                                ; preds = %7, %4
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %.not1012 = icmp eq ptr %10, null
  br i1 %.not1012, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  br label %13

._crit_edge.loopexit:                             ; preds = %20
  %12 = icmp ne i64 %.1, 0
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %9
  %.0.lcssa = phi i1 [ false, %9 ], [ %12, %._crit_edge.loopexit ]
  ret i1 %.0.lcssa

13:                                               ; preds = %.lr.ph, %20
  %14 = phi ptr [ %10, %.lr.ph ], [ %22, %20 ]
  %.014 = phi i64 [ 0, %.lr.ph ], [ %.1, %20 ]
  %.0813 = phi ptr [ %0, %.lr.ph ], [ %21, %20 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  %15 = call ptr @stringtab(ptr noundef nonnull %14) #3
  store ptr %15, ptr %2, align 8, !tbaa !9
  store i8 0, ptr %11, align 8, !tbaa !12
  %16 = load ptr, ptr @_user_flags, align 8, !tbaa !5
  %17 = call ptr @flagtab_remove(ptr noundef %16, ptr noundef nonnull %2)
  %.not11 = icmp eq ptr %17, null
  br i1 %.not11, label %20, label %18

18:                                               ; preds = %13
  call void @flag_free(ptr noundef nonnull %17)
  %19 = add i64 %.014, 1
  br label %20

20:                                               ; preds = %18, %13
  %.1 = phi i64 [ %19, %18 ], [ %.014, %13 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  %21 = getelementptr inbounds i8, ptr %.0813, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %.not10 = icmp eq ptr %22, null
  br i1 %.not10, label %._crit_edge.loopexit, label %13, !llvm.loop !13
}

; Function Attrs: nounwind uwtable
declare hidden void @flag_free(ptr noundef) local_unnamed_addr #0

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

!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 = !{!"flag_t", !6, i64 0, !11, i64 8}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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