; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes (ply)

; 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.PlyFile = type { ptr, i32, float, i32, ptr, i32, ptr, i32, ptr, ptr, ptr }
%struct.PlyElement = type { ptr, i32, i32, i32, ptr, ptr, i32, i32 }
%struct.PlyOtherProp = type { ptr, i32, i32, ptr }

@.str.9 = external hidden unnamed_addr constant [85 x i8], align 1
@stderr = external global ptr, align 8
@.str.43 = external hidden unnamed_addr constant [51 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z8my_allociiPc(i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #2

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z13copy_propertyP11PlyPropertyS0_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17setup_other_propsP10PlyElement(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local ptr @ply_get_other_properties(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call noundef ptr @_Z12find_elementP7PlyFilePc(ptr noundef %14, ptr noundef %15)
  store ptr %16, ptr %9, align 8, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %23

19:                                               ; preds = %3
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.43, ptr noundef %21) #4
  store ptr null, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %101

23:                                               ; preds = %3
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.PlyFile, ptr %25, i32 0, i32 9
  store ptr %24, ptr %26, align 8, !tbaa !11
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PlyElement, ptr %28, i32 0, i32 6
  store i32 %27, ptr %29, align 8, !tbaa !14
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_Z17setup_other_propsP10PlyElement(ptr noundef %30)
  %31 = call noundef ptr @_Z8my_allociiPc(i32 noundef 24, i32 noundef 1185, ptr noundef @.str.9)
  store ptr %31, ptr %10, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call noalias ptr @strdup(ptr noundef %32) #4
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.PlyOtherProp, ptr %34, i32 0, i32 0
  store ptr %33, ptr %35, align 8, !tbaa !16
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PlyElement, ptr %36, i32 0, i32 7
  %38 = load i32, ptr %37, align 4, !tbaa !18
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PlyOtherProp, ptr %39, i32 0, i32 1
  store i32 %38, ptr %40, align 8, !tbaa !19
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.PlyElement, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %42, align 8, !tbaa !20
  %44 = sext i32 %43 to i64
  %45 = mul i64 40, %44
  %46 = trunc i64 %45 to i32
  %47 = call noundef ptr @_Z8my_allociiPc(i32 noundef %46, i32 noundef 1196, ptr noundef @.str.9)
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PlyOtherProp, ptr %48, i32 0, i32 3
  store ptr %47, ptr %49, align 8, !tbaa !21
  store i32 0, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %85, %23
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.PlyElement, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 8, !tbaa !20
  %55 = icmp slt i32 %51, %54
  br i1 %55, label %56, label %88

56:                                               ; preds = %50
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.PlyElement, ptr %57, i32 0, i32 5
  %59 = load ptr, ptr %58, align 8, !tbaa !22
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr %59, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !23
  %64 = icmp ne i8 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %56
  br label %85

66:                                               ; preds = %56
  %67 = call noundef ptr @_Z8my_allociiPc(i32 noundef 40, i32 noundef 1203, ptr noundef @.str.9)
  store ptr %67, ptr %11, align 8, !tbaa !5
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.PlyElement, ptr %69, i32 0, i32 4
  %71 = load ptr, ptr %70, align 8, !tbaa !24
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds ptr, ptr %71, i64 %73
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  call void @_Z13copy_propertyP11PlyPropertyS0_(ptr noundef %68, ptr noundef %75)
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.PlyOtherProp, ptr %77, i32 0, i32 3
  %79 = load ptr, ptr %78, align 8, !tbaa !21
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %79, i64 %81
  store ptr %76, ptr %82, align 8, !tbaa !5
  %83 = load i32, ptr %12, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %12, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %66, %65
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %8, align 4, !tbaa !9
  br label %50, !llvm.loop !25

88:                                               ; preds = %50
  %89 = load i32, ptr %12, align 4, !tbaa !9
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.PlyOtherProp, ptr %90, i32 0, i32 2
  store i32 %89, ptr %91, align 4, !tbaa !27
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.PlyOtherProp, ptr %92, i32 0, i32 2
  %94 = load i32, ptr %93, align 4, !tbaa !27
  %95 = icmp eq i32 %94, 0
  br i1 %95, label %96, label %99

96:                                               ; preds = %88
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.PlyElement, ptr %97, i32 0, i32 6
  store i32 -1, ptr %98, align 8, !tbaa !14
  br label %99

99:                                               ; preds = %96, %88
  %100 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %100, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %101

101:                                              ; preds = %99, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %102 = load ptr, ptr %4, align 8
  ret ptr %102
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 64}
!12 = !{!"_ZTS7PlyFile", !6, i64 0, !10, i64 8, !13, i64 12, !10, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!13 = !{!"float", !7, i64 0}
!14 = !{!15, !10, i64 40}
!15 = !{!"_ZTS10PlyElement", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTS12PlyOtherProp", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!18 = !{!15, !10, i64 44}
!19 = !{!17, !10, i64 8}
!20 = !{!15, !10, i64 16}
!21 = !{!17, !6, i64 16}
!22 = !{!15, !6, i64 32}
!23 = !{!7, !7, i64 0}
!24 = !{!15, !6, i64 24}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!17, !10, i64 12}


; 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"

@.str.9 = external hidden unnamed_addr constant [85 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.43 = external hidden unnamed_addr constant [51 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z13copy_propertyP11PlyPropertyS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17setup_other_propsP10PlyElement(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @ply_get_other_properties(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef ptr @_Z12find_elementP7PlyFilePc(ptr noundef %0, ptr noundef %1)
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.43, ptr noundef %1) #3
  br label %48

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %4, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %4, i64 40
  store i32 %2, ptr %11, align 8, !tbaa !13
  tail call void @_Z17setup_other_propsP10PlyElement(ptr noundef nonnull %4)
  %12 = tail call noundef ptr @_Z8my_allociiPc(i32 noundef 24, i32 noundef 1185, ptr noundef nonnull @.str.9)
  %13 = tail call noalias ptr @strdup(ptr noundef %1) #4
  store ptr %13, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %4, i64 44
  %15 = load i32, ptr %14, align 4, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %12, i64 8
  store i32 %15, ptr %16, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %4, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !19
  %19 = mul i32 %18, 40
  %20 = tail call noundef ptr @_Z8my_allociiPc(i32 noundef %19, i32 noundef 1196, ptr noundef nonnull @.str.9)
  %21 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %20, ptr %21, align 8, !tbaa !20
  %22 = load i32, ptr %17, align 8, !tbaa !19
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %9
  %24 = getelementptr inbounds i8, ptr %12, i64 12
  store i32 0, ptr %24, align 4, !tbaa !21
  br label %47

.lr.ph:                                           ; preds = %9
  %25 = getelementptr inbounds i8, ptr %4, i64 32
  %26 = getelementptr inbounds i8, ptr %4, i64 24
  br label %27

27:                                               ; preds = %.lr.ph, %41
  %28 = phi i32 [ %22, %.lr.ph ], [ %42, %41 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %41 ]
  %.036 = phi i32 [ 0, %.lr.ph ], [ %.1, %41 ]
  %29 = load ptr, ptr %25, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %29, i64 %indvars.iv
  %31 = load i8, ptr %30, align 1, !tbaa !23
  %.not = icmp eq i8 %31, 0
  br i1 %.not, label %32, label %41

32:                                               ; preds = %27
  %33 = tail call noundef ptr @_Z8my_allociiPc(i32 noundef 40, i32 noundef 1203, ptr noundef nonnull @.str.9)
  %34 = load ptr, ptr %26, align 8, !tbaa !24
  %35 = getelementptr inbounds ptr, ptr %34, i64 %indvars.iv
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  tail call void @_Z13copy_propertyP11PlyPropertyS0_(ptr noundef %33, ptr noundef %36)
  %37 = load ptr, ptr %21, align 8, !tbaa !20
  %38 = sext i32 %.036 to i64
  %39 = getelementptr inbounds ptr, ptr %37, i64 %38
  store ptr %33, ptr %39, align 8, !tbaa !5
  %40 = add nsw i32 %.036, 1
  %.pre = load i32, ptr %17, align 8, !tbaa !19
  br label %41

41:                                               ; preds = %27, %32
  %42 = phi i32 [ %28, %27 ], [ %.pre, %32 ]
  %.1 = phi i32 [ %.036, %27 ], [ %40, %32 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next, %43
  br i1 %44, label %27, label %._crit_edge, !llvm.loop !25

._crit_edge:                                      ; preds = %41
  %45 = getelementptr inbounds i8, ptr %12, i64 12
  store i32 %.1, ptr %45, align 4, !tbaa !21
  %46 = icmp eq i32 %.1, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %._crit_edge.thread, %._crit_edge
  store i32 -1, ptr %11, align 8, !tbaa !13
  br label %48

48:                                               ; preds = %._crit_edge, %47, %6
  %.032 = phi ptr [ null, %6 ], [ %12, %47 ], [ %12, %._crit_edge ]
  ret ptr %.032
}

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { cold nounwind }
attributes #4 = { 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 64}
!10 = !{!"_ZTS7PlyFile", !6, i64 0, !11, i64 8, !12, i64 12, !11, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !11, i64 40}
!14 = !{!"_ZTS10PlyElement", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 44}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTS12PlyOtherProp", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16}
!17 = !{!14, !11, i64 44}
!18 = !{!16, !11, i64 8}
!19 = !{!14, !11, i64 16}
!20 = !{!16, !6, i64 16}
!21 = !{!16, !11, i64 12}
!22 = !{!14, !6, i64 32}
!23 = !{!7, !7, i64 0}
!24 = !{!14, !6, i64 24}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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