; 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_parse_header(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @msh_ply_parse_contents(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @msh_ply_get_property_from_element(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @msh_ply_read(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 5
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %1
  store i32 4, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %94

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.msh_ply_file, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %25

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, 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 !13
  %22 = getelementptr inbounds i8, ptr %21, i64 -16
  %23 = getelementptr inbounds %struct.msh_ply_array_header, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !14
  br label %26

25:                                               ; preds = %13
  br label %26

26:                                               ; preds = %25, %18
  %27 = phi i64 [ %24, %18 ], [ 0, %25 ]
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 14, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %94

30:                                               ; preds = %26
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.msh_ply_file, ptr %31, i32 0, i32 8
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %38, label %35

35:                                               ; preds = %30
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = call i32 @msh_ply_parse_header(ptr noundef %36)
  store i32 %37, ptr %4, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %35, %30
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %42, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %94

43:                                               ; preds = %38
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i32 @msh_ply_parse_contents(ptr noundef %44)
  store i32 %45, ptr %4, align 4, !tbaa !9
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %43
  %49 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %49, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %94

50:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !18
  br label %51

51:                                               ; preds = %87, %50
  %52 = load i64, ptr %6, align 8, !tbaa !18
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.msh_ply_file, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %64

57:                                               ; preds = %51
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.msh_ply_file, ptr %58, i32 0, i32 4
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = getelementptr inbounds i8, ptr %60, i64 -16
  %62 = getelementptr inbounds %struct.msh_ply_array_header, ptr %61, i32 0, i32 0
  %63 = load i64, ptr %62, align 8, !tbaa !14
  br label %65

64:                                               ; preds = %51
  br label %65

65:                                               ; preds = %64, %57
  %66 = phi i64 [ %63, %57 ], [ 0, %64 ]
  %67 = icmp ult i64 %52, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %65
  store i32 2, ptr %5, align 4
  br label %90

69:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.msh_ply_file, ptr %70, i32 0, i32 4
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = load i64, ptr %6, align 8, !tbaa !18
  %74 = getelementptr inbounds ptr, ptr %72, i64 %73
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  store ptr %75, ptr %7, align 8, !tbaa !5
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = call i32 @msh_ply_get_property_from_element(ptr noundef %76, ptr noundef %77)
  store i32 %78, ptr %4, align 4, !tbaa !9
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %83

81:                                               ; preds = %69
  %82 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %82, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %84

83:                                               ; preds = %69
  store i32 0, ptr %5, align 4
  br label %84

84:                                               ; preds = %83, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %85 = load i32, ptr %5, align 4
  switch i32 %85, label %90 [
    i32 0, label %86
  ]

86:                                               ; preds = %84
  br label %87

87:                                               ; preds = %86
  %88 = load i64, ptr %6, align 8, !tbaa !18
  %89 = add i64 %88, 1
  store i64 %89, ptr %6, align 8, !tbaa !18
  br label %51, !llvm.loop !19

90:                                               ; preds = %84, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %91 = load i32, ptr %5, align 4
  switch i32 %91, label %94 [
    i32 2, label %92
  ]

92:                                               ; preds = %90
  %93 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %93, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %94

94:                                               ; preds = %92, %90, %48, %41, %29, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %95 = load i32, ptr %2, align 4
  ret i32 %95
}

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 32}
!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 = !{!12, !6, i64 24}
!14 = !{!15, !16, i64 0}
!15 = !{!"msh_ply_array_header", !16, i64 0, !16, i64 8}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !10, i64 48}
!18 = !{!16, !16, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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_parse_header(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @msh_ply_get_property_from_element(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @msh_ply_read(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %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 %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %.not35 = icmp eq ptr %6, null
  br i1 %.not35, label %.critedge, label %7

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

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %.not36 = icmp eq i32 %13, 0
  br i1 %.not36, label %14, label %.thread

14:                                               ; preds = %11
  %15 = tail call i32 @msh_ply_parse_header(ptr noundef nonnull %0)
  %.not37 = icmp eq i32 %15, 0
  br i1 %.not37, label %.thread, label %.critedge

.thread:                                          ; preds = %11, %14
  %16 = tail call i32 @msh_ply_parse_contents(ptr noundef nonnull %0)
  %.not38 = icmp eq i32 %16, 0
  br i1 %.not38, label %.preheader, label %.critedge

.preheader:                                       ; preds = %.thread, %23
  %.024 = phi i64 [ %27, %23 ], [ 0, %.thread ]
  %17 = load ptr, ptr %5, align 8, !tbaa !11
  %.not39 = icmp eq ptr %17, null
  br i1 %.not39, label %21, label %18

18:                                               ; preds = %.preheader
  %19 = getelementptr inbounds i8, ptr %17, i64 -16
  %20 = load i64, ptr %19, align 8, !tbaa !12
  br label %21

21:                                               ; preds = %.preheader, %18
  %22 = phi i64 [ %20, %18 ], [ 0, %.preheader ]
  %.not41 = icmp ult i64 %.024, %22
  br i1 %.not41, label %23, label %.critedge

23:                                               ; preds = %21
  %24 = getelementptr inbounds ptr, ptr %17, i64 %.024
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = tail call i32 @msh_ply_get_property_from_element(ptr noundef nonnull %0, ptr noundef %25)
  %.not40 = icmp eq i32 %26, 0
  %27 = add nuw i64 %.024, 1
  br i1 %.not40, label %.preheader, label %.critedge, !llvm.loop !17

.critedge:                                        ; preds = %23, %21, %4, %.thread, %14, %7, %1
  %.3 = phi i32 [ 4, %1 ], [ 14, %7 ], [ %15, %14 ], [ %16, %.thread ], [ 14, %4 ], [ 0, %21 ], [ %26, %23 ]
  ret i32 %.3
}

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 32}
!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 = !{!6, !10, i64 24}
!12 = !{!13, !14, i64 0}
!13 = !{!"msh_ply_array_header", !14, i64 0, !14, i64 8}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !7, i64 48}
!16 = !{!10, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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