; LLVM IR from acm-clan/algorithm-stone :: templates/rb.ll (Z5main2v)

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

%class.RBTree = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5main2v() #0 {
  %1 = alloca %class.RBTree, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #5
  call void @_ZN6RBTreeC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 100, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %20, %0
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %13, i32 noundef %14)
  %16 = call i32 @rand() #5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = srem i32 %16, %17
  %19 = load i32, ptr %3, align 4, !tbaa !5
  call void @_ZN6RBTree3setEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %18, i32 noundef %19)
  br label %20

20:                                               ; preds = %12
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !9

23:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %33, %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %24
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %30)
  %32 = load i32, ptr %4, align 4, !tbaa !5
  call void @_ZN6RBTree6removeEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %32)
  br label %33

33:                                               ; preds = %29
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !5
  br label %24, !llvm.loop !11

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %45, %36
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %48

42:                                               ; preds = %37
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  call void @_ZN6RBTree3setEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %43, i32 noundef %44)
  br label %45

45:                                               ; preds = %42
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %5, align 4, !tbaa !5
  br label %37, !llvm.loop !12

48:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %59, %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %62

54:                                               ; preds = %49
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = call noundef i32 @_ZN6RBTree3getEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %56)
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %55, i32 noundef %57)
  br label %59

59:                                               ; preds = %54
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !5
  br label %49, !llvm.loop !13

62:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #5
  ret i32 0
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6RBTreeC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6RBTree3setEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) #0 align 2

; Function Attrs: nounwind
declare i32 @rand() #4

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6RBTree6removeEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6RBTree3getEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #0 align 2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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

%class.RBTree = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5main2v() local_unnamed_addr #0 {
  %1 = alloca %class.RBTree, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #5
  call void @_ZN6RBTreeC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1)
  br label %2

2:                                                ; preds = %0, %2
  %.02427 = phi i32 [ 1, %0 ], [ %6, %2 ]
  %3 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.02427, i32 noundef %.02427)
  %4 = call i32 @rand() #5
  %5 = srem i32 %4, 100
  call void @_ZN6RBTree3setEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %5, i32 noundef %.02427)
  %6 = add nuw nsw i32 %.02427, 1
  %exitcond.not = icmp eq i32 %6, 101
  br i1 %exitcond.not, label %.preheader26, label %2, !llvm.loop !5

.preheader26:                                     ; preds = %2, %.preheader26
  %.02328 = phi i32 [ %8, %.preheader26 ], [ 1, %2 ]
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.02328)
  call void @_ZN6RBTree6removeEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.02328)
  %8 = add nuw nsw i32 %.02328, 1
  %exitcond31.not = icmp eq i32 %8, 101
  br i1 %exitcond31.not, label %.preheader25, label %.preheader26, !llvm.loop !7

.preheader25:                                     ; preds = %.preheader26, %.preheader25
  %.02229 = phi i32 [ %9, %.preheader25 ], [ 1, %.preheader26 ]
  call void @_ZN6RBTree3setEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.02229, i32 noundef %.02229)
  %9 = add nuw nsw i32 %.02229, 1
  %exitcond32.not = icmp eq i32 %9, 101
  br i1 %exitcond32.not, label %.preheader, label %.preheader25, !llvm.loop !8

10:                                               ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #5
  ret i32 0

.preheader:                                       ; preds = %.preheader25, %.preheader
  %.030 = phi i32 [ %13, %.preheader ], [ 1, %.preheader25 ]
  %11 = call noundef i32 @_ZN6RBTree3getEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.030)
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %.030, i32 noundef %11)
  %13 = add nuw nsw i32 %.030, 1
  %exitcond33.not = icmp eq i32 %13, 101
  br i1 %exitcond33.not, label %10, label %.preheader, !llvm.loop !9
}

; 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 nounwind uwtable
declare dso_local void @_ZN6RBTreeC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #4

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6RBTree3getEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { nofree 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 #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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = distinct !{!9, !6}


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