; LLVM IR from kaynewbie/algorithm :: algorithm/CodingInterviews (binary-tree-iterate)

; 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.Node = type { i64, i32, ptr, ptr }
%struct.s = type { ptr, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 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

declare ptr @createStack(i32 noundef, i32 noundef) #1

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

declare i32 @stackPush(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i32 @stackPop(ptr noundef, ptr noundef) #1

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

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

11:                                               ; preds = %74, %1
  br label %12

12:                                               ; preds = %26, %11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %33

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Node, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %26

20:                                               ; preds = %15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call i32 @stackPush(ptr noundef %21, ptr noundef %24)
  br label %26

26:                                               ; preds = %20, %15
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call i32 @stackPush(ptr noundef %27, ptr noundef %28)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Node, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  store ptr %32, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !14

33:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %34 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %34, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @stackPop(ptr noundef %35, ptr noundef %36)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %38, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %39 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = call i32 @stackTop(ptr noundef %40, ptr noundef %41)
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %68

47:                                               ; preds = %33
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !16
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Node, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.Node, ptr %53, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !16
  %56 = icmp eq i64 %50, %55
  br i1 %56, label %57, label %68

57:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %58 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %58, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = call i32 @stackPop(ptr noundef %59, ptr noundef %60)
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call i32 @stackPush(ptr noundef %62, ptr noundef %63)
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Node, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  store ptr %67, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %73

68:                                               ; preds = %47, %33
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Node, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 8, !tbaa !17
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %71)
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %68, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.s, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 8, !tbaa !18
  %78 = icmp sge i32 %77, 0
  br i1 %78, label %11, label %79, !llvm.loop !20

79:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare i32 @stackTop(ptr noundef, ptr noundef) #1

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 allocsize(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 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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, !6, i64 24}
!10 = !{!"Node", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !11, i64 0}
!17 = !{!10, !12, i64 8}
!18 = !{!19, !12, i64 8}
!19 = !{!"s", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!20 = distinct !{!20, !15}


; 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 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1

declare ptr @createStack(i32 noundef, i32 noundef) local_unnamed_addr #0

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

declare i32 @stackPush(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare i32 @stackPop(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @postOrderCycle(ptr noundef %0) local_unnamed_addr #3 {
  %2 = tail call ptr @createStack(i32 noundef 32, i32 noundef 10) #4
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  br label %5

5:                                                ; preds = %33, %1
  %.0 = phi ptr [ %0, %1 ], [ %.2, %33 ]
  %.not27 = icmp eq ptr %.0, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %10
  %.128 = phi ptr [ %13, %10 ], [ %.0, %5 ]
  %6 = getelementptr inbounds i8, ptr %.128, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not26 = icmp eq ptr %7, null
  br i1 %.not26, label %10, label %8

8:                                                ; preds = %.lr.ph
  %9 = tail call i32 @stackPush(ptr noundef %2, ptr noundef nonnull %7) #4
  br label %10

10:                                               ; preds = %8, %.lr.ph
  %11 = tail call i32 @stackPush(ptr noundef %2, ptr noundef nonnull %.128) #4
  %12 = getelementptr inbounds i8, ptr %.128, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %10, %5
  %14 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #5
  %15 = tail call i32 @stackPop(ptr noundef %2, ptr noundef %14) #4
  %16 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #5
  %17 = tail call i32 @stackTop(ptr noundef %2, ptr noundef %16) #4
  %18 = getelementptr inbounds i8, ptr %14, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not25 = icmp eq ptr %19, null
  br i1 %.not25, label %29, label %20

20:                                               ; preds = %._crit_edge
  %21 = load i64, ptr %16, align 8, !tbaa !15
  %22 = load i64, ptr %19, align 8, !tbaa !15
  %23 = icmp eq i64 %21, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #5
  %26 = tail call i32 @stackPop(ptr noundef %2, ptr noundef %25) #4
  %27 = tail call i32 @stackPush(ptr noundef %2, ptr noundef nonnull %14) #4
  %28 = load ptr, ptr %18, align 8, !tbaa !5
  br label %33

29:                                               ; preds = %20, %._crit_edge
  %30 = getelementptr inbounds i8, ptr %14, i64 8
  %31 = load i32, ptr %30, align 8, !tbaa !16
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %31)
  br label %33

33:                                               ; preds = %29, %24
  %.2 = phi ptr [ %28, %24 ], [ null, %29 ]
  %34 = load i32, ptr %4, align 8, !tbaa !17
  %35 = icmp sgt i32 %34, -1
  br i1 %35, label %5, label %36, !llvm.loop !19

36:                                               ; preds = %33
  ret void
}

declare i32 @stackTop(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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, !11, i64 24}
!6 = !{!"Node", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !10, i64 8}
!17 = !{!18, !10, i64 8}
!18 = !{!"s", !11, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!19 = distinct !{!19, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass