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

; 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.1 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 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 @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52), i1 noundef zeroext) #3

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

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

28:                                               ; preds = %7
  br label %86

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

58:                                               ; preds = %29
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = mul i64 8, %60
  %62 = call noalias ptr @malloc(i64 noundef %61) #5
  %63 = getelementptr inbounds %"class.rmg::Mesh", ptr %15, i32 0, i32 3
  store ptr %62, ptr %63, align 8, !tbaa !16
  %64 = getelementptr inbounds %"class.rmg::Mesh", ptr %15, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !16
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  %69 = mul i64 8, %68
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %65, ptr align 4 %66, i64 %69, i1 false)
  br label %70

70:                                               ; preds = %58, %29
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %85

73:                                               ; preds = %70
  %74 = load i32, ptr %12, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = mul i64 12, %75
  %77 = call noalias ptr @malloc(i64 noundef %76) #5
  %78 = getelementptr inbounds %"class.rmg::Mesh", ptr %15, i32 0, i32 2
  store ptr %77, ptr %78, align 8, !tbaa !15
  %79 = getelementptr inbounds %"class.rmg::Mesh", ptr %15, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !15
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load i32, ptr %12, align 4, !tbaa !9
  %83 = zext i32 %82 to i64
  %84 = mul i64 12, %83
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %80, ptr align 4 %81, i64 %84, i1 false)
  br label %86

85:                                               ; preds = %70
  call void @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52) %15, i1 noundef zeroext true)
  call void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52) %15)
  br label %86

86:                                               ; preds = %85, %73, %28
  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.1 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 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 @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52), i1 noundef zeroext) local_unnamed_addr #3

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_4Vec2EjPKjj(ptr noundef nonnull align 8 dereferenceable(52) %0, ptr nocapture noundef readonly %1, ptr noundef readonly %2, ptr noundef readonly %3, i32 noundef %4, ptr nocapture noundef readonly %5, i32 noundef %6) unnamed_addr #4 align 2 {
  store ptr getelementptr inbounds inrange(-16, 16) (i8, ptr @_ZTVN3rmg4MeshE, i64 16), ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr null, ptr %11, align 8, !tbaa !8
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 0, ptr %12, align 8, !tbaa !13
  %13 = urem i32 %6, 3
  %14 = icmp eq i32 %13, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %8, i8 0, i64 28, i1 false)
  tail call void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext %14, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 111)
  br i1 %14, label %15, label %30

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

23:                                               ; preds = %15
  %24 = shl nuw nsw i64 %17, 3
  %25 = tail call noalias ptr @malloc(i64 noundef %24) #6
  store ptr %25, ptr %10, align 8, !tbaa !16
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr nonnull align 4 %3, i64 %24, i1 false)
  br label %26

26:                                               ; preds = %23, %15
  %.not20 = icmp eq ptr %2, null
  br i1 %.not20, label %29, label %27

27:                                               ; preds = %26
  %28 = tail call noalias ptr @malloc(i64 noundef %18) #6
  store ptr %28, ptr %9, align 8, !tbaa !17
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %28, ptr nonnull align 4 %2, i64 %18, i1 false)
  br label %30

29:                                               ; preds = %26
  tail call void @_ZN3rmg4Mesh12buildNormalsEb(ptr noundef nonnull align 8 dereferenceable(52) %0, i1 noundef zeroext true)
  tail call void @_ZN3rmg4Mesh12buildIndicesEv(ptr noundef nonnull align 8 dereferenceable(52) %0)
  br label %30

30:                                               ; preds = %7, %29, %27
  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, !12, i64 32}
!16 = !{!9, !10, i64 24}
!17 = !{!9, !10, i64 16}


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