; 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 }
%struct.msh_ply_element = type { [64 x i8], i32, ptr, i64, ptr, i64 }

@__func__.msh_ply_close = 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 void @_wip_free(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @msh_ply_close(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.msh_ply_file, ptr %5, i32 0, i32 5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %16

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.msh_ply_file, ptr %10, i32 0, i32 5
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call i32 @fclose(ptr noundef %12)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.msh_ply_file, ptr %14, i32 0, i32 5
  store ptr null, ptr %15, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %9, %1
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.msh_ply_file, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %84

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !13
  br label %22

22:                                               ; preds = %66, %21
  %23 = load i64, ptr %3, align 8, !tbaa !13
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.msh_ply_file, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %35

28:                                               ; preds = %22
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.msh_ply_file, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds i8, ptr %31, i64 -16
  %33 = getelementptr inbounds %struct.msh_ply_array_header, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !15
  br label %36

35:                                               ; preds = %22
  br label %36

36:                                               ; preds = %35, %28
  %37 = phi i64 [ %34, %28 ], [ 0, %35 ]
  %38 = icmp ult i64 %23, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %69

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.msh_ply_file, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  %44 = load i64, ptr %3, align 8, !tbaa !13
  %45 = getelementptr inbounds %struct.msh_ply_element, ptr %43, i64 %44
  store ptr %45, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.msh_ply_element, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %65

50:                                               ; preds = %40
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.msh_ply_element, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %62

55:                                               ; preds = %50
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.msh_ply_element, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = getelementptr inbounds i8, ptr %58, i64 -16
  call void @_wip_free(ptr noundef %59, ptr noundef @__func__.msh_ply_close)
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.msh_ply_element, ptr %60, i32 0, i32 2
  store ptr null, ptr %61, align 8, !tbaa !17
  br label %63

62:                                               ; preds = %50
  br label %63

63:                                               ; preds = %62, %55
  %64 = phi ptr [ null, %55 ], [ null, %62 ]
  br label %65

65:                                               ; preds = %63, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %3, align 8, !tbaa !13
  %68 = add i64 %67, 1
  store i64 %68, ptr %3, align 8, !tbaa !13
  br label %22, !llvm.loop !19

69:                                               ; preds = %39
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.msh_ply_file, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !12
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %81

74:                                               ; preds = %69
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.msh_ply_file, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !12
  %78 = getelementptr inbounds i8, ptr %77, i64 -16
  call void @_wip_free(ptr noundef %78, ptr noundef @__func__.msh_ply_close)
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.msh_ply_file, ptr %79, i32 0, i32 3
  store ptr null, ptr %80, align 8, !tbaa !12
  br label %82

81:                                               ; preds = %69
  br label %82

82:                                               ; preds = %81, %74
  %83 = phi ptr [ null, %74 ], [ null, %81 ]
  br label %84

84:                                               ; preds = %82, %16
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.msh_ply_file, ptr %85, i32 0, i32 4
  %87 = load ptr, ptr %86, align 8, !tbaa !21
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %104

89:                                               ; preds = %84
  %90 = load ptr, ptr %2, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.msh_ply_file, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !21
  %93 = icmp ne ptr %92, null
  br i1 %93, label %94, label %101

94:                                               ; preds = %89
  %95 = load ptr, ptr %2, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.msh_ply_file, ptr %95, i32 0, i32 4
  %97 = load ptr, ptr %96, align 8, !tbaa !21
  %98 = getelementptr inbounds i8, ptr %97, i64 -16
  call void @_wip_free(ptr noundef %98, ptr noundef @__func__.msh_ply_close)
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.msh_ply_file, ptr %99, i32 0, i32 4
  store ptr null, ptr %100, align 8, !tbaa !21
  br label %102

101:                                              ; preds = %89
  br label %102

102:                                              ; preds = %101, %94
  %103 = phi ptr [ null, %94 ], [ null, %101 ]
  br label %104

104:                                              ; preds = %102, %84
  %105 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_wip_free(ptr noundef %105, ptr noundef @__func__.msh_ply_close)
  ret void
}

declare i32 @fclose(ptr noundef) #1

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


; 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.msh_ply_element = type { [64 x i8], i32, ptr, i64, ptr, i64 }

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

declare void @_wip_free(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @msh_ply_close(ptr noundef %0) local_unnamed_addr #1 {
  %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 %6, label %4

4:                                                ; preds = %1
  %5 = tail call i32 @fclose(ptr noundef nonnull %3)
  store ptr null, ptr %2, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %4, %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %.not26 = icmp eq ptr %8, null
  br i1 %.not26, label %.loopexit, label %.thread

.thread:                                          ; preds = %6, %17
  %.pr35 = phi ptr [ %.pr, %17 ], [ %8, %6 ]
  %.033 = phi i64 [ %18, %17 ], [ 0, %6 ]
  %9 = getelementptr inbounds i8, ptr %.pr35, i64 -16
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %11 = icmp ult i64 %.033, %10
  br i1 %11, label %12, label %19

12:                                               ; preds = %.thread
  %13 = getelementptr inbounds %struct.msh_ply_element, ptr %.pr35, i64 %.033, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %.not30 = icmp eq ptr %14, null
  br i1 %.not30, label %17, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %14, i64 -16
  tail call void @_wip_free(ptr noundef nonnull %16, ptr noundef nonnull @__func__.msh_ply_close) #3
  store ptr null, ptr %13, align 8, !tbaa !15
  %.pr.pre = load ptr, ptr %7, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %15, %12
  %.pr = phi ptr [ %.pr.pre, %15 ], [ %.pr35, %12 ]
  %18 = add nuw i64 %.033, 1
  %.not27 = icmp eq ptr %.pr, null
  br i1 %.not27, label %.loopexit, label %.thread, !llvm.loop !17

19:                                               ; preds = %.thread
  %20 = getelementptr inbounds i8, ptr %.pr35, i64 -16
  tail call void @_wip_free(ptr noundef nonnull %20, ptr noundef nonnull @__func__.msh_ply_close) #3
  store ptr null, ptr %7, align 8, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %17, %19, %6
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %.not29 = icmp eq ptr %22, null
  br i1 %.not29, label %25, label %23

23:                                               ; preds = %.loopexit
  %24 = getelementptr inbounds i8, ptr %22, i64 -16
  tail call void @_wip_free(ptr noundef nonnull %24, ptr noundef nonnull @__func__.msh_ply_close) #3
  store ptr null, ptr %21, align 8, !tbaa !19
  br label %25

25:                                               ; preds = %23, %.loopexit
  tail call void @_wip_free(ptr noundef nonnull %0, ptr noundef nonnull @__func__.msh_ply_close) #3
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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 = { 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 = { nofree nounwind "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, !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 16}
!12 = !{!13, !14, i64 0}
!13 = !{!"msh_ply_array_header", !14, i64 0, !14, i64 8}
!14 = !{!"long", !8, i64 0}
!15 = !{!16, !10, i64 72}
!16 = !{!"msh_ply_element", !8, i64 0, !7, i64 64, !10, i64 72, !14, i64 80, !10, i64 88, !14, i64 96}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 24}


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