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

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

; 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: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #1

; 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) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Editor13rowInsertCharEP7editRowiiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(192) %4) #3 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.editRow, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp sgt i32 %13, %16
  br i1 %17, label %18, label %64

18:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.editRow, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = sub nsw i32 %19, %22
  store i32 %23, ptr %11, align 4, !tbaa !9
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.editRow, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.editRow, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = add nsw i32 %29, %30
  %32 = add nsw i32 %31, 2
  %33 = sext i32 %32 to i64
  %34 = call ptr @realloc(ptr noundef %26, i64 noundef %33) #6
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.editRow, ptr %35, i32 0, i32 3
  store ptr %34, ptr %36, align 8, !tbaa !13
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.editRow, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.editRow, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %39, i64 %43
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %44, i8 32, i64 %46, i1 false)
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.editRow, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.editRow, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add nsw i32 %52, %53
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %49, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !14
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.editRow, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !11
  %63 = add nsw i32 %62, %59
  store i32 %63, ptr %61, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %100

64:                                               ; preds = %5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.editRow, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.editRow, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = add nsw i32 %70, 2
  %72 = sext i32 %71 to i64
  %73 = call ptr @realloc(ptr noundef %67, i64 noundef %72) #6
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.editRow, ptr %74, i32 0, i32 3
  store ptr %73, ptr %75, align 8, !tbaa !13
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.editRow, ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !13
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %78, i64 %80
  %82 = getelementptr inbounds i8, ptr %81, i64 1
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.editRow, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !13
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %85, i64 %87
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.editRow, ptr %89, i32 0, i32 1
  %91 = load i32, ptr %90, align 4, !tbaa !11
  %92 = load i32, ptr %8, align 4, !tbaa !9
  %93 = sub nsw i32 %91, %92
  %94 = add nsw i32 %93, 1
  %95 = sext i32 %94 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %82, ptr align 1 %88, i64 %95, i1 false)
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.editRow, ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 4, !tbaa !11
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %97, align 4, !tbaa !11
  br label %100

100:                                              ; preds = %64, %18
  %101 = load i32, ptr %9, align 4, !tbaa !9
  %102 = trunc i32 %101 to i8
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.editRow, ptr %103, i32 0, i32 3
  %105 = load ptr, ptr %104, align 8, !tbaa !13
  %106 = load i32, ptr %8, align 4, !tbaa !9
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds i8, ptr %105, i64 %107
  store i8 %102, ptr %108, align 1, !tbaa !14
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN6Editor9UpdateRowEP7editRow(ptr noundef nonnull align 8 dereferenceable(448) %12, ptr noundef %109)
  %110 = load ptr, ptr %10, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.editorConfig, ptr %110, i32 0, i32 11
  %112 = load i32, ptr %111, align 8, !tbaa !15
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr %111, align 8, !tbaa !15
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

!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 4}
!12 = !{!"_ZTS7editRow", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !6, i64 16}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !10, i64 48}
!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, !20, i64 176, !19, i64 184}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !19, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"bool", !7, i64 0}


; 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: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #0

; 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) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Editor13rowInsertCharEP7editRowiiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef nonnull align 8 dereferenceable(192) %4) local_unnamed_addr #2 align 2 {
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp slt i32 %7, %2
  br i1 %8, label %9, label %24

9:                                                ; preds = %5
  %10 = sub nsw i32 %2, %7
  %11 = getelementptr inbounds i8, ptr %1, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = add nsw i32 %2, 2
  %14 = sext i32 %13 to i64
  %15 = tail call ptr @realloc(ptr noundef %12, i64 noundef %14) #4
  store ptr %15, ptr %11, align 8, !tbaa !11
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = sext i32 %10 to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %18, i8 32, i64 %19, i1 false)
  %20 = add i32 %16, %10
  %21 = sext i32 %20 to i64
  %22 = getelementptr i8, ptr %15, i64 %21
  %23 = getelementptr i8, ptr %22, i64 1
  store i8 0, ptr %23, align 1, !tbaa !12
  %.pre = sext i32 %2 to i64
  br label %36

24:                                               ; preds = %5
  %25 = getelementptr inbounds i8, ptr %1, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = add nsw i32 %7, 2
  %28 = sext i32 %27 to i64
  %29 = tail call ptr @realloc(ptr noundef %26, i64 noundef %28) #4
  store ptr %29, ptr %25, align 8, !tbaa !11
  %30 = sext i32 %2 to i64
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = getelementptr inbounds i8, ptr %31, i64 1
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %reass.sub = sub i32 %33, %2
  %34 = add i32 %reass.sub, 1
  %35 = sext i32 %34 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %32, ptr align 1 %31, i64 %35, i1 false)
  br label %36

36:                                               ; preds = %24, %9
  %.pre-phi = phi i64 [ %30, %24 ], [ %.pre, %9 ]
  %37 = phi ptr [ %29, %24 ], [ %15, %9 ]
  %storemerge.in = phi i32 [ %33, %24 ], [ %20, %9 ]
  %storemerge = add i32 %storemerge.in, 1
  store i32 %storemerge, ptr %6, align 4, !tbaa !5
  %38 = trunc i32 %3 to i8
  %39 = getelementptr inbounds i8, ptr %37, i64 %.pre-phi
  store i8 %38, ptr %39, align 1, !tbaa !12
  tail call void @_ZN6Editor9UpdateRowEP7editRow(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef nonnull %1)
  %40 = getelementptr inbounds i8, ptr %4, i64 48
  %41 = load i32, ptr %40, align 8, !tbaa !13
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %40, align 8, !tbaa !13
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #1 = { mustprogress 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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(1) }

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass