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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

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

20:                                               ; preds = %5
  %21 = load i8, ptr %9, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = icmp sgt i32 %22, 4
  br i1 %23, label %24, label %25

24:                                               ; preds = %20, %5
  br label %48

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

48:                                               ; preds = %25, %24
  ret void
}

; 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) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

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

18:                                               ; preds = %5, %10
  ret void
}

; 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) #2

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 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass