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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @createTree() #0 {
  %1 = alloca i32, align 4
  %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
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = call noalias ptr @malloc(i64 noundef %12) #4
  store ptr %13, ptr %2, align 8, !tbaa !9
  %14 = load ptr, ptr %2, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.TripleDirectionNode, ptr %14, i32 0, i32 0
  store i32 1, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = call noalias ptr @malloc(i64 noundef %17) #4
  store ptr %18, ptr %3, align 8, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.TripleDirectionNode, ptr %19, i32 0, i32 0
  store i32 2, ptr %20, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = call noalias ptr @malloc(i64 noundef %22) #4
  store ptr %23, ptr %4, align 8, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.TripleDirectionNode, ptr %24, i32 0, i32 0
  store i32 3, ptr %25, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = call noalias ptr @malloc(i64 noundef %27) #4
  store ptr %28, ptr %5, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.TripleDirectionNode, ptr %29, i32 0, i32 0
  store i32 4, ptr %30, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = call noalias ptr @malloc(i64 noundef %32) #4
  store ptr %33, ptr %6, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.TripleDirectionNode, ptr %34, i32 0, i32 0
  store i32 5, ptr %35, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = call noalias ptr @malloc(i64 noundef %37) #4
  store ptr %38, ptr %7, align 8, !tbaa !9
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.TripleDirectionNode, ptr %39, i32 0, i32 0
  store i32 6, ptr %40, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = call noalias ptr @malloc(i64 noundef %42) #4
  store ptr %43, ptr %8, align 8, !tbaa !9
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.TripleDirectionNode, ptr %44, i32 0, i32 0
  store i32 10, ptr %45, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = call noalias ptr @malloc(i64 noundef %47) #4
  store ptr %48, ptr %9, align 8, !tbaa !9
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.TripleDirectionNode, ptr %49, i32 0, i32 0
  store i32 11, ptr %50, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = call noalias ptr @malloc(i64 noundef %52) #4
  store ptr %53, ptr %10, align 8, !tbaa !9
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.TripleDirectionNode, ptr %54, i32 0, i32 0
  store i32 12, ptr %55, align 8, !tbaa !11
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.TripleDirectionNode, ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !13
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.TripleDirectionNode, ptr %60, i32 0, i32 2
  store ptr %59, ptr %61, align 8, !tbaa !14
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.TripleDirectionNode, ptr %63, i32 0, i32 3
  store ptr %62, ptr %64, align 8, !tbaa !15
  %65 = load ptr, ptr %4, align 8, !tbaa !9
  %66 = load ptr, ptr %5, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.TripleDirectionNode, ptr %66, i32 0, i32 1
  store ptr %65, ptr %67, align 8, !tbaa !13
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.TripleDirectionNode, ptr %69, i32 0, i32 2
  store ptr %68, ptr %70, align 8, !tbaa !14
  %71 = load ptr, ptr %7, align 8, !tbaa !9
  %72 = load ptr, ptr %6, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.TripleDirectionNode, ptr %72, i32 0, i32 3
  store ptr %71, ptr %73, align 8, !tbaa !15
  %74 = load ptr, ptr %2, align 8, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.TripleDirectionNode, ptr %75, i32 0, i32 1
  store ptr %74, ptr %76, align 8, !tbaa !13
  %77 = load ptr, ptr %3, align 8, !tbaa !9
  %78 = load ptr, ptr %6, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.TripleDirectionNode, ptr %78, i32 0, i32 2
  store ptr %77, ptr %79, align 8, !tbaa !14
  %80 = load ptr, ptr %5, align 8, !tbaa !9
  %81 = load ptr, ptr %4, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.TripleDirectionNode, ptr %81, i32 0, i32 3
  store ptr %80, ptr %82, align 8, !tbaa !15
  %83 = load ptr, ptr %4, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.TripleDirectionNode, ptr %83, i32 0, i32 1
  store ptr null, ptr %84, align 8, !tbaa !13
  %85 = load ptr, ptr %4, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.TripleDirectionNode, ptr %85, i32 0, i32 2
  store ptr null, ptr %86, align 8, !tbaa !14
  %87 = load ptr, ptr %6, align 8, !tbaa !9
  %88 = load ptr, ptr %3, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.TripleDirectionNode, ptr %88, i32 0, i32 3
  store ptr %87, ptr %89, align 8, !tbaa !15
  %90 = load ptr, ptr %9, align 8, !tbaa !9
  %91 = load ptr, ptr %3, align 8, !tbaa !9
  %92 = getelementptr inbounds %struct.TripleDirectionNode, ptr %91, i32 0, i32 1
  store ptr %90, ptr %92, align 8, !tbaa !13
  %93 = load ptr, ptr %3, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.TripleDirectionNode, ptr %93, i32 0, i32 2
  store ptr null, ptr %94, align 8, !tbaa !14
  %95 = load ptr, ptr %6, align 8, !tbaa !9
  %96 = load ptr, ptr %2, align 8, !tbaa !9
  %97 = getelementptr inbounds %struct.TripleDirectionNode, ptr %96, i32 0, i32 3
  store ptr %95, ptr %97, align 8, !tbaa !15
  %98 = load ptr, ptr %2, align 8, !tbaa !9
  %99 = getelementptr inbounds %struct.TripleDirectionNode, ptr %98, i32 0, i32 1
  store ptr null, ptr %99, align 8, !tbaa !13
  %100 = load ptr, ptr %2, align 8, !tbaa !9
  %101 = getelementptr inbounds %struct.TripleDirectionNode, ptr %100, i32 0, i32 2
  store ptr null, ptr %101, align 8, !tbaa !14
  %102 = load ptr, ptr %5, align 8, !tbaa !9
  %103 = load ptr, ptr %8, align 8, !tbaa !9
  %104 = getelementptr inbounds %struct.TripleDirectionNode, ptr %103, i32 0, i32 3
  store ptr %102, ptr %104, align 8, !tbaa !15
  %105 = load ptr, ptr %8, align 8, !tbaa !9
  %106 = getelementptr inbounds %struct.TripleDirectionNode, ptr %105, i32 0, i32 1
  store ptr null, ptr %106, align 8, !tbaa !13
  %107 = load ptr, ptr %8, align 8, !tbaa !9
  %108 = getelementptr inbounds %struct.TripleDirectionNode, ptr %107, i32 0, i32 2
  store ptr null, ptr %108, align 8, !tbaa !14
  %109 = load ptr, ptr %3, align 8, !tbaa !9
  %110 = load ptr, ptr %9, align 8, !tbaa !9
  %111 = getelementptr inbounds %struct.TripleDirectionNode, ptr %110, i32 0, i32 3
  store ptr %109, ptr %111, align 8, !tbaa !15
  %112 = load ptr, ptr %10, align 8, !tbaa !9
  %113 = load ptr, ptr %9, align 8, !tbaa !9
  %114 = getelementptr inbounds %struct.TripleDirectionNode, ptr %113, i32 0, i32 1
  store ptr %112, ptr %114, align 8, !tbaa !13
  %115 = load ptr, ptr %9, align 8, !tbaa !9
  %116 = getelementptr inbounds %struct.TripleDirectionNode, ptr %115, i32 0, i32 2
  store ptr null, ptr %116, align 8, !tbaa !14
  %117 = load ptr, ptr %9, align 8, !tbaa !9
  %118 = load ptr, ptr %10, align 8, !tbaa !9
  %119 = getelementptr inbounds %struct.TripleDirectionNode, ptr %118, i32 0, i32 3
  store ptr %117, ptr %119, align 8, !tbaa !15
  %120 = load ptr, ptr %10, align 8, !tbaa !9
  %121 = getelementptr inbounds %struct.TripleDirectionNode, ptr %120, i32 0, i32 1
  store ptr null, ptr %121, align 8, !tbaa !13
  %122 = load ptr, ptr %10, align 8, !tbaa !9
  %123 = getelementptr inbounds %struct.TripleDirectionNode, ptr %122, i32 0, i32 2
  store ptr null, ptr %123, align 8, !tbaa !14
  %124 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret ptr %124
}

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

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

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

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


