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

; 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: mustprogress uwtable
define dso_local void @_ZN3rmg4MeshC2EPKNS_4Vec3EPKNS_4Vec2Ejb(ptr noundef nonnull align 8 dereferenceable(52) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i1 noundef zeroext %4) unnamed_addr #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  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 i32 %3, ptr %9, align 4, !tbaa !9
  %11 = zext i1 %4 to i8
  store i8 %11, ptr %10, align 1, !tbaa !11
  %12 = 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 %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 1
  store ptr null, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 2
  store ptr null, ptr %14, align 8, !tbaa !17
  %15 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 3
  store ptr null, ptr %15, align 8, !tbaa !18
  %16 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 4
  store i32 0, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 6
  store ptr null, ptr %17, align 8, !tbaa !20
  %18 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 7
  store i32 0, ptr %18, align 8, !tbaa !21
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = urem i32 %19, 3
  %21 = icmp eq i32 %20, 0
  call void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext %21, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 45)
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = urem i32 %22, 3
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %5
  br label %61

26:                                               ; preds = %5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = mul i64 12, %28
  %30 = call noalias ptr @malloc(i64 noundef %29) #5
  %31 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 1
  store ptr %30, ptr %31, align 8, !tbaa !15
  %32 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = mul i64 12, %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %33, ptr align 4 %34, i64 %37, i1 false)
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 4
  store i32 %38, ptr %39, align 8, !tbaa !19
  %40 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 6
  store ptr null, ptr %40, align 8, !tbaa !20
  %41 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 7
  store i32 0, ptr %41, align 8, !tbaa !21
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %56

44:                                               ; preds = %26
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = mul i64 8, %46
  %48 = call noalias ptr @malloc(i64 noundef %47) #5
  %49 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 3
  store ptr %48, ptr %49, align 8, !tbaa !18
  %50 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = mul i64 8, %54
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %51, ptr align 4 %52, i64 %55, i1 false)
  br label %58

56:                                               ; preds = %26
  %57 = getelementptr inbounds %"class.rmg::Mesh", ptr %12, i32 0, i32 3
  store ptr null, ptr %57, align 8, !tbaa !18
  br label %58

58:                                               ; preds = %56, %44
  %59 = load i8, ptr %10, align 1, !tbaa !11, !range !22, !noundef !23
  %60 = trunc i8 %59 to i1
  call void @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52) %12, i1 noundef zeroext %60)
  call void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52) %12)
  br label %61

61:                                               ; preds = %58, %25
  ret void
}

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

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

; 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

declare void @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52), i1 noundef zeroext) #4

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

attributes #0 = { 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 = { 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 #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: readwrite) }
attributes #4 = { "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 = !{!"bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"_ZTSN3rmg4MeshE", !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48}
!17 = !{!16, !6, i64 16}
!18 = !{!16, !6, i64 24}
!19 = !{!16, !10, i64 32}
!20 = !{!16, !6, i64 40}
!21 = !{!16, !10, i64 48}
!22 = !{i8 0, i8 2}
!23 = !{}


; 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: mustprogress uwtable
define dso_local void @_ZN3rmg4MeshC2EPKNS_4Vec3EPKNS_4Vec2Ejb(ptr noundef nonnull align 8 dereferenceable(52) %0, ptr nocapture noundef readonly %1, ptr noundef readonly %2, i32 noundef %3, i1 noundef zeroext %4) unnamed_addr #0 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 %3, 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 45)
  br i1 %11, label %12, label %22

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

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

20:                                               ; preds = %12
  store ptr null, ptr %7, align 8, !tbaa !16
  br label %21

21:                                               ; preds = %20, %17
  tail call void @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52) %0, i1 noundef zeroext %4)
  tail call void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52) %0)
  br label %22

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

; 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 #1

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

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

declare void @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52), i1 noundef zeroext) local_unnamed_addr #4

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

; 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 = { 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 = { 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 #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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, !12, i64 32}
!16 = !{!9, !10, i64 24}


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