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

@_ZL18native_binary_type = external hidden global i32, align 4
@_ZL13types_checked = external hidden global i32, align 4
@.str.9 = external hidden unnamed_addr constant [85 x i8], align 1

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

16:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %89

17:                                               ; preds = %4
  %18 = load i32, ptr @_ZL18native_binary_type, align 4, !tbaa !9
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  call void @_Z22get_native_binary_typev()
  br label %21

21:                                               ; preds = %20, %17
  %22 = load i32, ptr @_ZL13types_checked, align 4, !tbaa !9
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @_Z11check_typesv()
  br label %25

25:                                               ; preds = %24, %21
  %26 = call noundef ptr @_Z8my_allociiPc(i32 noundef 80, i32 noundef 171, ptr noundef @.str.9)
  store ptr %26, ptr %11, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 4
  br i1 %28, label %29, label %33

29:                                               ; preds = %25
  %30 = load i32, ptr @_ZL18native_binary_type, align 4, !tbaa !9
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.PlyFile, ptr %31, i32 0, i32 1
  store i32 %30, ptr %32, align 8, !tbaa !11
  br label %37

33:                                               ; preds = %25
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.PlyFile, ptr %35, i32 0, i32 1
  store i32 %34, ptr %36, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %33, %29
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.PlyFile, ptr %38, i32 0, i32 5
  store i32 0, ptr %39, align 8, !tbaa !14
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.PlyFile, ptr %40, i32 0, i32 7
  store i32 0, ptr %41, align 8, !tbaa !15
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.PlyFile, ptr %43, i32 0, i32 3
  store i32 %42, ptr %44, align 8, !tbaa !16
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.PlyFile, ptr %45, i32 0, i32 2
  store float 1.000000e+00, ptr %46, align 4, !tbaa !17
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PlyFile, ptr %48, i32 0, i32 0
  store ptr %47, ptr %49, align 8, !tbaa !18
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.PlyFile, ptr %50, i32 0, i32 10
  store ptr null, ptr %51, align 8, !tbaa !19
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = mul i64 8, %53
  %55 = trunc i64 %54 to i32
  %56 = call noundef ptr @_Z8my_allociiPc(i32 noundef %55, i32 noundef 185, ptr noundef @.str.9)
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.PlyFile, ptr %57, i32 0, i32 4
  store ptr %56, ptr %58, align 8, !tbaa !20
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %84, %37
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %63, label %87

63:                                               ; preds = %59
  %64 = call noundef ptr @_Z8my_allociiPc(i32 noundef 48, i32 noundef 187, ptr noundef @.str.9)
  store ptr %64, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.PlyFile, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !20
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %68, i64 %70
  store ptr %65, ptr %71, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds ptr, ptr %72, i64 %74
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = call noalias ptr @strdup(ptr noundef %76) #4
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.PlyElement, ptr %78, i32 0, i32 0
  store ptr %77, ptr %79, align 8, !tbaa !21
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.PlyElement, ptr %80, i32 0, i32 1
  store i32 0, ptr %81, align 8, !tbaa !23
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.PlyElement, ptr %82, i32 0, i32 3
  store i32 0, ptr %83, align 8, !tbaa !24
  br label %84

84:                                               ; preds = %63
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %10, align 4, !tbaa !9
  br label %59, !llvm.loop !25

87:                                               ; preds = %59
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %88, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %89

89:                                               ; preds = %87, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %90 = load ptr, ptr %5, align 8
  ret ptr %90
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z22get_native_binary_typev() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11check_typesv() #2

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

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

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

attributes #0 = { 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 = { 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 = { 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, !10, i64 8}
!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 = !{!12, !10, i64 32}
!15 = !{!12, !10, i64 48}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !13, i64 12}
!18 = !{!12, !6, i64 0}
!19 = !{!12, !6, i64 72}
!20 = !{!12, !6, i64 24}
!21 = !{!22, !6, i64 0}
!22 = !{!"_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}
!23 = !{!22, !10, i64 8}
!24 = !{!22, !10, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"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"

@_ZL18native_binary_type = external hidden local_unnamed_addr global i32, align 4
@_ZL13types_checked = external hidden local_unnamed_addr global i32, align 4
@.str.9 = external hidden unnamed_addr constant [85 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @ply_write(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %4
  %7 = load i32, ptr @_ZL18native_binary_type, align 4, !tbaa !5
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  tail call void @_Z22get_native_binary_typev()
  br label %10

10:                                               ; preds = %9, %6
  %11 = load i32, ptr @_ZL13types_checked, align 4, !tbaa !5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %13

12:                                               ; preds = %10
  tail call void @_Z11check_typesv()
  br label %13

13:                                               ; preds = %12, %10
  %14 = tail call noundef ptr @_Z8my_allociiPc(i32 noundef 80, i32 noundef 171, ptr noundef nonnull @.str.9)
  %15 = icmp eq i32 %3, 4
  %16 = load i32, ptr @_ZL18native_binary_type, align 4
  %spec.select = select i1 %15, i32 %16, i32 %3
  %17 = getelementptr inbounds i8, ptr %14, i64 8
  store i32 %spec.select, ptr %17, align 8
  %18 = getelementptr inbounds i8, ptr %14, i64 32
  store i32 0, ptr %18, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %14, i64 48
  store i32 0, ptr %19, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %14, i64 16
  store i32 %1, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %14, i64 12
  store float 1.000000e+00, ptr %21, align 4, !tbaa !15
  store ptr %0, ptr %14, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %14, i64 72
  store ptr null, ptr %22, align 8, !tbaa !17
  %23 = shl i32 %1, 3
  %24 = tail call noundef ptr @_Z8my_allociiPc(i32 noundef %23, i32 noundef 185, ptr noundef nonnull @.str.9)
  %25 = getelementptr inbounds i8, ptr %14, i64 24
  store ptr %24, ptr %25, align 8, !tbaa !18
  %26 = icmp sgt i32 %1, 0
  br i1 %26, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %13
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %27 = tail call noundef ptr @_Z8my_allociiPc(i32 noundef 48, i32 noundef 187, ptr noundef nonnull @.str.9)
  %28 = load ptr, ptr %25, align 8, !tbaa !18
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv
  store ptr %27, ptr %29, align 8, !tbaa !19
  %30 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = tail call noalias ptr @strdup(ptr noundef %31) #2
  store ptr %32, ptr %27, align 8, !tbaa !20
  %33 = getelementptr inbounds i8, ptr %27, i64 8
  store i32 0, ptr %33, align 8, !tbaa !22
  %34 = getelementptr inbounds i8, ptr %27, i64 16
  store i32 0, ptr %34, align 8, !tbaa !23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !24

.loopexit:                                        ; preds = %.lr.ph, %13, %4
  %.0 = phi ptr [ null, %4 ], [ %14, %13 ], [ %14, %.lr.ph ]
  ret ptr %.0
}

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

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

; 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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 32}
!10 = !{!"_ZTS7PlyFile", !11, i64 0, !6, i64 8, !12, i64 12, !6, i64 16, !11, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !6, i64 48}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !12, i64 12}
!16 = !{!10, !11, i64 0}
!17 = !{!10, !11, i64 72}
!18 = !{!10, !11, i64 24}
!19 = !{!11, !11, i64 0}
!20 = !{!21, !11, i64 0}
!21 = !{!"_ZTS10PlyElement", !11, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 44}
!22 = !{!21, !6, i64 8}
!23 = !{!21, !6, i64 16}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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