; 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"

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local noundef ptr @createTree() local_unnamed_addr #0 {
  %1 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 1, ptr %1, align 8, !tbaa !5
  %2 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 2, ptr %2, align 8, !tbaa !5
  %3 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 3, ptr %3, align 8, !tbaa !5
  %4 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 4, ptr %4, align 8, !tbaa !5
  %5 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 5, ptr %5, align 8, !tbaa !5
  %6 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 6, ptr %6, align 8, !tbaa !5
  %7 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 10, ptr %7, align 8, !tbaa !5
  %8 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 11, ptr %8, align 8, !tbaa !5
  %9 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 12, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %4, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %5, ptr %11, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %6, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %3, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %7, ptr %14, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %6, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %1, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %2, ptr %17, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %4, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %3, i64 8
  %20 = getelementptr inbounds i8, ptr %2, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %19, i8 0, i64 16, i1 false)
  store ptr %5, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %8, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr null, ptr %22, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr %5, ptr %23, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  %25 = getelementptr inbounds i8, ptr %7, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %24, i8 0, i64 16, i1 false)
  store ptr %4, ptr %25, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %7, i64 8
  %27 = getelementptr inbounds i8, ptr %8, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %26, i8 0, i64 16, i1 false)
  store ptr %2, ptr %27, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %9, ptr %28, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr null, ptr %29, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr %8, ptr %30, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %9, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %31, i8 0, i64 16, i1 false)
  ret ptr %6
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite) 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 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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, !7, i64 0}
!6 = !{!"TripleDirectionNode", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 24}


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