; LLVM IR from Angold-4/chainsaw :: src/debug/editor.ll (ZN6Editor6delRowEi)

; 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.Editor = type { i8, ptr, ptr, %struct.buffer, ptr, ptr, %struct.editorConfig, %struct.editorConfig }
%struct.buffer = type { ptr, i64, i8, i32 }
%struct.editorConfig = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr, [80 x i8], %"class.std::__cxx11::basic_string", i8, i64 }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%struct.editRow = type { i32, i32, i32, ptr, ptr }

; 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Editor6delRowEi(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %11 = getelementptr inbounds %struct.editorConfig, ptr %10, i32 0, i32 8
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp sge i32 %9, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %75

15:                                               ; preds = %2
  %16 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %17 = getelementptr inbounds %struct.editorConfig, ptr %16, i32 0, i32 10
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %struct.editRow, ptr %18, i64 %20
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN6Editor7freeRowEP7editRow(ptr noundef nonnull align 8 dereferenceable(448) %8, ptr noundef %22)
  %23 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %24 = getelementptr inbounds %struct.editorConfig, ptr %23, i32 0, i32 10
  %25 = load ptr, ptr %24, align 8, !tbaa !19
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.editRow, ptr %25, i64 %27
  %29 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %30 = getelementptr inbounds %struct.editorConfig, ptr %29, i32 0, i32 10
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.editRow, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.editRow, ptr %34, i64 1
  %36 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %37 = getelementptr inbounds %struct.editorConfig, ptr %36, i32 0, i32 8
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = sub nsw i32 %38, %39
  %41 = sub nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = mul i64 32, %42
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %28, ptr align 8 %35, i64 %43, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %44 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %44, ptr %7, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %63, %15
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %48 = getelementptr inbounds %struct.editorConfig, ptr %47, i32 0, i32 8
  %49 = load i32, ptr %48, align 8, !tbaa !11
  %50 = sub nsw i32 %49, 1
  %51 = icmp slt i32 %46, %50
  br i1 %51, label %53, label %52

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

53:                                               ; preds = %45
  %54 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %55 = getelementptr inbounds %struct.editorConfig, ptr %54, i32 0, i32 10
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.editRow, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct.editRow, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !20
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %60, align 8, !tbaa !20
  br label %63

63:                                               ; preds = %53
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !9
  br label %45, !llvm.loop !22

66:                                               ; preds = %52
  %67 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %68 = getelementptr inbounds %struct.editorConfig, ptr %67, i32 0, i32 8
  %69 = load i32, ptr %68, align 8, !tbaa !11
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %68, align 8, !tbaa !11
  %71 = getelementptr inbounds %class.Editor, ptr %8, i32 0, i32 6
  %72 = getelementptr inbounds %struct.editorConfig, ptr %71, i32 0, i32 11
  %73 = load i32, ptr %72, align 8, !tbaa !24
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %72, align 8, !tbaa !24
  store i32 0, ptr %6, align 4
  br label %75

75:                                               ; preds = %66, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %76 = load i32, ptr %6, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  ret void

78:                                               ; preds = %75
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Editor7freeRowEP7editRow(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 96}
!12 = !{!"_ZTS6Editor", !13, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !6, i64 48, !6, i64 56, !16, i64 64, !16, i64 256}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS6buffer", !6, i64 0, !15, i64 8, !13, i64 16, !10, i64 20}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTS12editorConfig", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !6, i64 40, !10, i64 48, !6, i64 56, !7, i64 64, !17, i64 144, !13, i64 176, !15, i64 184}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !15, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!12, !6, i64 104}
!20 = !{!21, !10, i64 0}
!21 = !{!"_ZTS7editRow", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!12, !10, i64 112}


; 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.editRow = type { i32, i32, i32, ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6Editor6delRowEi(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp sgt i32 %4, %1
  br i1 %.not, label %5, label %29

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  %7 = load ptr, ptr %6, align 8, !tbaa !17
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds %struct.editRow, ptr %7, i64 %8
  tail call void @_ZN6Editor7freeRowEP7editRow(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef %9)
  %10 = load ptr, ptr %6, align 8, !tbaa !17
  %11 = getelementptr inbounds %struct.editRow, ptr %10, i64 %8
  %12 = getelementptr inbounds i8, ptr %11, i64 32
  %13 = load i32, ptr %3, align 8, !tbaa !5
  %14 = xor i32 %1, -1
  %15 = add i32 %13, %14
  %16 = sext i32 %15 to i64
  %17 = shl nsw i64 %16, 5
  tail call void @llvm.memmove.p0.p0.i64(ptr align 8 %11, ptr nonnull align 8 %12, i64 %17, i1 false)
  %18 = load i32, ptr %3, align 8, !tbaa !5
  %19 = add nsw i32 %18, -1
  %20 = icmp sgt i32 %19, %1
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %21 = load ptr, ptr %6, align 8, !tbaa !17
  %wide.trip.count = sext i32 %19 to i64
  br label %25

._crit_edge:                                      ; preds = %25, %5
  store i32 %19, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 112
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 8, !tbaa !18
  br label %29

25:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ %8, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %26 = getelementptr inbounds %struct.editRow, ptr %21, i64 %indvars.iv
  %27 = load i32, ptr %26, align 8, !tbaa !19
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %26, align 8, !tbaa !19
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %25, !llvm.loop !21

29:                                               ; preds = %2, %._crit_edge
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Editor7freeRowEP7editRow(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree 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" }

!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, !13, i64 96}
!6 = !{!"_ZTS6Editor", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !10, i64 48, !10, i64 56, !14, i64 64, !14, i64 256}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS6buffer", !10, i64 0, !12, i64 8, !7, i64 16, !13, i64 20}
!12 = !{!"long", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"_ZTS12editorConfig", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !10, i64 40, !13, i64 48, !10, i64 56, !8, i64 64, !15, i64 144, !7, i64 176, !12, i64 184}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !12, i64 8, !8, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!17 = !{!6, !10, i64 104}
!18 = !{!6, !13, i64 112}
!19 = !{!20, !13, i64 0}
!20 = !{!"_ZTS7editRow", !13, i64 0, !13, i64 4, !13, i64 8, !10, i64 16, !10, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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