; LLVM IR from FRC-Utilities/LibDS :: src (string)

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

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.DS_StrJoin = external hidden unnamed_addr constant [47 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @DS_StrJoin(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %14

13:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 201, ptr noundef @__PRETTY_FUNCTION__.DS_StrJoin) #3
  unreachable

14:                                               ; preds = %12
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 202, ptr noundef @__PRETTY_FUNCTION__.DS_StrJoin) #3
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.DS_String, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  br label %26

25:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 203, ptr noundef @__PRETTY_FUNCTION__.DS_StrJoin) #3
  unreachable

26:                                               ; preds = %24
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.DS_String, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  br label %33

32:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 204, ptr noundef @__PRETTY_FUNCTION__.DS_StrJoin) #3
  unreachable

33:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.DS_String, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !12
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.DS_String, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !12
  %41 = trunc i64 %40 to i32
  store i32 %41, ptr %7, align 4, !tbaa !13
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !13
  %44 = load i32, ptr %6, align 4, !tbaa !13
  %45 = add nsw i32 %43, %44
  %46 = sext i32 %45 to i64
  %47 = call i32 @DS_StrResize(ptr noundef %42, i64 noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %74

49:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %50

50:                                               ; preds = %70, %49
  %51 = load i32, ptr %8, align 4, !tbaa !13
  %52 = load i32, ptr %6, align 4, !tbaa !13
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %73

54:                                               ; preds = %50
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.DS_String, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !13
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !15
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.DS_String, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = load i32, ptr %7, align 4, !tbaa !13
  %66 = load i32, ptr %8, align 4, !tbaa !13
  %67 = add nsw i32 %65, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %64, i64 %68
  store i8 %61, ptr %69, align 1, !tbaa !15
  br label %70

70:                                               ; preds = %54
  %71 = load i32, ptr %8, align 4, !tbaa !13
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !13
  br label %50, !llvm.loop !16

73:                                               ; preds = %50
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %75

74:                                               ; preds = %33
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %75

75:                                               ; preds = %74, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %76 = load i32, ptr %3, align 4
  ret i32 %76
}

attributes #0 = { noreturn 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { noreturn nounwind }
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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.DS_StrJoin = external hidden unnamed_addr constant [47 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @DS_StrResize(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @DS_StrJoin(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 201, ptr noundef nonnull @__PRETTY_FUNCTION__.DS_StrJoin) #2
  unreachable

4:                                                ; preds = %2
  %.not20 = icmp eq ptr %0, null
  br i1 %.not20, label %5, label %6

5:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 202, ptr noundef nonnull @__PRETTY_FUNCTION__.DS_StrJoin) #2
  unreachable

6:                                                ; preds = %4
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %.not21 = icmp eq ptr %7, null
  br i1 %.not21, label %8, label %9

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 203, ptr noundef nonnull @__PRETTY_FUNCTION__.DS_StrJoin) #2
  unreachable

9:                                                ; preds = %6
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %.not22 = icmp eq ptr %10, null
  br i1 %.not22, label %11, label %12

11:                                               ; preds = %9
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 204, ptr noundef nonnull @__PRETTY_FUNCTION__.DS_StrJoin) #2
  unreachable

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = add i64 %16, %14
  %sext = shl i64 %17, 32
  %18 = ashr exact i64 %sext, 32
  %19 = tail call i32 @DS_StrResize(ptr noundef nonnull %0, i64 noundef %18)
  %.not23 = icmp eq i32 %19, 0
  br i1 %.not23, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %12
  %20 = trunc i64 %14 to i32
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %sext26 = shl i64 %16, 32
  %22 = ashr exact i64 %sext26, 32
  %wide.trip.count = and i64 %14, 2147483647
  %23 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %14, 3
  %24 = icmp ult i64 %23, 3
  br i1 %24, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = sub nsw i64 %wide.trip.count, %xtraiter
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %25 = load ptr, ptr %1, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 %indvars.iv
  %27 = load i8, ptr %26, align 1, !tbaa !12
  %28 = load ptr, ptr %0, align 8, !tbaa !5
  %29 = getelementptr i8, ptr %28, i64 %indvars.iv
  %30 = getelementptr i8, ptr %29, i64 %22
  store i8 %27, ptr %30, align 1, !tbaa !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 %indvars.iv.next
  %33 = load i8, ptr %32, align 1, !tbaa !12
  %34 = load ptr, ptr %0, align 8, !tbaa !5
  %35 = getelementptr i8, ptr %34, i64 %indvars.iv.next
  %36 = getelementptr i8, ptr %35, i64 %22
  store i8 %33, ptr %36, align 1, !tbaa !12
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %37 = load ptr, ptr %1, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 %indvars.iv.next.1
  %39 = load i8, ptr %38, align 1, !tbaa !12
  %40 = load ptr, ptr %0, align 8, !tbaa !5
  %41 = getelementptr i8, ptr %40, i64 %indvars.iv.next.1
  %42 = getelementptr i8, ptr %41, i64 %22
  store i8 %39, ptr %42, align 1, !tbaa !12
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %43 = load ptr, ptr %1, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 %indvars.iv.next.2
  %45 = load i8, ptr %44, align 1, !tbaa !12
  %46 = load ptr, ptr %0, align 8, !tbaa !5
  %47 = getelementptr i8, ptr %46, i64 %indvars.iv.next.2
  %48 = getelementptr i8, ptr %47, i64 %22
  store i8 %45, ptr %48, align 1, !tbaa !12
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %49 = load ptr, ptr %1, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 %indvars.iv.epil
  %51 = load i8, ptr %50, align 1, !tbaa !12
  %52 = load ptr, ptr %0, align 8, !tbaa !5
  %53 = getelementptr i8, ptr %52, i64 %indvars.iv.epil
  %54 = getelementptr i8, ptr %53, i64 %22
  store i8 %51, ptr %54, align 1, !tbaa !12
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph.epil, !llvm.loop !15

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader, %12
  %.017 = phi i32 [ 0, %12 ], [ 1, %.preheader ], [ 1, %.lr.ph.epil ], [ 1, %.loopexit.loopexit.unr-lcssa ]
  ret i32 %.017
}

attributes #0 = { noreturn 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 #1 = { 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 #2 = { noreturn 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 0}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}


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