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

; 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::Mesh" = type <{ ptr, ptr, ptr, ptr, i32, [4 x i8], ptr, i32, [4 x i8] }>

@_ZTVN3rmg4MeshE = external dso_local unnamed_addr constant { [4 x ptr] }, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) #0

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

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

declare void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52)) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg4MeshC2EPKNS_4Vec3ES3_PKNS_4Vec2Ej(ptr noundef nonnull align 8 dereferenceable(52) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) unnamed_addr #4 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load ptr, ptr %6, align 8
  store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTVN3rmg4MeshE, i32 0, i32 0, i32 2), ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 1
  store ptr null, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 2
  store ptr null, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 3
  store ptr null, ptr %14, align 8, !tbaa !16
  %15 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 4
  store i32 0, ptr %15, align 8, !tbaa !17
  %16 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 6
  store ptr null, ptr %16, align 8, !tbaa !18
  %17 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 7
  store i32 0, ptr %17, align 8, !tbaa !19
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = urem i32 %18, 3
  %20 = icmp eq i32 %19, 0
  call void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext %20, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 79)
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = urem i32 %21, 3
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %5
  br label %65

25:                                               ; preds = %5
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = mul i64 12, %27
  %29 = call noalias ptr @malloc(i64 noundef %28) #5
  %30 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 1
  store ptr %29, ptr %30, align 8, !tbaa !13
  %31 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = mul i64 12, %35
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %32, ptr align 4 %33, i64 %36, i1 false)
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = mul i64 12, %38
  %40 = call noalias ptr @malloc(i64 noundef %39) #5
  %41 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 2
  store ptr %40, ptr %41, align 8, !tbaa !15
  %42 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = mul i64 12, %46
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %43, ptr align 4 %44, i64 %47, i1 false)
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 4
  store i32 %48, ptr %49, align 8, !tbaa !17
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %64

52:                                               ; preds = %25
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = mul i64 8, %54
  %56 = call noalias ptr @malloc(i64 noundef %55) #5
  %57 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 3
  store ptr %56, ptr %57, align 8, !tbaa !16
  %58 = getelementptr inbounds %"class.rmg::Mesh", ptr %11, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = mul i64 8, %62
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %59, ptr align 4 %60, i64 %63, i1 false)
  br label %64

64:                                               ; preds = %52, %25
  call void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52) %11)
  br label %65

65:                                               ; preds = %64, %24
  ret void
}

attributes #0 = { inlinehint mustprogress 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { mustprogress 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTSN3rmg4MeshE", !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !10, i64 32}
!18 = !{!14, !6, i64 40}
!19 = !{!14, !10, i64 48}


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

@_ZTVN3rmg4MeshE = external dso_local unnamed_addr constant { [4 x ptr] }, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; 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

declare void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52)) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg4MeshC2EPKNS_4Vec3ES3_PKNS_4Vec2Ej(ptr noundef nonnull align 8 dereferenceable(52) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr noundef readonly %3, i32 noundef %4) unnamed_addr #4 align 2 {
  store ptr getelementptr inbounds inrange(-16, 16) (i8, ptr @_ZTVN3rmg4MeshE, i64 16), ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr null, ptr %8, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 0, ptr %9, align 8, !tbaa !13
  %10 = urem i32 %4, 3
  %11 = icmp eq i32 %10, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %6, i8 0, i64 28, i1 false)
  tail call void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext %11, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 79)
  br i1 %11, label %12, label %23

12:                                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = zext i32 %4 to i64
  %16 = mul nuw nsw i64 %15, 12
  %17 = tail call noalias ptr @malloc(i64 noundef %16) #6
  store ptr %17, ptr %6, align 8, !tbaa !14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %1, i64 %16, i1 false)
  %18 = tail call noalias ptr @malloc(i64 noundef %16) #6
  store ptr %18, ptr %14, align 8, !tbaa !15
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %2, i64 %16, i1 false)
  store i32 %4, ptr %13, align 8, !tbaa !16
  %.not13 = icmp eq ptr %3, null
  br i1 %.not13, label %22, label %19

19:                                               ; preds = %12
  %20 = shl nuw nsw i64 %15, 3
  %21 = tail call noalias ptr @malloc(i64 noundef %20) #6
  store ptr %21, ptr %7, align 8, !tbaa !17
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %21, ptr nonnull align 4 %3, i64 %20, i1 false)
  br label %22

22:                                               ; preds = %19, %12
  tail call void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52) %0)
  br label %23

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

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

attributes #0 = { inlinehint mustprogress 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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { mustprogress 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 40}
!9 = !{!"_ZTSN3rmg4MeshE", !10, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !10, i64 40, !12, i64 48}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"int", !11, i64 0}
!13 = !{!9, !12, i64 48}
!14 = !{!9, !10, i64 8}
!15 = !{!9, !10, i64 16}
!16 = !{!9, !12, i64 32}
!17 = !{!9, !10, i64 24}


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