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

; 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.5 = external hidden unnamed_addr constant [7 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 @_ZN6Bitmap6SetBitEjb(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i1 noundef zeroext %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca %"class.stl::string_view", align 8
  %8 = alloca %"class.stl::source_location", align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %"class.stl::string_view", align 8
  %12 = alloca %"class.stl::source_location", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %13 = zext i1 %2 to i8
  store i8 %13, ptr %6, align 1, !tbaa !11
  %14 = load ptr, ptr %4, align 8
  %15 = getelementptr inbounds %class.Bitmap, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp ne ptr %16, 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.5, i32 noundef 83, i32 noundef 0) #3
  %18 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8
  %20 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 1
  %21 = load i32, ptr %20, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %17, ptr %19, i32 %21, ptr noundef nonnull align 8 dereferenceable(24) %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = udiv i32 %22, 8
  store i32 %23, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = urem i32 %24, 8
  store i32 %25, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = getelementptr inbounds %class.Bitmap, ptr %14, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = icmp ult i32 %26, %28
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %11, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind writable sret(%"class.stl::source_location") align 8 %12, ptr noundef @.str, ptr noundef @.str.5, i32 noundef 86, i32 noundef 0) #3
  %30 = getelementptr inbounds { ptr, i32 }, ptr %11, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8
  %32 = getelementptr inbounds { ptr, i32 }, ptr %11, i32 0, i32 1
  %33 = load i32, ptr %32, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %29, ptr %31, i32 %33, ptr noundef nonnull align 8 dereferenceable(24) %12) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #3
  %34 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %43

36:                                               ; preds = %3
  %37 = getelementptr inbounds %class.Bitmap, ptr %14, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZN3bit6SetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1) %41, i32 noundef %42) #3
  br label %50

43:                                               ; preds = %3
  %44 = getelementptr inbounds %class.Bitmap, ptr %14, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZN3bit8ResetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1) %48, i32 noundef %49) #3
  br label %50

50:                                               ; preds = %43, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret ptr %14
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3bit6SetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1), i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3bit8ResetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1), i32 noundef) #1

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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTS6Bitmap", !10, i64 0, !6, i64 8}
!15 = !{!14, !10, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}


; 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.5 = external hidden unnamed_addr constant [7 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 @_ZN6Bitmap6SetBitEjb(ptr noundef nonnull readonly returned align 8 dereferenceable(16) %0, i32 noundef %1, i1 noundef zeroext %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.5, i32 noundef 83, 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 = lshr i32 %1, 3
  %15 = and i32 %1, 7
  %16 = load i32, ptr %0, align 8, !tbaa !11
  %17 = icmp ult i32 %14, %16
  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.5, i32 noundef 86, i32 noundef 0) #3
  %18 = load ptr, ptr %6, align 8
  %19 = getelementptr inbounds i8, ptr %6, i64 8
  %20 = load i32, ptr %19, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %17, ptr %18, i32 %20, ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = zext nneg i32 %14 to i64
  %23 = getelementptr inbounds i8, ptr %21, i64 %22
  br i1 %2, label %24, label %25

24:                                               ; preds = %3
  call void @_ZN3bit6SetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1) %23, i32 noundef %15) #3
  br label %26

25:                                               ; preds = %3
  call void @_ZN3bit8ResetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1) %23, i32 noundef %15) #3
  br label %26

26:                                               ; preds = %25, %24
  ret ptr %0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3bit6SetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3bit8ResetBitIhEEvRT_j(ptr noundef nonnull align 1 dereferenceable(1), i32 noundef) local_unnamed_addr #1

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 = !{!6, !7, i64 0}


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