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

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

@.str.13 = external hidden unnamed_addr constant [1 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Editor9InsertRowEiPcmR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448), i32 noundef, ptr noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(192)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Editor10InsertCharEiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(192) %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.editorConfig, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.editorConfig, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !17
  %17 = add nsw i32 %13, %16
  store i32 %17, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.editorConfig, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.editorConfig, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !19
  %24 = add nsw i32 %20, %23
  store i32 %24, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.editorConfig, ptr %26, i32 0, i32 8
  %28 = load i32, ptr %27, align 8, !tbaa !20
  %29 = icmp sge i32 %25, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %3
  br label %38

31:                                               ; preds = %3
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.editorConfig, ptr %32, i32 0, i32 10
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.editRow, ptr %34, i64 %36
  br label %38

38:                                               ; preds = %31, %30
  %39 = phi ptr [ null, %30 ], [ %37, %31 ]
  store ptr %39, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %56, label %42

42:                                               ; preds = %38
  br label %43

43:                                               ; preds = %49, %42
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.editorConfig, ptr %44, i32 0, i32 8
  %46 = load i32, ptr %45, align 8, !tbaa !20
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %49, label %55

49:                                               ; preds = %43
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.editorConfig, ptr %50, i32 0, i32 8
  %52 = load i32, ptr %51, align 8, !tbaa !20
  %53 = call noalias ptr @strdup(ptr noundef @.str.13) #3
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN6Editor9InsertRowEiPcmR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %10, i32 noundef %52, ptr noundef %53, i64 noundef 0, ptr noundef nonnull align 8 dereferenceable(192) %54)
  br label %43, !llvm.loop !22

55:                                               ; preds = %43
  br label %56

56:                                               ; preds = %55, %38
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.editorConfig, ptr %57, i32 0, i32 10
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.editRow, ptr %59, i64 %61
  store ptr %62, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN6Editor13rowInsertCharEP7editRowiiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %10, ptr noundef %63, i32 noundef %64, i32 noundef %65, ptr noundef nonnull align 8 dereferenceable(192) %66)
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.editorConfig, ptr %67, i32 0, i32 0
  %69 = load i32, ptr %68, align 8, !tbaa !19
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.editorConfig, ptr %70, i32 0, i32 5
  %72 = load i32, ptr %71, align 4, !tbaa !24
  %73 = sub nsw i32 %72, 1
  %74 = icmp eq i32 %69, %73
  br i1 %74, label %75, label %80

75:                                               ; preds = %56
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.editorConfig, ptr %76, i32 0, i32 3
  %78 = load i32, ptr %77, align 4, !tbaa !18
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %77, align 4, !tbaa !18
  br label %85

80:                                               ; preds = %56
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.editorConfig, ptr %81, i32 0, i32 0
  %83 = load i32, ptr %82, align 8, !tbaa !19
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %82, align 8, !tbaa !19
  br label %85

85:                                               ; preds = %80, %75
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.editorConfig, ptr %86, i32 0, i32 11
  %88 = load i32, ptr %87, align 8, !tbaa !25
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %87, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Editor13rowInsertCharEP7editRowiiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 8 dereferenceable(192)) #1 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!"_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, !13, i64 144, !16, i64 176, !15, i64 184}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!12, !10, i64 4}
!18 = !{!12, !10, i64 12}
!19 = !{!12, !10, i64 0}
!20 = !{!12, !10, i64 32}
!21 = !{!12, !6, i64 40}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!12, !10, i64 20}
!25 = !{!12, !10, i64 48}


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

@.str.13 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Editor9InsertRowEiPcmR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448), i32 noundef, ptr noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Editor10InsertCharEiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(192) %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !15
  %8 = add nsw i32 %7, %5
  %9 = getelementptr inbounds i8, ptr %2, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !16
  %11 = load i32, ptr %2, align 8, !tbaa !17
  %12 = add nsw i32 %11, %10
  %13 = getelementptr inbounds i8, ptr %2, i64 32
  %14 = load i32, ptr %13, align 8
  %15 = getelementptr inbounds i8, ptr %2, i64 40
  %.not2728 = icmp sgt i32 %14, %8
  br i1 %.not2728, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %16 = phi i32 [ %18, %.lr.ph ], [ %14, %3 ]
  %17 = tail call noalias ptr @strdup(ptr noundef nonnull @.str.13) #2
  tail call void @_ZN6Editor9InsertRowEiPcmR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, i32 noundef %16, ptr noundef %17, i64 noundef 0, ptr noundef nonnull align 8 dereferenceable(192) %2)
  %18 = load i32, ptr %13, align 8, !tbaa !18
  %.not27 = icmp sgt i32 %18, %8
  br i1 %.not27, label %.loopexit, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph, %3
  %19 = load ptr, ptr %15, align 8, !tbaa !21
  %20 = sext i32 %8 to i64
  %21 = getelementptr inbounds %struct.editRow, ptr %19, i64 %20
  tail call void @_ZN6Editor13rowInsertCharEP7editRowiiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef %21, i32 noundef %12, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(192) %2)
  %22 = load i32, ptr %2, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %2, i64 20
  %24 = load i32, ptr %23, align 4, !tbaa !22
  %25 = add nsw i32 %24, -1
  %26 = icmp eq i32 %22, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %.loopexit
  %28 = load i32, ptr %9, align 4, !tbaa !16
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %9, align 4, !tbaa !16
  br label %32

30:                                               ; preds = %.loopexit
  %31 = add nsw i32 %22, 1
  store i32 %31, ptr %2, align 8, !tbaa !17
  br label %32

32:                                               ; preds = %30, %27
  %33 = getelementptr inbounds i8, ptr %2, i64 48
  %34 = load i32, ptr %33, align 8, !tbaa !23
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %33, align 8, !tbaa !23
  ret void
}

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

; 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 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, !7, i64 8}
!6 = !{!"_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, !11, i64 144, !14, i64 176, !13, i64 184}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !8, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!6, !7, i64 4}
!16 = !{!6, !7, i64 12}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !7, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!6, !10, i64 40}
!22 = !{!6, !7, i64 20}
!23 = !{!6, !7, i64 48}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass