; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Unit Test/Tests/DataStructuresTests/StringsTest/StringTest (StringTest)

; 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.ErrorTestStruct = type { i32 }
%struct.String = type { ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [150 x i8], align 1
@ERROR_TEST = external dso_local global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [19 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

declare ptr @stringInitialization(i32 noundef) #1

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #1

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

declare void @destroyString(ptr noundef) #1

declare void @stringRemove(ptr noundef, i32 noundef) #1

declare void @stringAppendC(ptr noundef, ptr noundef) #1

declare void @stringChangeStringC(ptr noundef, ptr noundef) #1

declare void @stringChangeStringS(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @testStringSubStringS(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = call ptr @stringInitialization(i32 noundef 1)
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = call ptr @stringInitialization(i32 noundef 10)
  store ptr %7, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @stringAppendC(ptr noundef %8, ptr noundef @.str.12)
  %9 = call i32 @stringSubStringS(ptr noundef null, ptr noundef null)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ErrorTestStruct, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %10, ptr noundef @.str, i32 noundef 302, ptr noundef null, i32 noundef -83386157, i32 noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call i32 @stringSubStringS(ptr noundef %14, ptr noundef null)
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ErrorTestStruct, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %16, ptr noundef @.str, i32 noundef 305, ptr noundef null, i32 noundef -83384987, i32 noundef %19)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  call void @stringChangeStringS(ptr noundef %20, ptr noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %22

22:                                               ; preds = %35, %1
  %23 = load i32, ptr %5, align 4, !tbaa !12
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.String, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %38

29:                                               ; preds = %22
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call i32 @stringSubStringS(ptr noundef %31, ptr noundef %32)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %30, ptr noundef @.str, i32 noundef 310, ptr noundef null, i32 noundef 1, i32 noundef %33)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @stringRemove(ptr noundef %34, i32 noundef 0)
  br label %35

35:                                               ; preds = %29
  %36 = load i32, ptr %5, align 4, !tbaa !12
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !12
  br label %22, !llvm.loop !15

38:                                               ; preds = %28
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  call void @stringChangeStringC(ptr noundef %39, ptr noundef @.str.8)
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call i32 @stringSubStringS(ptr noundef %41, ptr noundef %42)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %40, ptr noundef @.str, i32 noundef 315, ptr noundef null, i32 noundef 0, i32 noundef %43)
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @stringChangeStringC(ptr noundef %44, ptr noundef @.str.9)
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call i32 @stringSubStringS(ptr noundef %46, ptr noundef %47)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %45, ptr noundef @.str, i32 noundef 318, ptr noundef null, i32 noundef 0, i32 noundef %48)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  call void @stringChangeStringC(ptr noundef %49, ptr noundef @.str.10)
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call i32 @stringSubStringS(ptr noundef %51, ptr noundef %52)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %50, ptr noundef @.str, i32 noundef 321, ptr noundef null, i32 noundef 0, i32 noundef %53)
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @stringChangeStringC(ptr noundef %54, ptr noundef @.str.11)
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = call i32 @stringSubStringS(ptr noundef %56, ptr noundef %57)
  call void @CuAssertIntEquals_LineMsg(ptr noundef %55, ptr noundef @.str, i32 noundef 324, ptr noundef null, i32 noundef 0, i32 noundef %58)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  call void @destroyString(ptr noundef %59)
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyString(ptr noundef %60)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare i32 @stringSubStringS(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 = { 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 = { 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, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"String", !6, i64 0, !11, i64 8, !11, i64 12}
!15 = distinct !{!15, !16}
!16 = !{!"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 = external hidden unnamed_addr constant [150 x i8], align 1
@ERROR_TEST = external dso_local local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [19 x i8], align 1

declare ptr @stringInitialization(i32 noundef) local_unnamed_addr #0

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @destroyString(ptr noundef) local_unnamed_addr #0

declare void @stringRemove(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @stringAppendC(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @stringChangeStringC(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @stringChangeStringS(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @testStringSubStringS(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @stringInitialization(i32 noundef 1) #2
  %3 = tail call ptr @stringInitialization(i32 noundef 10) #2
  tail call void @stringAppendC(ptr noundef %3, ptr noundef nonnull @.str.12) #2
  %4 = tail call i32 @stringSubStringS(ptr noundef null, ptr noundef null) #2
  %5 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 302, ptr noundef null, i32 noundef -83386157, i32 noundef %6) #2
  %7 = tail call i32 @stringSubStringS(ptr noundef %2, ptr noundef null) #2
  %8 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %9 = load i32, ptr %8, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 305, ptr noundef null, i32 noundef -83384987, i32 noundef %9) #2
  tail call void @stringChangeStringS(ptr noundef %2, ptr noundef %3) #2
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  tail call void @stringChangeStringC(ptr noundef %3, ptr noundef nonnull @.str.8) #2
  %13 = tail call i32 @stringSubStringS(ptr noundef nonnull %2, ptr noundef %3) #2
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 315, ptr noundef null, i32 noundef 0, i32 noundef %13) #2
  tail call void @stringChangeStringC(ptr noundef %3, ptr noundef nonnull @.str.9) #2
  %14 = tail call i32 @stringSubStringS(ptr noundef nonnull %2, ptr noundef %3) #2
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 318, ptr noundef null, i32 noundef 0, i32 noundef %14) #2
  tail call void @stringChangeStringC(ptr noundef %3, ptr noundef nonnull @.str.10) #2
  %15 = tail call i32 @stringSubStringS(ptr noundef nonnull %2, ptr noundef %3) #2
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 321, ptr noundef null, i32 noundef 0, i32 noundef %15) #2
  tail call void @stringChangeStringC(ptr noundef %3, ptr noundef nonnull @.str.11) #2
  %16 = tail call i32 @stringSubStringS(ptr noundef nonnull %2, ptr noundef %3) #2
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 324, ptr noundef null, i32 noundef 0, i32 noundef %16) #2
  tail call void @destroyString(ptr noundef %3) #2
  tail call void @destroyString(ptr noundef nonnull %2) #2
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.030 = phi i32 [ %18, %.lr.ph ], [ 0, %1 ]
  %17 = tail call i32 @stringSubStringS(ptr noundef nonnull %2, ptr noundef %3) #2
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 310, ptr noundef null, i32 noundef 1, i32 noundef %17) #2
  tail call void @stringRemove(ptr noundef %3, i32 noundef 0) #2
  %18 = add nuw nsw i32 %.030, 1
  %19 = load i32, ptr %10, align 8, !tbaa !12
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

declare i32 @stringSubStringS(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"String", !6, i64 0, !11, i64 8, !11, i64 12}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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