; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Image.ll (ZN7R2ImageC2ERKS_)

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

%class.R2Image = type { i32, i32, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

declare void @_Z7RNAbortPKcz(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 uwtable
define dso_local void @_ZN7R2ImageC2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.R2Image, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  store i32 %12, ptr %9, align 8, !tbaa !9
  %13 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.R2Image, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !12
  store i32 %16, ptr %13, align 4, !tbaa !12
  %17 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.R2Image, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !13
  store i32 %20, ptr %17, align 8, !tbaa !13
  %21 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.R2Image, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !14
  store i32 %24, ptr %21, align 4, !tbaa !14
  %25 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 4
  store ptr null, ptr %25, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %26 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = mul nsw i32 %27, %29
  store i32 %30, ptr %5, align 4, !tbaa !16
  %31 = load i32, ptr %5, align 4, !tbaa !16
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %59

33:                                               ; preds = %2
  %34 = load i32, ptr %5, align 4, !tbaa !16
  %35 = sext i32 %34 to i64
  %36 = call noalias noundef nonnull ptr @_Znam(i64 noundef %35) #5
  %37 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 4
  store ptr %36, ptr %37, align 8, !tbaa !15
  %38 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = icmp ne ptr %39, null
  br i1 %40, label %42, label %41

41:                                               ; preds = %33
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 131, ptr noundef @.str.2)
  br label %42

42:                                               ; preds = %41, %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %43 = getelementptr inbounds %class.R2Image, ptr %8, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  store ptr %44, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %class.R2Image, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  store ptr %47, ptr %7, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %52, %42
  %49 = load i32, ptr %5, align 4, !tbaa !16
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %5, align 4, !tbaa !16
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %58

52:                                               ; preds = %48
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 1
  store ptr %54, ptr %7, align 8, !tbaa !5
  %55 = load i8, ptr %53, align 1, !tbaa !17
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i32 1
  store ptr %57, ptr %6, align 8, !tbaa !5
  store i8 %55, ptr %56, align 1, !tbaa !17
  br label %48, !llvm.loop !18

58:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %59

59:                                               ; preds = %58, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { "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 }
attributes #5 = { builtin allocsize(0) }

!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, !11, i64 0}
!10 = !{!"_ZTS7R2Image", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 12}
!15 = !{!10, !6, i64 16}
!16 = !{!11, !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7R2ImageC2ERKS_(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(24) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %1) unnamed_addr #1 align 2 {
  %3 = load <4 x i32>, ptr %1, align 8, !tbaa !5
  store <4 x i32> %3, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr null, ptr %4, align 8, !tbaa !9
  %5 = extractelement <4 x i32> %3, i64 1
  %6 = extractelement <4 x i32> %3, i64 3
  %7 = mul nsw i32 %6, %5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %2
  %10 = zext nneg i32 %7 to i64
  %11 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %10) #2
  store ptr %11, ptr %4, align 8, !tbaa !9
  %12 = add nsw i32 %7, -1
  %.not14 = icmp eq i32 %12, 0
  br i1 %.not14, label %.loopexit, label %iter.check

iter.check:                                       ; preds = %9
  %13 = ptrtoint ptr %11 to i64
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = zext i32 %12 to i64
  %min.iters.check = icmp ult i32 %7, 9
  %17 = ptrtoint ptr %15 to i64
  %18 = sub i64 %13, %17
  %diff.check = icmp ult i64 %18, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check17 = icmp ult i32 %7, 33
  br i1 %min.iters.check17, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %16, 4294967264
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %15, i64 %index
  %next.gep19 = getelementptr i8, ptr %11, i64 %index
  %19 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <16 x i8>, ptr %next.gep, align 1, !tbaa !12
  %wide.load21 = load <16 x i8>, ptr %19, align 1, !tbaa !12
  %20 = getelementptr i8, ptr %next.gep19, i64 16
  store <16 x i8> %wide.load, ptr %next.gep19, align 1, !tbaa !12
  store <16 x i8> %wide.load21, ptr %20, align 1, !tbaa !12
  %index.next = add nuw i64 %index, 32
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %16
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end30 = getelementptr i8, ptr %11, i64 %n.vec
  %ind.end27 = getelementptr i8, ptr %15, i64 %n.vec
  %.cast24 = trunc nuw i64 %n.vec to i32
  %ind.end25 = sub i32 %12, %.cast24
  %n.vec.remaining = and i64 %16, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec23 = and i64 %16, 4294967288
  %.cast = trunc nuw i64 %n.vec23 to i32
  %ind.end = sub i32 %12, %.cast
  %ind.end26 = getelementptr i8, ptr %15, i64 %n.vec23
  %ind.end29 = getelementptr i8, ptr %11, i64 %n.vec23
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index32 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next36, %vec.epilog.vector.body ]
  %next.gep33 = getelementptr i8, ptr %15, i64 %index32
  %next.gep34 = getelementptr i8, ptr %11, i64 %index32
  %wide.load35 = load <8 x i8>, ptr %next.gep33, align 1, !tbaa !12
  store <8 x i8> %wide.load35, ptr %next.gep34, align 1, !tbaa !12
  %index.next36 = add nuw i64 %index32, 8
  %22 = icmp eq i64 %index.next36, %n.vec23
  br i1 %22, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !17

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n37 = icmp eq i64 %n.vec23, %16
  br i1 %cmp.n37, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.ph = phi i32 [ %12, %iter.check ], [ %ind.end25, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.016.ph = phi ptr [ %15, %iter.check ], [ %ind.end27, %vec.epilog.iter.check ], [ %ind.end26, %vec.epilog.middle.block ]
  %.01015.ph = phi ptr [ %11, %iter.check ], [ %ind.end30, %vec.epilog.iter.check ], [ %ind.end29, %vec.epilog.middle.block ]
  %23 = add nsw i32 %.ph, -1
  %xtraiter = and i32 %.ph, 7
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %24 = phi i32 [ %28, %.lr.ph.prol ], [ %.ph, %.lr.ph.preheader ]
  %.016.prol = phi ptr [ %25, %.lr.ph.prol ], [ %.016.ph, %.lr.ph.preheader ]
  %.01015.prol = phi ptr [ %27, %.lr.ph.prol ], [ %.01015.ph, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %25 = getelementptr inbounds i8, ptr %.016.prol, i64 1
  %26 = load i8, ptr %.016.prol, align 1, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %.01015.prol, i64 1
  store i8 %26, ptr %.01015.prol, align 1, !tbaa !12
  %28 = add nsw i32 %24, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !18

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.unr = phi i32 [ %.ph, %.lr.ph.preheader ], [ %28, %.lr.ph.prol ]
  %.016.unr = phi ptr [ %.016.ph, %.lr.ph.preheader ], [ %25, %.lr.ph.prol ]
  %.01015.unr = phi ptr [ %.01015.ph, %.lr.ph.preheader ], [ %27, %.lr.ph.prol ]
  %29 = icmp ult i32 %23, 7
  br i1 %29, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %30 = phi i32 [ %55, %.lr.ph ], [ %.unr, %.lr.ph.prol.loopexit ]
  %.016 = phi ptr [ %52, %.lr.ph ], [ %.016.unr, %.lr.ph.prol.loopexit ]
  %.01015 = phi ptr [ %54, %.lr.ph ], [ %.01015.unr, %.lr.ph.prol.loopexit ]
  %31 = getelementptr inbounds i8, ptr %.016, i64 1
  %32 = load i8, ptr %.016, align 1, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %.01015, i64 1
  store i8 %32, ptr %.01015, align 1, !tbaa !12
  %34 = getelementptr inbounds i8, ptr %.016, i64 2
  %35 = load i8, ptr %31, align 1, !tbaa !12
  %36 = getelementptr inbounds i8, ptr %.01015, i64 2
  store i8 %35, ptr %33, align 1, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %.016, i64 3
  %38 = load i8, ptr %34, align 1, !tbaa !12
  %39 = getelementptr inbounds i8, ptr %.01015, i64 3
  store i8 %38, ptr %36, align 1, !tbaa !12
  %40 = getelementptr inbounds i8, ptr %.016, i64 4
  %41 = load i8, ptr %37, align 1, !tbaa !12
  %42 = getelementptr inbounds i8, ptr %.01015, i64 4
  store i8 %41, ptr %39, align 1, !tbaa !12
  %43 = getelementptr inbounds i8, ptr %.016, i64 5
  %44 = load i8, ptr %40, align 1, !tbaa !12
  %45 = getelementptr inbounds i8, ptr %.01015, i64 5
  store i8 %44, ptr %42, align 1, !tbaa !12
  %46 = getelementptr inbounds i8, ptr %.016, i64 6
  %47 = load i8, ptr %43, align 1, !tbaa !12
  %48 = getelementptr inbounds i8, ptr %.01015, i64 6
  store i8 %47, ptr %45, align 1, !tbaa !12
  %49 = getelementptr inbounds i8, ptr %.016, i64 7
  %50 = load i8, ptr %46, align 1, !tbaa !12
  %51 = getelementptr inbounds i8, ptr %.01015, i64 7
  store i8 %50, ptr %48, align 1, !tbaa !12
  %52 = getelementptr inbounds i8, ptr %.016, i64 8
  %53 = load i8, ptr %49, align 1, !tbaa !12
  %54 = getelementptr inbounds i8, ptr %.01015, i64 8
  store i8 %53, ptr %51, align 1, !tbaa !12
  %55 = add nsw i32 %30, -8
  %.not.7 = icmp eq i32 %55, 0
  br i1 %.not.7, label %.loopexit, label %.lr.ph, !llvm.loop !20

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %vec.epilog.middle.block, %9, %2
  ret void
}

attributes #0 = { nobuiltin allocsize(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 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 = { builtin allocsize(0) }

!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, !11, i64 16}
!10 = !{!"_ZTS7R2Image", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !14, !15, !16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !14, !15}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass