; LLVM IR from bartobri/data-structures-c :: symbol-table/binary-search-tree-root-insertion (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 { i32, 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 @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 i32, align 4
  %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 4, 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 %57

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 i32, ptr %18, align 4, !tbaa !9
  store i32 %19, ptr %6, align 4, !tbaa !12
  %20 = load i32, ptr %6, align 4, !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 i32, ptr %24, align 4, !tbaa !9
  %26 = icmp slt i32 %20, %25
  br i1 %26, label %27, label %41

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

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

55:                                               ; preds = %41, %27
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %57

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

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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, 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 @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 %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 i32, ptr %1, align 4, !tbaa !9
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = icmp slt i32 %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 @STinsertR(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 @STinsertR(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, !11, i64 0}
!10 = !{!"", !11, 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