; 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
declare dso_local i32 @msh_ply_add_property_to_element(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @msh_ply_write(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.msh_ply_file, ptr %8, i32 0, i32 4
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %19

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.msh_ply_file, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %15, i64 -16
  %17 = getelementptr inbounds %struct.msh_ply_array_header, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !13
  br label %20

19:                                               ; preds = %1
  br label %20

20:                                               ; preds = %19, %12
  %21 = phi i64 [ %18, %12 ], [ 0, %19 ]
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i32 14, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %84

24:                                               ; preds = %20
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.msh_ply_file, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %36

29:                                               ; preds = %24
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.msh_ply_file, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %32, i64 -16
  %34 = getelementptr inbounds %struct.msh_ply_array_header, ptr %33, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !13
  br label %37

36:                                               ; preds = %24
  br label %37

37:                                               ; preds = %36, %29
  %38 = phi i64 [ %35, %29 ], [ 0, %36 ]
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %73

40:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !17
  br label %41

41:                                               ; preds = %69, %40
  %42 = load i64, ptr %6, align 8, !tbaa !17
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.msh_ply_file, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %54

47:                                               ; preds = %41
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.msh_ply_file, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds i8, ptr %50, i64 -16
  %52 = getelementptr inbounds %struct.msh_ply_array_header, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !13
  br label %55

54:                                               ; preds = %41
  br label %55

55:                                               ; preds = %54, %47
  %56 = phi i64 [ %53, %47 ], [ 0, %54 ]
  %57 = icmp ult i64 %42, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %55
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %72

59:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.msh_ply_file, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = load i64, ptr %6, align 8, !tbaa !17
  %64 = getelementptr inbounds ptr, ptr %62, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  store ptr %65, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = call i32 @msh_ply_add_property_to_element(ptr noundef %66, ptr noundef %67)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %69

69:                                               ; preds = %59
  %70 = load i64, ptr %6, align 8, !tbaa !17
  %71 = add i64 %70, 1
  store i64 %71, ptr %6, align 8, !tbaa !17
  br label %41, !llvm.loop !18

72:                                               ; preds = %58
  br label %73

73:                                               ; preds = %72, %37
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = call i32 @msh_ply__write_header(ptr noundef %74)
  store i32 %75, ptr %4, align 4, !tbaa !9
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %73
  %79 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %79, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %84

80:                                               ; preds = %73
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = call i32 @msh_ply__write_data(ptr noundef %81)
  store i32 %82, ptr %4, align 4, !tbaa !9
  %83 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %83, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %84

84:                                               ; preds = %80, %78, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %85 = load i32, ptr %2, align 4
  ret i32 %85
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @msh_ply__write_data(ptr 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 = !{!12, !6, i64 16}
!17 = !{!15, !15, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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
declare dso_local i32 @msh_ply_add_property_to_element(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @msh_ply_write(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.critedge, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %3, i64 -16
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %.critedge, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %.not22 = icmp eq ptr %10, null
  br i1 %.not22, label %.critedge26.preheader, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %10, i64 -16
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %.critedge26.preheader, label %.loopexit

.critedge26.preheader:                            ; preds = %8, %11
  br label %.critedge26

.critedge26:                                      ; preds = %.critedge26.preheader, %22
  %15 = phi ptr [ %.pre, %22 ], [ %3, %.critedge26.preheader ]
  %.017 = phi i64 [ %26, %22 ], [ 0, %.critedge26.preheader ]
  %.not23 = icmp eq ptr %15, null
  br i1 %.not23, label %19, label %16

16:                                               ; preds = %.critedge26
  %17 = getelementptr inbounds i8, ptr %15, i64 -16
  %18 = load i64, ptr %17, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %.critedge26, %16
  %20 = phi i64 [ %18, %16 ], [ 0, %.critedge26 ]
  %21 = icmp ult i64 %.017, %20
  br i1 %21, label %22, label %.loopexit

22:                                               ; preds = %19
  %23 = getelementptr inbounds ptr, ptr %15, i64 %.017
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = tail call i32 @msh_ply_add_property_to_element(ptr noundef nonnull %0, ptr noundef %24)
  %26 = add nuw i64 %.017, 1
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br label %.critedge26, !llvm.loop !16

.loopexit:                                        ; preds = %19, %11
  %27 = tail call i32 @msh_ply__write_header(ptr noundef nonnull %0)
  %.not24 = icmp eq i32 %27, 0
  br i1 %.not24, label %28, label %.critedge

28:                                               ; preds = %.loopexit
  %29 = tail call i32 @msh_ply__write_data(ptr noundef nonnull %0)
  br label %.critedge

.critedge:                                        ; preds = %1, %.loopexit, %4, %28
  %.0 = phi i32 [ %29, %28 ], [ 14, %4 ], [ %27, %.loopexit ], [ 14, %1 ]
  ret i32 %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @msh_ply__write_data(ptr 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 = !{!6, !10, i64 16}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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