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

@z = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @NEW(ptr noundef, ptr noundef, ptr noundef, i32 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: nounwind uwtable
declare dso_local ptr @STrotR(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @STinsertT(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr @z, align 8, !tbaa !5
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %11, label %16

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr @z, align 8, !tbaa !5
  %14 = load ptr, ptr @z, align 8, !tbaa !5
  %15 = call ptr @NEW(ptr noundef %12, ptr noundef %13, ptr noundef %14, i32 noundef 1)
  store ptr %15, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %59

16:                                               ; preds = %2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.anon, ptr %17, i32 0, i32 0
  %19 = load i8, ptr %18, align 4, !tbaa !9
  store i8 %19, ptr %6, align 1, !tbaa !12
  %20 = load i8, ptr %6, align 1, !tbaa !12
  %21 = sext i8 %20 to i32
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.STnode, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds %struct.anon, ptr %24, i32 0, i32 0
  %26 = load i8, ptr %25, align 4, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp slt i32 %21, %27
  br i1 %28, label %29, label %43

29:                                               ; preds = %16
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.STnode, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call ptr @STinsertT(ptr noundef %32, ptr noundef %33)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.STnode, ptr %35, i32 0, i32 1
  store ptr %34, ptr %36, align 8, !tbaa !15
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.STnode, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !16
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 8, !tbaa !16
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = call ptr @STrotR(ptr noundef %41)
  store ptr %42, ptr %4, align 8, !tbaa !5
  br label %57

43:                                               ; preds = %16
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.STnode, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call ptr @STinsertT(ptr noundef %46, ptr noundef %47)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.STnode, ptr %49, i32 0, i32 2
  store ptr %48, ptr %50, align 8, !tbaa !17
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.STnode, ptr %51, i32 0, i32 3
  %53 = load i32, ptr %52, align 8, !tbaa !16
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %52, align 8, !tbaa !16
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = call ptr @STrotL(ptr noundef %55)
  store ptr %56, ptr %4, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %43, %29
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %58, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %59

59:                                               ; preds = %57, %11
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  %60 = load ptr, ptr %3, align 8
  ret ptr %60
}

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


; 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
declare dso_local ptr @NEW(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @STinsertT(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 %6

common.ret:                                       ; preds = %2
  %5 = tail call ptr @NEW(ptr noundef %1, ptr noundef %3, ptr noundef %3, i32 noundef 1)
  br label %common.ret19

6:                                                ; preds = %2
  %7 = load i8, ptr %1, align 4, !tbaa !9
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = load i8, ptr %8, align 4, !tbaa !9
  %10 = icmp slt i8 %7, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  br i1 %10, label %12, label %19

common.ret19:                                     ; preds = %19, %12, %common.ret
  %common.ret19.op = phi ptr [ %5, %common.ret ], [ %18, %12 ], [ %25, %19 ]
  ret ptr %common.ret19.op

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = tail call ptr @STinsertT(ptr noundef %14, ptr noundef nonnull %1)
  store ptr %15, ptr %13, align 8, !tbaa !14
  %16 = load i32, ptr %11, align 8, !tbaa !15
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %11, align 8, !tbaa !15
  %18 = tail call ptr @STrotR(ptr noundef nonnull %0)
  br label %common.ret19

19:                                               ; preds = %6
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = tail call ptr @STinsertT(ptr noundef %21, ptr noundef nonnull %1)
  store ptr %22, ptr %20, align 8, !tbaa !16
  %23 = load i32, ptr %11, align 8, !tbaa !15
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %11, align 8, !tbaa !15
  %25 = tail call ptr @STrotL(ptr noundef nonnull %0)
  br label %common.ret19
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"", !7, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"STnode", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !11, i64 24}
!16 = !{!13, !6, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass