; 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
declare i32 @rand() #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @STinsertR(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 i8, align 1
  %8 = 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) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr @z, align 8, !tbaa !5
  %11 = icmp eq ptr %9, %10
  br i1 %11, label %12, label %17

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

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

33:                                               ; preds = %17
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call ptr @STinsertT(ptr noundef %34, ptr noundef %35)
  store ptr %36, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %65

37:                                               ; preds = %17
  %38 = load i8, ptr %6, align 1, !tbaa !12
  %39 = sext i8 %38 to i32
  %40 = load i8, ptr %7, align 1, !tbaa !12
  %41 = sext i8 %40 to i32
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %37
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.STnode, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call ptr @STinsertR(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 1
  store ptr %48, ptr %50, align 8, !tbaa !16
  br label %59

51:                                               ; preds = %37
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.STnode, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = call ptr @STinsertR(ptr noundef %54, ptr noundef %55)
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.STnode, ptr %57, i32 0, i32 2
  store ptr %56, ptr %58, align 8, !tbaa !17
  br label %59

59:                                               ; preds = %51, %43
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.STnode, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 8, !tbaa !15
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %61, align 8, !tbaa !15
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %64, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %65

65:                                               ; preds = %59, %33, %12
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %66 = load ptr, ptr %3, align 8
  ret ptr %66
}

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 "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 = { 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, !11, i64 24}
!16 = !{!14, !6, i64 8}
!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
declare i32 @rand() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @STinsertR(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 %5, label %7

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

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

17:                                               ; preds = %7
  %18 = tail call ptr @STinsertT(ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %common.ret

common.ret:                                       ; preds = %5, %17, %19
  %common.ret.op = phi ptr [ %0, %19 ], [ %6, %5 ], [ %18, %17 ]
  ret ptr %common.ret.op

19:                                               ; preds = %7
  %20 = icmp slt i8 %8, %10
  %. = select i1 %20, i64 8, i64 16
  %21 = getelementptr inbounds i8, ptr %0, i64 %.
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = tail call ptr @STinsertR(ptr noundef %22, ptr noundef nonnull %1)
  store ptr %23, ptr %21, align 8, !tbaa !5
  %24 = load i32, ptr %12, align 8, !tbaa !14
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %12, align 8, !tbaa !14
  br label %common.ret
}

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, !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, !11, i64 24}


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