; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3MeshProperty.ll (ZNK14R3MeshProperty9WriteARFFEPKc)

; 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.R3MeshProperty = type { ptr, [1024 x i8], i32, ptr, double, double, double, double, double, double }

@stderr = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK6R3Mesh9NVerticesEv(ptr noundef nonnull align 8 dereferenceable(272)) #0 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK14R3MeshProperty11VertexValueEi(ptr noundef nonnull align 8 dereferenceable(1096), i32 noundef) #2 align 2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare noalias ptr @fopen(ptr noundef, ptr noundef) #4

declare i32 @fclose(ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK14R3MeshProperty9WriteARFFEPKc(ptr noundef nonnull align 8 dereferenceable(1096) %0, ptr noundef %1) #5 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call noalias ptr @fopen(ptr noundef %12, ptr noundef @.str.22)
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %20, label %16

16:                                               ; preds = %2
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef @.str.9, ptr noundef %18) #6
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %65

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %21 = getelementptr inbounds %struct.R3MeshProperty, ptr %11, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call noundef ptr @_ZNK6R3Mesh4NameEv(ptr noundef nonnull align 8 dereferenceable(272) %22)
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %29

25:                                               ; preds = %20
  %26 = getelementptr inbounds %struct.R3MeshProperty, ptr %11, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call noundef ptr @_ZNK6R3Mesh4NameEv(ptr noundef nonnull align 8 dereferenceable(272) %27)
  br label %30

29:                                               ; preds = %20
  br label %30

30:                                               ; preds = %29, %25
  %31 = phi ptr [ %28, %25 ], [ @.str.23, %29 ]
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.24, ptr noundef %33) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %35 = call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %11)
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %39

37:                                               ; preds = %30
  %38 = call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %11)
  br label %40

39:                                               ; preds = %30
  br label %40

40:                                               ; preds = %39, %37
  %41 = phi ptr [ %38, %37 ], [ @.str.25, %39 ]
  store ptr %41, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str.26, ptr noundef %43) #6
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.27) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %47

47:                                               ; preds = %59, %40
  %48 = load i32, ptr %10, align 4, !tbaa !13
  %49 = getelementptr inbounds %struct.R3MeshProperty, ptr %11, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = call noundef i32 @_ZNK6R3Mesh9NVerticesEv(ptr noundef nonnull align 8 dereferenceable(272) %50)
  %52 = icmp slt i32 %48, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %62

54:                                               ; preds = %47
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !13
  %57 = call noundef double @_ZNK14R3MeshProperty11VertexValueEi(ptr noundef nonnull align 8 dereferenceable(1096) %11, i32 noundef %56)
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str.28, double noundef %57) #6
  br label %59

59:                                               ; preds = %54
  %60 = load i32, ptr %10, align 4, !tbaa !13
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %10, align 4, !tbaa !13
  br label %47, !llvm.loop !14

62:                                               ; preds = %53
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = call i32 @fclose(ptr noundef %63)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %65

65:                                               ; preds = %62, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %66 = load i32, ptr %3, align 4
  ret i32 %66
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK6R3Mesh4NameEv(ptr noundef nonnull align 8 dereferenceable(272)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096)) #2 align 2

attributes #0 = { inlinehint mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 "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 = { "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 #5 = { mustprogress 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 #6 = { 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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS14R3MeshProperty", !6, i64 0, !7, i64 8, !11, i64 1032, !6, i64 1040, !12, i64 1048, !12, i64 1056, !12, i64 1064, !12, i64 1072, !12, i64 1080, !12, i64 1088}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK6R3Mesh9NVerticesEv(ptr noundef nonnull align 8 dereferenceable(272)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK14R3MeshProperty11VertexValueEi(ptr noundef nonnull align 8 dereferenceable(1096), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZNK14R3MeshProperty9WriteARFFEPKc(ptr noundef nonnull align 8 dereferenceable(1096) %0, ptr noundef %1) local_unnamed_addr #3 align 2 {
  %3 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.22)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %7

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.9, ptr noundef %1) #4
  br label %33

7:                                                ; preds = %2
  %8 = load ptr, ptr %0, align 8, !tbaa !9
  %9 = tail call noundef ptr @_ZNK6R3Mesh4NameEv(ptr noundef nonnull align 8 dereferenceable(272) %8)
  %.not16 = icmp eq ptr %9, null
  br i1 %.not16, label %13, label %10

10:                                               ; preds = %7
  %11 = load ptr, ptr %0, align 8, !tbaa !9
  %12 = tail call noundef ptr @_ZNK6R3Mesh4NameEv(ptr noundef nonnull align 8 dereferenceable(272) %11)
  br label %13

13:                                               ; preds = %7, %10
  %14 = phi ptr [ %12, %10 ], [ @.str.23, %7 ]
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.24, ptr noundef %14) #5
  %16 = tail call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %0)
  %.not17 = icmp eq ptr %16, null
  br i1 %.not17, label %19, label %17

17:                                               ; preds = %13
  %18 = tail call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %0)
  br label %19

19:                                               ; preds = %13, %17
  %20 = phi ptr [ %18, %17 ], [ @.str.25, %13 ]
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.26, ptr noundef %20) #5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.27) #5
  %23 = load ptr, ptr %0, align 8, !tbaa !9
  %24 = tail call noundef i32 @_ZNK6R3Mesh9NVerticesEv(ptr noundef nonnull align 8 dereferenceable(272) %23)
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %19
  %26 = tail call i32 @fclose(ptr noundef nonnull %3)
  br label %33

.lr.ph:                                           ; preds = %19, %.lr.ph
  %.018 = phi i32 [ %29, %.lr.ph ], [ 0, %19 ]
  %27 = tail call noundef double @_ZNK14R3MeshProperty11VertexValueEi(ptr noundef nonnull align 8 dereferenceable(1096) %0, i32 noundef %.018)
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.28, double noundef %27) #5
  %29 = add nuw nsw i32 %.018, 1
  %30 = load ptr, ptr %0, align 8, !tbaa !9
  %31 = tail call noundef i32 @_ZNK6R3Mesh9NVerticesEv(ptr noundef nonnull align 8 dereferenceable(272) %30)
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !13

33:                                               ; preds = %._crit_edge, %4
  %.014 = phi i32 [ 1, %._crit_edge ], [ 0, %4 ]
  ret i32 %.014
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK6R3Mesh4NameEv(ptr noundef nonnull align 8 dereferenceable(272)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096)) local_unnamed_addr #1 align 2

attributes #0 = { inlinehint mustprogress 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 #1 = { inlinehint mustprogress 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 = { mustprogress 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 = { cold nounwind }
attributes #5 = { 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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS14R3MeshProperty", !6, i64 0, !7, i64 8, !11, i64 1032, !6, i64 1040, !12, i64 1048, !12, i64 1056, !12, i64 1064, !12, i64 1072, !12, i64 1080, !12, i64 1088}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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