; LLVM IR from bartobri/data-structures-c :: symbol-table/binary-search-tree-randomized-insertion-deletion (st)

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

@z = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @STjoinLR(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr @z, align 8, !tbaa !5
  %8 = icmp eq ptr %6, %7
  br i1 %8, label %9, label %11

9:                                                ; preds = %2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %3, align 8
  br label %79

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr @z, align 8, !tbaa !5
  %14 = icmp eq ptr %12, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %3, align 8
  br label %79

17:                                               ; preds = %11
  %18 = call i32 @rand() #2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.STnode, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.STnode, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = add nsw i32 %21, %24
  %26 = sdiv i32 2147483647, %25
  %27 = add nsw i32 %26, 1
  %28 = sdiv i32 %18, %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.STnode, ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 8, !tbaa !9
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %33, label %56

33:                                               ; preds = %17
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.STnode, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !12
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call ptr @STjoinLR(ptr noundef %36, ptr noundef %37)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.STnode, ptr %39, i32 0, i32 2
  store ptr %38, ptr %40, align 8, !tbaa !12
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.STnode, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  %44 = getelementptr inbounds %struct.STnode, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.STnode, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = getelementptr inbounds %struct.STnode, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 8, !tbaa !9
  %51 = add nsw i32 %45, %50
  %52 = add nsw i32 %51, 1
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.STnode, ptr %53, i32 0, i32 3
  store i32 %52, ptr %54, align 8, !tbaa !9
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %55, ptr %3, align 8
  br label %79

56:                                               ; preds = %17
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.STnode, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = call ptr @STjoinLR(ptr noundef %57, ptr noundef %60)
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.STnode, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !13
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.STnode, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !12
  %67 = getelementptr inbounds %struct.STnode, ptr %66, i32 0, i32 3
  %68 = load i32, ptr %67, align 8, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.STnode, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = getelementptr inbounds %struct.STnode, ptr %71, i32 0, i32 3
  %73 = load i32, ptr %72, align 8, !tbaa !9
  %74 = add nsw i32 %68, %73
  %75 = add nsw i32 %74, 1
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.STnode, ptr %76, i32 0, i32 3
  store i32 %75, ptr %77, align 8, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %78, ptr %3, align 8
  br label %79

79:                                               ; preds = %56, %33, %15, %9
  %80 = load ptr, ptr %3, align 8
  ret ptr %80
}

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

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 = { 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 #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 24}
!10 = !{!"STnode", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 8}


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

@z = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @STjoinLR(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @z, align 8, !tbaa !5
  %4 = icmp eq ptr %3, %0
  br i1 %4, label %common.ret, label %5

5:                                                ; preds = %2
  %6 = icmp eq ptr %3, %1
  br i1 %6, label %common.ret, label %7

7:                                                ; preds = %5
  %8 = tail call i32 @rand() #2
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %1, i64 24
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = add nsw i32 %12, %10
  %14 = sdiv i32 2147483647, %13
  %15 = add nsw i32 %14, 1
  %16 = sdiv i32 %8, %15
  %17 = icmp slt i32 %16, %10
  br i1 %17, label %22, label %28

common.ret.sink.split:                            ; preds = %22, %28
  %.sink29 = phi ptr [ %31, %28 ], [ %27, %22 ]
  %.pn = phi ptr [ %33, %28 ], [ %25, %22 ]
  %.sink25 = phi ptr [ %11, %28 ], [ %9, %22 ]
  %common.ret.op.ph = phi ptr [ %1, %28 ], [ %0, %22 ]
  %.sink.in = getelementptr inbounds i8, ptr %.pn, i64 24
  %.sink = load i32, ptr %.sink.in, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %.sink29, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = add i32 %.sink, 1
  %21 = add i32 %20, %19
  store i32 %21, ptr %.sink25, align 8, !tbaa !9
  br label %common.ret

common.ret:                                       ; preds = %common.ret.sink.split, %2, %5
  %common.ret.op = phi ptr [ %1, %2 ], [ %0, %5 ], [ %common.ret.op.ph, %common.ret.sink.split ]
  ret ptr %common.ret.op

22:                                               ; preds = %7
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = tail call ptr @STjoinLR(ptr noundef %24, ptr noundef nonnull %1)
  store ptr %25, ptr %23, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  br label %common.ret.sink.split

28:                                               ; preds = %7
  %29 = getelementptr inbounds i8, ptr %1, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = tail call ptr @STjoinLR(ptr noundef nonnull %0, ptr noundef %30)
  store ptr %31, ptr %29, align 8, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %1, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !12
  br label %common.ret.sink.split
}

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

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 = { 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 #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 24}
!10 = !{!"STnode", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass