; LLVM IR from achilles288/robot-monitor-graphics :: src/base/bitmap.ll (ZN3rmg6BitmapC2Etth)

; 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.rmg::Bitmap" = type { i16, i16, i8, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3rmg6BitmapC2Etth(ptr noundef nonnull align 8 dereferenceable(16) %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store i16 %2, ptr %7, align 2, !tbaa !9
  store i8 %3, ptr %8, align 1, !tbaa !11
  %10 = load ptr, ptr %5, align 8
  %11 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 0
  store i16 0, ptr %11, align 8, !tbaa !12
  %12 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 1
  store i16 0, ptr %12, align 2, !tbaa !14
  %13 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 2
  store i8 0, ptr %13, align 4, !tbaa !15
  %14 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 3
  store ptr null, ptr %14, align 8, !tbaa !16
  %15 = load i8, ptr %8, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = icmp slt i32 %16, 1
  br i1 %17, label %22, label %18

18:                                               ; preds = %4
  %19 = load i8, ptr %8, align 1, !tbaa !11
  %20 = zext i8 %19 to i32
  %21 = icmp sgt i32 %20, 4
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %4
  br label %45

23:                                               ; preds = %18
  %24 = load i16, ptr %6, align 2, !tbaa !9
  %25 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 0
  store i16 %24, ptr %25, align 8, !tbaa !12
  %26 = load i16, ptr %7, align 2, !tbaa !9
  %27 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 1
  store i16 %26, ptr %27, align 2, !tbaa !14
  %28 = load i8, ptr %8, align 1, !tbaa !11
  %29 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 2
  store i8 %28, ptr %29, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %30 = load i16, ptr %6, align 2, !tbaa !9
  %31 = zext i16 %30 to i32
  %32 = load i16, ptr %7, align 2, !tbaa !9
  %33 = zext i16 %32 to i32
  %34 = mul nsw i32 %31, %33
  %35 = load i8, ptr %8, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = mul nsw i32 %34, %36
  %38 = sext i32 %37 to i64
  store i64 %38, ptr %9, align 8, !tbaa !17
  %39 = load i64, ptr %9, align 8, !tbaa !17
  %40 = call noalias ptr @malloc(i64 noundef %39) #5
  %41 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 3
  store ptr %40, ptr %41, align 8, !tbaa !16
  %42 = getelementptr inbounds %"class.rmg::Bitmap", ptr %10, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = load i64, ptr %9, align 8, !tbaa !17
  call void @llvm.memset.p0.i64(ptr align 1 %43, i8 0, i64 %44, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %45

45:                                               ; preds = %23, %22
  ret void
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTSN3rmg6BitmapE", !10, i64 0, !10, i64 2, !7, i64 4, !6, i64 8}
!14 = !{!13, !10, i64 2}
!15 = !{!13, !7, i64 4}
!16 = !{!13, !6, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}


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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: write, inaccessiblemem: readwrite) uwtable
define dso_local void @_ZN3rmg6BitmapC2Etth(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(16) %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3) unnamed_addr #0 align 2 {
  store i16 0, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 0, ptr %5, align 2, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  store i8 0, ptr %6, align 4, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %7, align 8, !tbaa !13
  %8 = add i8 %3, -5
  %or.cond = icmp ult i8 %8, -4
  br i1 %or.cond, label %16, label %9

9:                                                ; preds = %4
  %10 = zext nneg i8 %3 to i64
  store i16 %1, ptr %0, align 8, !tbaa !5
  store i16 %2, ptr %5, align 2, !tbaa !11
  store i8 %3, ptr %6, align 4, !tbaa !12
  %11 = zext i16 %1 to i64
  %12 = zext i16 %2 to i64
  %13 = mul nuw nsw i64 %12, %11
  %14 = mul nuw nsw i64 %13, %10
  %15 = and i64 %14, 4294967295
  %calloc = tail call ptr @calloc(i64 1, i64 %15)
  store ptr %calloc, ptr %7, align 8, !tbaa !13
  br label %16

16:                                               ; preds = %4, %9
  ret void
}

; Function Attrs: 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

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: write, inaccessiblemem: readwrite) 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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }

!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 = !{!"_ZTSN3rmg6BitmapE", !7, i64 0, !7, i64 2, !8, i64 4, !10, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 2}
!12 = !{!6, !8, i64 4}
!13 = !{!6, !10, i64 8}


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