; LLVM IR from jovanlanik/wip :: src (wip_mdl)

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

%struct.wip_ply_t = type { i32, i32, ptr, ptr, ptr, ptr, ptr }
%struct.wip_mdl_t = type { ptr, ptr, i32, i32 }
%struct.wip_vertex_t = type { %struct.anon, %struct.anon.1, %struct.anon.3, %struct.anon.5 }
%struct.anon = type { [3 x float], %struct.anon.0 }
%struct.anon.0 = type { float, float, float }
%struct.anon.1 = type { [3 x float], %struct.anon.2 }
%struct.anon.2 = type { float, float, float }
%struct.anon.3 = type { [2 x float], %struct.anon.4 }
%struct.anon.4 = type { float, float }
%struct.anon.5 = type { [4 x i8], %struct.anon.6 }
%struct.anon.6 = type { i8, i8, i8, i8 }

@__func__.wip_prepModel = external hidden unnamed_addr constant [14 x i8], align 1

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

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

declare ptr @_wip_alloc(i64 noundef, ptr 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

; Function Attrs: nounwind uwtable
define dso_local ptr @wip_prepModel(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.wip_ply_t, ptr %6, i32 0, i32 0
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.wip_mdl_t, ptr %9, i32 0, i32 2
  store i32 %8, ptr %10, align 8, !tbaa !12
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.wip_ply_t, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.wip_mdl_t, ptr %14, i32 0, i32 3
  store i32 %13, ptr %15, align 4, !tbaa !15
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.wip_ply_t, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = mul i64 %19, 72
  %21 = call ptr @_wip_alloc(i64 noundef %20, ptr noundef @__func__.wip_prepModel)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.wip_mdl_t, ptr %22, i32 0, i32 0
  store ptr %21, ptr %23, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !17
  br label %24

24:                                               ; preds = %96, %2
  %25 = load i32, ptr %5, align 4, !tbaa !17
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.wip_ply_t, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !9
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %99

31:                                               ; preds = %24
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.wip_mdl_t, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = load i32, ptr %5, align 4, !tbaa !17
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.wip_vertex_t, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct.wip_vertex_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [3 x float], ptr %39, i64 0, i64 0
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.wip_ply_t, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  %44 = load i32, ptr %5, align 4, !tbaa !17
  %45 = mul nsw i32 %44, 3
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %43, i64 %46
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %40, ptr align 4 %47, i64 12, i1 false)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.wip_mdl_t, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !16
  %51 = load i32, ptr %5, align 4, !tbaa !17
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.wip_vertex_t, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.wip_vertex_t, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.anon.1, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds [3 x float], ptr %55, i64 0, i64 0
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.wip_ply_t, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = load i32, ptr %5, align 4, !tbaa !17
  %61 = mul nsw i32 %60, 3
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %59, i64 %62
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %56, ptr align 4 %63, i64 12, i1 false)
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.wip_mdl_t, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load i32, ptr %5, align 4, !tbaa !17
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.wip_vertex_t, ptr %66, i64 %68
  %70 = getelementptr inbounds %struct.wip_vertex_t, ptr %69, i32 0, i32 2
  %71 = getelementptr inbounds %struct.anon.3, ptr %70, i32 0, i32 0
  %72 = getelementptr inbounds [2 x float], ptr %71, i64 0, i64 0
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.wip_ply_t, ptr %73, i32 0, i32 4
  %75 = load ptr, ptr %74, align 8, !tbaa !20
  %76 = load i32, ptr %5, align 4, !tbaa !17
  %77 = mul nsw i32 %76, 2
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds float, ptr %75, i64 %78
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %72, ptr align 4 %79, i64 8, i1 false)
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.wip_mdl_t, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !16
  %83 = load i32, ptr %5, align 4, !tbaa !17
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds %struct.wip_vertex_t, ptr %82, i64 %84
  %86 = getelementptr inbounds %struct.wip_vertex_t, ptr %85, i32 0, i32 3
  %87 = getelementptr inbounds %struct.anon.5, ptr %86, i32 0, i32 0
  %88 = getelementptr inbounds [4 x i8], ptr %87, i64 0, i64 0
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.wip_ply_t, ptr %89, i32 0, i32 5
  %91 = load ptr, ptr %90, align 8, !tbaa !21
  %92 = load i32, ptr %5, align 4, !tbaa !17
  %93 = mul nsw i32 %92, 4
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i8, ptr %91, i64 %94
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %88, ptr align 1 %95, i64 4, i1 false)
  br label %96

96:                                               ; preds = %31
  %97 = load i32, ptr %5, align 4, !tbaa !17
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %5, align 4, !tbaa !17
  br label %24, !llvm.loop !22

99:                                               ; preds = %30
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.wip_ply_t, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 4, !tbaa !14
  %103 = mul nsw i32 3, %102
  %104 = sext i32 %103 to i64
  %105 = mul i64 %104, 4
  %106 = call ptr @_wip_alloc(i64 noundef %105, ptr noundef @__func__.wip_prepModel)
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.wip_mdl_t, ptr %107, i32 0, i32 1
  store ptr %106, ptr %108, align 8, !tbaa !24
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.wip_mdl_t, ptr %109, i32 0, i32 1
  %111 = load ptr, ptr %110, align 8, !tbaa !24
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.wip_ply_t, ptr %112, i32 0, i32 6
  %114 = load ptr, ptr %113, align 8, !tbaa !25
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.wip_ply_t, ptr %115, i32 0, i32 1
  %117 = load i32, ptr %116, align 4, !tbaa !14
  %118 = mul nsw i32 3, %117
  %119 = sext i32 %118 to i64
  %120 = mul i64 %119, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %111, ptr align 4 %114, i64 %120, i1 false)
  %121 = load ptr, ptr %3, align 8, !tbaa !5
  ret ptr %121
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #4 = { nounwind }

!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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 16}
!13 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!14 = !{!10, !11, i64 4}
!15 = !{!13, !11, i64 20}
!16 = !{!13, !6, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !6, i64 8}
!19 = !{!10, !6, i64 16}
!20 = !{!10, !6, i64 24}
!21 = !{!10, !6, i64 32}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!13, !6, i64 8}
!25 = !{!10, !6, i64 40}


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

%struct.wip_vertex_t = type { %struct.anon, %struct.anon.1, %struct.anon.3, %struct.anon.5 }
%struct.anon = type { [3 x float], %struct.anon.0 }
%struct.anon.0 = type { float, float, float }
%struct.anon.1 = type { [3 x float], %struct.anon.2 }
%struct.anon.2 = type { float, float, float }
%struct.anon.3 = type { [2 x float], %struct.anon.4 }
%struct.anon.4 = type { float, float }
%struct.anon.5 = type { [4 x i8], %struct.anon.6 }
%struct.anon.6 = type { i8, i8, i8, i8 }

@__func__.wip_prepModel = external hidden unnamed_addr constant [14 x i8], align 1

declare ptr @_wip_alloc(i64 noundef, ptr 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: nounwind uwtable
define dso_local noundef ptr @wip_prepModel(ptr noundef returned %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load <2 x i32>, ptr %1, align 8, !tbaa !5
  store <2 x i32> %4, ptr %3, align 8, !tbaa !5
  %5 = extractelement <2 x i32> %4, i64 0
  %6 = sext i32 %5 to i64
  %7 = mul nsw i64 %6, 72
  %8 = tail call ptr @_wip_alloc(i64 noundef %7, ptr noundef nonnull @__func__.wip_prepModel) #3
  store ptr %8, ptr %0, align 8, !tbaa !9
  %9 = load i32, ptr %1, align 8, !tbaa !12
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  br label %28

._crit_edge:                                      ; preds = %28, %2
  %15 = getelementptr inbounds i8, ptr %1, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = mul nsw i32 %16, 3
  %18 = sext i32 %17 to i64
  %19 = shl nsw i64 %18, 2
  %20 = tail call ptr @_wip_alloc(i64 noundef %19, ptr noundef nonnull @__func__.wip_prepModel) #3
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %20, ptr %21, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %1, i64 40
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = load i32, ptr %15, align 4, !tbaa !14
  %25 = mul nsw i32 %24, 3
  %26 = sext i32 %25 to i64
  %27 = shl nsw i64 %26, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %23, i64 %27, i1 false)
  ret ptr %0

28:                                               ; preds = %.lr.ph, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %28 ]
  %29 = load ptr, ptr %0, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.wip_vertex_t, ptr %29, i64 %indvars.iv
  %31 = load ptr, ptr %11, align 8, !tbaa !17
  %32 = mul nuw nsw i64 %indvars.iv, 3
  %33 = getelementptr inbounds float, ptr %31, i64 %32
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %30, ptr noundef nonnull align 4 dereferenceable(12) %33, i64 12, i1 false)
  %34 = load ptr, ptr %0, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.wip_vertex_t, ptr %34, i64 %indvars.iv, i32 1
  %36 = load ptr, ptr %12, align 8, !tbaa !18
  %37 = getelementptr inbounds float, ptr %36, i64 %32
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %35, ptr noundef nonnull align 4 dereferenceable(12) %37, i64 12, i1 false)
  %38 = load ptr, ptr %0, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.wip_vertex_t, ptr %38, i64 %indvars.iv, i32 2
  %40 = load ptr, ptr %13, align 8, !tbaa !19
  %.idx = shl nsw i64 %indvars.iv, 3
  %41 = getelementptr inbounds i8, ptr %40, i64 %.idx
  %42 = load i64, ptr %41, align 4
  store i64 %42, ptr %39, align 4
  %43 = load ptr, ptr %0, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.wip_vertex_t, ptr %43, i64 %indvars.iv, i32 3
  %45 = load ptr, ptr %14, align 8, !tbaa !20
  %46 = shl nsw i64 %indvars.iv, 2
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i32, ptr %47, align 1
  store i32 %48, ptr %44, align 4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %49 = load i32, ptr %1, align 8, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = icmp slt i64 %indvars.iv.next, %50
  br i1 %51, label %28, label %._crit_edge, !llvm.loop !21
}

attributes #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 20}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!14 = !{!13, !6, i64 4}
!15 = !{!10, !11, i64 8}
!16 = !{!13, !11, i64 40}
!17 = !{!13, !11, i64 8}
!18 = !{!13, !11, i64 16}
!19 = !{!13, !11, i64 24}
!20 = !{!13, !11, i64 32}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass