; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Unit Test/CuTest (CuTest)

; 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.CuSuite = type { i32, [1024 x ptr], i32 }
%struct.CuTest = type { ptr, ptr, i32, i32, ptr, ptr }

@.str.13 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [11 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: nounwind uwtable
declare dso_local void @CuStringAppend(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @CuStringAppendFormat(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @CuSuiteDetails(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.CuSuite, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %29

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.CuSuite, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.CuSuite, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = sub nsw i32 %17, %20
  store i32 %21, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 1
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, ptr @.str.13, ptr @.str.14
  store ptr %25, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %26, ptr noundef @.str.15, i32 noundef %27, ptr noundef %28)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %92

29:                                               ; preds = %2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.CuSuite, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  call void @CuStringAppend(ptr noundef %35, ptr noundef @.str.16)
  br label %41

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.CuSuite, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !11
  call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %37, ptr noundef @.str.17, i32 noundef %40)
  br label %41

41:                                               ; preds = %36, %34
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %71, %41
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.CuSuite, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !13
  %47 = icmp slt i32 %43, %46
  br i1 %47, label %48, label %74

48:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.CuSuite, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1024 x ptr], ptr %50, i64 0, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %9, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.CuTest, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !14
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %70

59:                                               ; preds = %48
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.CuTest, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.CuTest, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %62, ptr noundef @.str.18, i32 noundef %63, ptr noundef %66, ptr noundef %69)
  br label %70

70:                                               ; preds = %59, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %5, align 4, !tbaa !9
  br label %42, !llvm.loop !18

74:                                               ; preds = %42
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  call void @CuStringAppend(ptr noundef %75, ptr noundef @.str.19)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.CuSuite, ptr %77, i32 0, i32 0
  %79 = load i32, ptr %78, align 8, !tbaa !13
  call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %76, ptr noundef @.str.20, i32 noundef %79)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.CuSuite, ptr %81, i32 0, i32 0
  %83 = load i32, ptr %82, align 8, !tbaa !13
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.CuSuite, ptr %84, i32 0, i32 2
  %86 = load i32, ptr %85, align 8, !tbaa !11
  %87 = sub nsw i32 %83, %86
  call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %80, ptr noundef @.str.21, i32 noundef %87)
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.CuSuite, ptr %89, i32 0, i32 2
  %91 = load i32, ptr %90, align 8, !tbaa !11
  call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %88, ptr noundef @.str.22, i32 noundef %91)
  br label %92

92:                                               ; preds = %74, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8200}
!12 = !{!"", !10, i64 0, !7, i64 8, !10, i64 8200}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !10, i64 16}
!15 = !{!"CuTest", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32}
!16 = !{!15, !6, i64 0}
!17 = !{!15, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"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.13 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @CuStringAppend(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @CuStringAppendFormat(ptr noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @CuSuiteDetails(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8200
  %4 = load i32, ptr %3, align 8, !tbaa !5
  switch i32 %4, label %10 [
    i32 0, label %5
    i32 1, label %9
  ]

5:                                                ; preds = %2
  %6 = load i32, ptr %0, align 8, !tbaa !10
  %7 = icmp eq i32 %6, 1
  %8 = select i1 %7, ptr @.str.13, ptr @.str.14
  tail call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %1, ptr noundef nonnull @.str.15, i32 noundef %6, ptr noundef nonnull %8)
  br label %35

9:                                                ; preds = %2
  tail call void @CuStringAppend(ptr noundef %1, ptr noundef nonnull @.str.16)
  br label %11

10:                                               ; preds = %2
  tail call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %1, ptr noundef nonnull @.str.17, i32 noundef %4)
  br label %11

11:                                               ; preds = %10, %9
  %12 = load i32, ptr %0, align 8, !tbaa !10
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  br label %15

15:                                               ; preds = %.lr.ph, %26
  %16 = phi i32 [ %12, %.lr.ph ], [ %27, %26 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %.02932 = phi i32 [ 0, %.lr.ph ], [ %.1, %26 ]
  %17 = getelementptr inbounds [1024 x ptr], ptr %14, i64 0, i64 %indvars.iv
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %26, label %21

21:                                               ; preds = %15
  %22 = add nsw i32 %.02932, 1
  %23 = load ptr, ptr %18, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %18, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  tail call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %1, ptr noundef nonnull @.str.18, i32 noundef %22, ptr noundef %23, ptr noundef %25)
  %.pre = load i32, ptr %0, align 8, !tbaa !10
  br label %26

26:                                               ; preds = %21, %15
  %27 = phi i32 [ %.pre, %21 ], [ %16, %15 ]
  %.1 = phi i32 [ %22, %21 ], [ %.02932, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next, %28
  br i1 %29, label %15, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %26, %11
  tail call void @CuStringAppend(ptr noundef %1, ptr noundef nonnull @.str.19)
  %30 = load i32, ptr %0, align 8, !tbaa !10
  tail call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %1, ptr noundef nonnull @.str.20, i32 noundef %30)
  %31 = load i32, ptr %0, align 8, !tbaa !10
  %32 = load i32, ptr %3, align 8, !tbaa !5
  %33 = sub nsw i32 %31, %32
  tail call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %1, ptr noundef nonnull @.str.21, i32 noundef %33)
  %34 = load i32, ptr %3, align 8, !tbaa !5
  tail call void (ptr, ptr, ...) @CuStringAppendFormat(ptr noundef %1, ptr noundef nonnull @.str.22, i32 noundef %34)
  br label %35

35:                                               ; preds = %._crit_edge, %5
  ret void
}

attributes #0 = { 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, !7, i64 8200}
!6 = !{!"", !7, i64 0, !8, i64 8, !7, i64 8200}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !7, i64 16}
!14 = !{!"CuTest", !12, i64 0, !12, i64 8, !7, i64 16, !7, i64 20, !12, i64 24, !12, i64 32}
!15 = !{!14, !12, i64 0}
!16 = !{!14, !12, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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