; LLVM IR from HarshCasper/NeoAlgo :: C/ds (inorder_predecessor_successor)

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

@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [32 x i8], align 1

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

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

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

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

11:                                               ; preds = %39, %2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %20

14:                                               ; preds = %11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.tree, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp ne i32 %17, %18
  br label %20

20:                                               ; preds = %14, %11
  %21 = phi i1 [ false, %11 ], [ %19, %14 ]
  br i1 %21, label %22, label %40

22:                                               ; preds = %20
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tree, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = icmp sgt i32 %25, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %22
  store i32 1, ptr %8, align 4, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tree, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !11
  store i32 %31, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tree, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  store ptr %34, ptr %6, align 8, !tbaa !5
  br label %39

35:                                               ; preds = %22
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tree, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  store ptr %38, ptr %6, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %35, %28
  br label %11, !llvm.loop !15

40:                                               ; preds = %20
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %45

43:                                               ; preds = %40
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %81

45:                                               ; preds = %40
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tree, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %69

50:                                               ; preds = %45
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tree, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  store ptr %53, ptr %6, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %59, %50
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tree, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %63

59:                                               ; preds = %54
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.tree, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  store ptr %62, ptr %6, align 8, !tbaa !5
  br label %54, !llvm.loop !17

63:                                               ; preds = %54
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.tree, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !11
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %64, i32 noundef %67)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %81

69:                                               ; preds = %45
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = icmp eq i32 %70, 1
  br i1 %71, label %72, label %76

72:                                               ; preds = %69
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %73, i32 noundef %74)
  br label %79

76:                                               ; preds = %69
  %77 = load i32, ptr %5, align 4, !tbaa !9
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %77)
  br label %79

79:                                               ; preds = %76, %72
  br label %80

80:                                               ; preds = %79
  store i32 0, ptr %9, align 4
  br label %81

81:                                               ; preds = %80, %63, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %82 = load i32, ptr %9, align 4
  switch i32 %82, label %85 [
    i32 0, label %83
    i32 1, label %83
  ]

83:                                               ; preds = %81, %81
  %84 = load i32, ptr %3, align 4
  ret i32 %84

85:                                               ; preds = %81
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"tree", !6, i64 0, !10, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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"

@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [32 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @in_succ(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %cond35 = icmp eq ptr %0, null
  br i1 %cond35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %5
  %.038 = phi i32 [ %.1, %5 ], [ 0, %2 ]
  %.02037 = phi i32 [ %.121, %5 ], [ undef, %2 ]
  %.02236 = phi ptr [ %.123, %5 ], [ %0, %2 ]
  %3 = getelementptr inbounds i8, ptr %.02236, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not29 = icmp eq i32 %4, %1
  br i1 %.not29, label %.critedge, label %5

5:                                                ; preds = %.lr.ph
  %6 = icmp sgt i32 %4, %1
  %.123.in.idx = select i1 %6, i64 0, i64 16
  %.123.in = getelementptr inbounds i8, ptr %.02236, i64 %.123.in.idx
  %.121 = select i1 %6, i32 %4, i32 %.02037
  %.1 = select i1 %6, i32 1, i32 %.038
  %.123 = load ptr, ptr %.123.in, align 8, !tbaa !11
  %cond = icmp eq ptr %.123, null
  br i1 %cond, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %5, %2
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %21

.critedge:                                        ; preds = %.lr.ph
  %8 = getelementptr inbounds i8, ptr %.02236, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %.not30 = icmp eq ptr %9, null
  br i1 %.not30, label %15, label %.preheader

.preheader:                                       ; preds = %.critedge, %.preheader
  %.2 = phi ptr [ %10, %.preheader ], [ %9, %.critedge ]
  %10 = load ptr, ptr %.2, align 8, !tbaa !15
  %.not31 = icmp eq ptr %10, null
  br i1 %.not31, label %11, label %.preheader, !llvm.loop !16

11:                                               ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %.2, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %1, i32 noundef %13)
  br label %21

15:                                               ; preds = %.critedge
  %16 = icmp eq i32 %.038, 1
  br i1 %16, label %17, label %19

17:                                               ; preds = %15
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %1, i32 noundef %.02037)
  br label %21

19:                                               ; preds = %15
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %1)
  br label %21

21:                                               ; preds = %19, %17, %11, %._crit_edge
  ret i32 0
}

attributes #0 = { 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 #1 = { nofree 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, !10, i64 8}
!6 = !{!"tree", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass