; 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.msh_ply_file = type { i32, i32, i32, ptr, ptr, ptr, i32, i32, i32 }
%struct.msh_ply_array_header = type { i64, i64 }

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @msh_ply_add_descriptor(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  store i32 4, ptr %3, align 4
  br label %87

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call i32 @msh_ply__validate_descriptor(ptr noundef %12)
  store i32 %13, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %11
  %17 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %17, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

18:                                               ; preds = %11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.msh_ply_file, ptr %19, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %30

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.msh_ply_file, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %26, i64 -16
  %28 = getelementptr inbounds %struct.msh_ply_array_header, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !13
  br label %31

30:                                               ; preds = %18
  br label %31

31:                                               ; preds = %30, %23
  %32 = phi i64 [ %29, %23 ], [ 0, %30 ]
  %33 = add i64 1, %32
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.msh_ply_file, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %45

38:                                               ; preds = %31
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.msh_ply_file, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds i8, ptr %41, i64 -16
  %43 = getelementptr inbounds %struct.msh_ply_array_header, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !16
  br label %46

45:                                               ; preds = %31
  br label %46

46:                                               ; preds = %45, %38
  %47 = phi i64 [ %44, %38 ], [ 0, %45 ]
  %48 = icmp ule i64 %33, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %46
  br label %72

50:                                               ; preds = %46
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.msh_ply_file, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.msh_ply_file, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %65

58:                                               ; preds = %50
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.msh_ply_file, ptr %59, i32 0, i32 4
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds i8, ptr %61, i64 -16
  %63 = getelementptr inbounds %struct.msh_ply_array_header, ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 8, !tbaa !13
  br label %66

65:                                               ; preds = %50
  br label %66

66:                                               ; preds = %65, %58
  %67 = phi i64 [ %64, %58 ], [ 0, %65 ]
  %68 = add i64 1, %67
  %69 = call ptr @msh_ply__array_grow(ptr noundef %53, i64 noundef %68, i64 noundef 8)
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.msh_ply_file, ptr %70, i32 0, i32 4
  store ptr %69, ptr %71, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %66, %49
  %73 = phi ptr [ null, %49 ], [ %69, %66 ]
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.msh_ply_file, ptr %75, i32 0, i32 4
  %77 = load ptr, ptr %76, align 8, !tbaa !11
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.msh_ply_file, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = getelementptr inbounds i8, ptr %80, i64 -16
  %82 = getelementptr inbounds %struct.msh_ply_array_header, ptr %81, i32 0, i32 0
  %83 = load i64, ptr %82, align 8, !tbaa !13
  %84 = add i64 %83, 1
  store i64 %84, ptr %82, align 8, !tbaa !13
  %85 = getelementptr inbounds ptr, ptr %77, i64 %83
  store ptr %74, ptr %85, align 8, !tbaa !5
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

86:                                               ; preds = %72, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %87

87:                                               ; preds = %86, %10
  %88 = load i32, ptr %3, align 4
  ret i32 %88
}

; Function Attrs: nounwind uwtable
declare hidden i32 @msh_ply__validate_descriptor(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @msh_ply__array_grow(ptr noundef, i64 noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"msh_ply_file", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48}
!13 = !{!14, !15, i64 0}
!14 = !{!"msh_ply_array_header", !15, i64 0, !15, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 8}


; 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: nounwind uwtable
define dso_local i32 @msh_ply_add_descriptor(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %21, label %3

3:                                                ; preds = %2
  %4 = tail call i32 @msh_ply__validate_descriptor(ptr noundef %1)
  %.not20 = icmp eq i32 %4, 0
  br i1 %.not20, label %5, label %21

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not21 = icmp eq ptr %7, null
  br i1 %.not21, label %.thread27, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %7, i64 -16
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = add i64 %10, 1
  %12 = getelementptr inbounds i8, ptr %7, i64 -8
  %13 = load i64, ptr %12, align 8, !tbaa !14
  %.not23 = icmp ugt i64 %11, %13
  br i1 %.not23, label %.thread27, label %16

.thread27:                                        ; preds = %8, %5
  %14 = phi i64 [ 1, %5 ], [ %11, %8 ]
  %15 = tail call ptr @msh_ply__array_grow(ptr noundef %7, i64 noundef %14, i64 noundef 8)
  store ptr %15, ptr %6, align 8, !tbaa !15
  %.phi.trans.insert = getelementptr inbounds i8, ptr %15, i64 -16
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !11
  %.pre28 = add i64 %.pre, 1
  br label %16

16:                                               ; preds = %8, %.thread27
  %.pre-phi = phi i64 [ %11, %8 ], [ %.pre28, %.thread27 ]
  %17 = phi i64 [ %10, %8 ], [ %.pre, %.thread27 ]
  %18 = phi ptr [ %7, %8 ], [ %15, %.thread27 ]
  %19 = getelementptr inbounds i8, ptr %18, i64 -16
  store i64 %.pre-phi, ptr %19, align 8, !tbaa !11
  %20 = getelementptr inbounds ptr, ptr %18, i64 %17
  store ptr %1, ptr %20, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %16, %3, %2
  %.1 = phi i32 [ 4, %2 ], [ 0, %16 ], [ %4, %3 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @msh_ply__validate_descriptor(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @msh_ply__array_grow(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

attributes #0 = { 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" }

!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, !10, i64 24}
!6 = !{!"msh_ply_file", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 44, !7, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"msh_ply_array_header", !13, i64 0, !13, i64 8}
!13 = !{!"long", !8, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass