; LLVM IR from pavlosdais/Abstract-Data-Types :: tests (test_RedBlackTree)

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

@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @acutest_check_(i32 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: noreturn nounwind uwtable
declare dso_local void @acutest_abort_() #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @createData(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @compareFunction(ptr noundef, ptr noundef) #0

declare ptr @rbt_create(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

declare void @rbt_destroy(ptr noundef) #3

; Function Attrs: nounwind
declare void @srand(i32 noundef) #4

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @create_shuffled_array(i32 noundef) #5

declare zeroext i1 @rbt_insert(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @test_traversal() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  %8 = call ptr @rbt_create(ptr noundef @compareFunction, ptr noundef @free)
  store ptr %8, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  %9 = call i64 @time(ptr noundef %2) #6
  %10 = trunc i64 %9 to i32
  call void @srand(i32 noundef %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %11 = call ptr @create_shuffled_array(i32 noundef 100000)
  store ptr %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %25, %0
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp ult i32 %13, 100000
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %28

16:                                               ; preds = %12
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %18, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = call ptr @createData(i32 noundef %22)
  %24 = call zeroext i1 @rbt_insert(ptr noundef %17, ptr noundef %23)
  br label %25

25:                                               ; preds = %16
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !11

28:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = call ptr @rbt_first(ptr noundef %29)
  store ptr %30, ptr %6, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %49, %28
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %54

35:                                               ; preds = %31
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call ptr @rbt_node_value(ptr noundef %37)
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = icmp eq i32 %39, %40
  %42 = zext i1 %41 to i32
  %43 = call i32 (i32, ptr, i32, ptr, ...) @acutest_check_(i32 noundef %42, ptr noundef @.str.38, i32 noundef 108, ptr noundef @.str.5, ptr noundef @.str.47)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %36
  call void @acutest_abort_() #7
  unreachable

46:                                               ; preds = %36
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = call ptr @rbt_find_next(ptr noundef %50)
  store ptr %51, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !9
  br label %31, !llvm.loop !13

54:                                               ; preds = %34
  store i32 99999, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %55 = load ptr, ptr %1, align 8, !tbaa !5
  %56 = call ptr @rbt_last(ptr noundef %55)
  store ptr %56, ptr %7, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %75, %54
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %80

61:                                               ; preds = %57
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = call ptr @rbt_node_value(ptr noundef %63)
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = icmp eq i32 %65, %66
  %68 = zext i1 %67 to i32
  %69 = call i32 (i32, ptr, i32, ptr, ...) @acutest_check_(i32 noundef %68, ptr noundef @.str.38, i32 noundef 113, ptr noundef @.str.5, ptr noundef @.str.47)
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %72, label %71

71:                                               ; preds = %62
  call void @acutest_abort_() #7
  unreachable

72:                                               ; preds = %62
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = call ptr @rbt_find_previous(ptr noundef %76)
  store ptr %77, ptr %7, align 8, !tbaa !5
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %5, align 4, !tbaa !9
  br label %57, !llvm.loop !14

80:                                               ; preds = %60
  %81 = load ptr, ptr %1, align 8, !tbaa !5
  call void @rbt_destroy(ptr noundef %81)
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %82) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret void
}

declare ptr @rbt_first(ptr noundef) #3

declare ptr @rbt_node_value(ptr noundef) #3

declare ptr @rbt_find_next(ptr noundef) #3

declare ptr @rbt_last(ptr noundef) #3

declare ptr @rbt_find_previous(ptr noundef) #3

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

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [39 x i8], align 1

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

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

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

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @acutest_abort_() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @createData(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @compareFunction(ptr noundef, ptr noundef) #0

declare ptr @rbt_create(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) #4

declare void @rbt_destroy(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @create_shuffled_array(i32 noundef) local_unnamed_addr #6

declare zeroext i1 @rbt_insert(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @test_traversal() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = tail call ptr @rbt_create(ptr noundef nonnull @compareFunction, ptr noundef nonnull @free) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #7
  %3 = call i64 @time(ptr noundef nonnull %1) #7
  %4 = trunc i64 %3 to i32
  call void @srand(i32 noundef %4) #7
  %5 = call ptr @create_shuffled_array(i32 noundef 100000)
  br label %8

6:                                                ; preds = %8
  %7 = call ptr @rbt_first(ptr noundef %2) #7
  %.not25 = icmp eq ptr %7, null
  br i1 %.not25, label %._crit_edge, label %.lr.ph

8:                                                ; preds = %0, %8
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %8 ]
  %9 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = call ptr @createData(i32 noundef %10)
  %12 = call zeroext i1 @rbt_insert(ptr noundef %2, ptr noundef %11) #7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100000
  br i1 %exitcond.not, label %6, label %8, !llvm.loop !9

._crit_edge:                                      ; preds = %20, %6
  %13 = call ptr @rbt_last(ptr noundef %2) #7
  %.not2128 = icmp eq ptr %13, null
  br i1 %.not2128, label %._crit_edge33, label %.lr.ph32

.lr.ph:                                           ; preds = %6, %20
  %.01827 = phi ptr [ %21, %20 ], [ %7, %6 ]
  %.01926 = phi i32 [ %22, %20 ], [ 0, %6 ]
  %14 = call ptr @rbt_node_value(ptr noundef nonnull %.01827) #7
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, %.01926
  %17 = zext i1 %16 to i32
  %18 = call i32 (i32, ptr, i32, ptr, ...) @acutest_check_(i32 noundef %17, ptr noundef nonnull @.str.38, i32 noundef 108, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.47)
  %.not23 = icmp eq i32 %18, 0
  br i1 %.not23, label %19, label %20

19:                                               ; preds = %.lr.ph
  call void @acutest_abort_() #8
  unreachable

20:                                               ; preds = %.lr.ph
  %21 = call ptr @rbt_find_next(ptr noundef nonnull %.01827) #7
  %22 = add nuw nsw i32 %.01926, 1
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge33:                                    ; preds = %29, %._crit_edge
  call void @rbt_destroy(ptr noundef %2) #7
  call void @free(ptr noundef %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #7
  ret void

.lr.ph32:                                         ; preds = %._crit_edge, %29
  %.030 = phi ptr [ %30, %29 ], [ %13, %._crit_edge ]
  %.129 = phi i32 [ %31, %29 ], [ 99999, %._crit_edge ]
  %23 = call ptr @rbt_node_value(ptr noundef nonnull %.030) #7
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp eq i32 %24, %.129
  %26 = zext i1 %25 to i32
  %27 = call i32 (i32, ptr, i32, ptr, ...) @acutest_check_(i32 noundef %26, ptr noundef nonnull @.str.38, i32 noundef 113, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.47)
  %.not22 = icmp eq i32 %27, 0
  br i1 %.not22, label %28, label %29

28:                                               ; preds = %.lr.ph32
  call void @acutest_abort_() #8
  unreachable

29:                                               ; preds = %.lr.ph32
  %30 = call ptr @rbt_find_previous(ptr noundef nonnull %.030) #7
  %31 = add nsw i32 %.129, -1
  %.not21 = icmp eq ptr %30, null
  br i1 %.not21, label %._crit_edge33, label %.lr.ph32, !llvm.loop !12
}

declare ptr @rbt_first(ptr noundef) local_unnamed_addr #3

declare ptr @rbt_node_value(ptr noundef) local_unnamed_addr #3

declare ptr @rbt_find_next(ptr noundef) local_unnamed_addr #3

declare ptr @rbt_last(ptr noundef) local_unnamed_addr #3

declare ptr @rbt_find_previous(ptr noundef) local_unnamed_addr #3

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn 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 = { "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 = { mustprogress nounwind willreturn allockind("free") 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 #5 = { 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 #6 = { inlinehint 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 #7 = { nounwind }
attributes #8 = { noreturn }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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