; LLVM IR from Zhuagenborn/Tiny-x86-OS :: src/kernel/util/bitmap.ll (ZN6Bitmap3SetEjj)

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

%"class.stl::source_location" = type { ptr, ptr, i32, i32 }
%"class.stl::string_view" = type <{ ptr, i32, [4 x i8] }>
%class.Bitmap = type { i32, ptr }

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind
declare void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext, ptr, i32, ptr noundef nonnull align 8 dereferenceable(24)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind noalias writable sret(%"class.stl::source_location") align 8, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN6Bitmap3SetEjj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"class.stl::string_view", align 8
  %8 = alloca %"class.stl::source_location", align 8
  %9 = alloca %"class.stl::string_view", align 8
  %10 = alloca %"class.stl::source_location", align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8
  %13 = getelementptr inbounds %class.Bitmap, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %7, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind writable sret(%"class.stl::source_location") align 8 %8, ptr noundef @.str, ptr noundef @.str.3, i32 noundef 63, i32 noundef 0) #3
  %16 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8
  %18 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 1
  %19 = load i32, ptr %18, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %15, ptr %17, i32 %19, ptr noundef nonnull align 8 dereferenceable(24) %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp ugt i32 %20, 0
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %9, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind writable sret(%"class.stl::source_location") align 8 %10, ptr noundef @.str, ptr noundef @.str.3, i32 noundef 64, i32 noundef 0) #3
  %22 = getelementptr inbounds { ptr, i32 }, ptr %9, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8
  %24 = getelementptr inbounds { ptr, i32 }, ptr %9, i32 0, i32 1
  %25 = load i32, ptr %24, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %21, ptr %23, i32 %25, ptr noundef nonnull align 8 dereferenceable(24) %10) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %36, %3
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp ne i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %39

31:                                               ; preds = %26
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = add i32 %32, %33
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN6Bitmap6SetBitEjb(ptr noundef nonnull align 8 dereferenceable(16) %12, i32 noundef %34, i1 noundef zeroext true) #3
  br label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = add i32 %37, 1
  store i32 %38, ptr %11, align 4, !tbaa !9
  br label %26, !llvm.loop !13

39:                                               ; preds = %30
  ret ptr %12
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN6Bitmap6SetBitEjb(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i1 noundef zeroext) #1 align 2

attributes #0 = { 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 #1 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS6Bitmap", !10, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"class.stl::source_location" = type { ptr, ptr, i32, i32 }
%"class.stl::string_view" = type <{ ptr, i32, [4 x i8] }>

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind
declare void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext, ptr, i32, ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind noalias writable sret(%"class.stl::source_location") align 8, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN6Bitmap3SetEjj(ptr noundef nonnull returned align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca %"class.stl::string_view", align 8
  %5 = alloca %"class.stl::source_location", align 8
  %6 = alloca %"class.stl::string_view", align 8
  %7 = alloca %"class.stl::source_location", align 8
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %4, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind nonnull writable sret(%"class.stl::source_location") align 8 %5, ptr noundef nonnull @.str, ptr noundef nonnull @.str.3, i32 noundef 63, i32 noundef 0) #3
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds i8, ptr %4, i64 8
  %13 = load i32, ptr %12, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %10, ptr %11, i32 %13, ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  %14 = icmp ne i32 %2, 0
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %6, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind nonnull writable sret(%"class.stl::source_location") align 8 %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.3, i32 noundef 64, i32 noundef 0) #3
  %15 = load ptr, ptr %6, align 8
  %16 = getelementptr inbounds i8, ptr %6, i64 8
  %17 = load i32, ptr %16, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %14, ptr %15, i32 %17, ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  %.not6 = icmp eq i32 %2, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret ptr %0

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.07 = phi i32 [ %20, %.lr.ph ], [ 0, %3 ]
  %18 = add i32 %.07, %1
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN6Bitmap6SetBitEjb(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %18, i1 noundef zeroext true) #3
  %20 = add nuw i32 %.07, 1
  %.not = icmp eq i32 %20, %2
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN6Bitmap6SetBitEjb(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i1 noundef zeroext) local_unnamed_addr #1 align 2

attributes #0 = { 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 #1 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 8}
!6 = !{!"_ZTS6Bitmap", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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