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

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

26:                                               ; preds = %2
  %27 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 0
  %28 = load i16, ptr %27, align 8, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 1
  %31 = load i16, ptr %30, align 2, !tbaa !12
  %32 = zext i16 %31 to i32
  %33 = mul nsw i32 %29, %32
  %34 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 2
  %35 = load i8, ptr %34, align 4, !tbaa !13
  %36 = zext i8 %35 to i32
  %37 = mul nsw i32 %33, %36
  %38 = sext i32 %37 to i64
  %39 = call noalias ptr @malloc(i64 noundef %38) #3
  %40 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 3
  store ptr %39, ptr %40, align 8, !tbaa !14
  %41 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.rmg::Bitmap", ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 0
  %47 = load i16, ptr %46, align 8, !tbaa !9
  %48 = zext i16 %47 to i32
  %49 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 1
  %50 = load i16, ptr %49, align 2, !tbaa !12
  %51 = zext i16 %50 to i32
  %52 = mul nsw i32 %48, %51
  %53 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 2
  %54 = load i8, ptr %53, align 4, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = mul nsw i32 %52, %55
  %57 = sext i32 %56 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %42, ptr align 1 %45, i64 %57, i1 false)
  br label %60

58:                                               ; preds = %2
  %59 = getelementptr inbounds %"class.rmg::Bitmap", ptr %5, i32 0, i32 3
  store ptr null, ptr %59, align 8, !tbaa !14
  br label %60

60:                                               ; preds = %58, %26
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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, !11, i64 0}
!10 = !{!"_ZTSN3rmg6BitmapE", !11, i64 0, !11, i64 2, !7, i64 4, !6, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 2}
!13 = !{!10, !7, i64 4}
!14 = !{!10, !6, i64 8}


; 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local void @_ZN3rmg6BitmapC2ERKS0_(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1) unnamed_addr #2 align 2 {
  store i16 0, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 0, ptr %3, align 2, !tbaa !11
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  store i8 0, ptr %4, align 4, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %5, align 8, !tbaa !13
  %6 = load i16, ptr %1, align 8, !tbaa !5
  store i16 %6, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 2
  %8 = load i16, ptr %7, align 2, !tbaa !11
  store i16 %8, ptr %3, align 2, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %1, i64 4
  %10 = load i8, ptr %9, align 4, !tbaa !12
  store i8 %10, ptr %4, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %22, label %13

13:                                               ; preds = %2
  %14 = zext i16 %6 to i64
  %15 = zext i16 %8 to i64
  %16 = mul nuw nsw i64 %15, %14
  %17 = zext i8 %10 to i64
  %18 = mul nuw nsw i64 %16, %17
  %19 = and i64 %18, 4294967295
  %20 = tail call noalias ptr @malloc(i64 noundef %19) #3
  store ptr %20, ptr %5, align 8, !tbaa !13
  %21 = load ptr, ptr %11, align 8, !tbaa !13
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %20, ptr align 1 %21, i64 %19, i1 false)
  br label %22

22:                                               ; preds = %2, %13
  ret void
}

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