; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (homework_btree)

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

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

; Function Attrs: nounwind uwtable
define dso_local void @create_btree(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [30 x ptr], align 16
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %2
  br label %82

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 240, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 -1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11
  store i8 %19, ptr %10, align 1, !tbaa !11
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %20, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %74, %14
  %22 = load i8, ptr %10, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %81

25:                                               ; preds = %21
  %26 = load i8, ptr %10, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  switch i32 %27, label %39 [
    i32 40, label %28
    i32 41, label %35
    i32 44, label %38
  ]

28:                                               ; preds = %25
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %7, align 4, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [30 x ptr], ptr %5, i64 0, i64 %33
  store ptr %31, ptr %34, align 8, !tbaa !5
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %74

35:                                               ; preds = %25
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %7, align 4, !tbaa !9
  br label %74

38:                                               ; preds = %25
  store i32 2, ptr %8, align 4, !tbaa !9
  br label %74

39:                                               ; preds = %25
  %40 = call noalias ptr @malloc(i64 noundef 24) #4
  store ptr %40, ptr %6, align 8, !tbaa !5
  %41 = load i8, ptr %10, align 1, !tbaa !11
  %42 = sext i8 %41 to i32
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.btree, ptr %43, i32 0, i32 0
  store i32 %42, ptr %44, align 8, !tbaa !12
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.btree, ptr %45, i32 0, i32 2
  store ptr null, ptr %46, align 8, !tbaa !14
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.btree, ptr %47, i32 0, i32 1
  store ptr null, ptr %48, align 8, !tbaa !15
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %55, label %52

52:                                               ; preds = %39
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %53, ptr %54, align 8, !tbaa !5
  br label %73

55:                                               ; preds = %39
  %56 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %56, label %71 [
    i32 1, label %57
    i32 2, label %64
  ]

57:                                               ; preds = %55
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [30 x ptr], ptr %5, i64 0, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.btree, ptr %62, i32 0, i32 1
  store ptr %58, ptr %63, align 8, !tbaa !15
  br label %72

64:                                               ; preds = %55
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [30 x ptr], ptr %5, i64 0, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.btree, ptr %69, i32 0, i32 2
  store ptr %65, ptr %70, align 8, !tbaa !14
  br label %72

71:                                               ; preds = %55
  br label %72

72:                                               ; preds = %71, %64, %57
  br label %73

73:                                               ; preds = %72, %52
  br label %74

74:                                               ; preds = %73, %38, %35, %28
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %9, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i8, ptr %75, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !11
  store i8 %80, ptr %10, align 1, !tbaa !11
  br label %21, !llvm.loop !16

81:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  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
  call void @llvm.lifetime.end.p0(i64 240, ptr %5) #3
  br label %82

82:                                               ; preds = %81, %13
  ret void
}

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

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

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


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree nounwind memory(write, argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local void @create_btree(ptr nocapture noundef %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca [30 x ptr], align 16
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %34, label %4

4:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 240, ptr nonnull %3) #4
  %5 = load i8, ptr %1, align 1, !tbaa !5
  store ptr null, ptr %0, align 8, !tbaa !8
  br label %6

6:                                                ; preds = %30, %4
  %indvars.iv = phi i64 [ %indvars.iv.next, %30 ], [ 0, %4 ]
  %.027 = phi ptr [ %.128, %30 ], [ null, %4 ]
  %.025 = phi i32 [ %.126, %30 ], [ -1, %4 ]
  %.024 = phi i32 [ %.1, %30 ], [ undef, %4 ]
  %.0 = phi i8 [ %32, %30 ], [ %5, %4 ]
  switch i8 %.0, label %13 [
    i8 0, label %33
    i8 40, label %7
    i8 41, label %11
    i8 44, label %30
  ]

7:                                                ; preds = %6
  %8 = add nsw i32 %.025, 1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [30 x ptr], ptr %3, i64 0, i64 %9
  store ptr %.027, ptr %10, align 8, !tbaa !8
  br label %30

11:                                               ; preds = %6
  %12 = add nsw i32 %.025, -1
  br label %30

13:                                               ; preds = %6
  %14 = sext i8 %.0 to i32
  %15 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #5
  store i32 %14, ptr %15, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %16, i8 0, i64 16, i1 false)
  %17 = load ptr, ptr %0, align 8, !tbaa !8
  %.not32 = icmp eq ptr %17, null
  br i1 %.not32, label %18, label %19

18:                                               ; preds = %13
  store ptr %15, ptr %0, align 8, !tbaa !8
  br label %30

19:                                               ; preds = %13
  switch i32 %.024, label %30 [
    i32 1, label %20
    i32 2, label %25
  ]

20:                                               ; preds = %19
  %21 = sext i32 %.025 to i64
  %22 = getelementptr inbounds [30 x ptr], ptr %3, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !8
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %15, ptr %24, align 8, !tbaa !13
  br label %30

25:                                               ; preds = %19
  %26 = sext i32 %.025 to i64
  %27 = getelementptr inbounds [30 x ptr], ptr %3, i64 0, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !8
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  store ptr %15, ptr %29, align 8, !tbaa !14
  br label %30

30:                                               ; preds = %6, %18, %19, %25, %20, %11, %7
  %.128 = phi ptr [ %15, %19 ], [ %15, %25 ], [ %15, %20 ], [ %15, %18 ], [ %.027, %11 ], [ %.027, %7 ], [ %.027, %6 ]
  %.126 = phi i32 [ %.025, %19 ], [ %.025, %25 ], [ %.025, %20 ], [ %.025, %18 ], [ %12, %11 ], [ %8, %7 ], [ %.025, %6 ]
  %.1 = phi i32 [ %.024, %19 ], [ 2, %25 ], [ 1, %20 ], [ %.024, %18 ], [ %.024, %11 ], [ 1, %7 ], [ 2, %6 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  %32 = load i8, ptr %31, align 1, !tbaa !5
  br label %6, !llvm.loop !15

33:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 240, ptr nonnull %3) #4
  br label %34

34:                                               ; preds = %2, %33
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind memory(write, argmem: readwrite, 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"btree", !12, i64 0, !9, i64 8, !9, i64 16}
!12 = !{!"int", !6, i64 0}
!13 = !{!11, !9, i64 8}
!14 = !{!11, !9, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass