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

; 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 { i8, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [27 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @Search_Link(ptr noundef, i8 noundef signext) #3

; Function Attrs: nounwind uwtable
define dso_local void @insert(ptr noundef %0, i8 noundef signext %1, i8 noundef signext %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i8, ptr %5, align 1, !tbaa !9
  %14 = call ptr @Search_Link(ptr noundef %12, i8 noundef signext %13)
  store ptr %14, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %3
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 1, ptr %8, align 4
  br label %89

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Tree, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  %23 = icmp eq ptr %22, null
  br i1 %23, label %29, label %24

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Tree, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %86

29:                                               ; preds = %24, %19
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %9)
  %32 = load i8, ptr %9, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 76
  br i1 %34, label %39, label %35

35:                                               ; preds = %29
  %36 = load i8, ptr %9, align 1, !tbaa !9
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 108
  br i1 %38, label %39, label %62

39:                                               ; preds = %35, %29
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Tree, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !10
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %59

44:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %45 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %45, ptr %10, align 8, !tbaa !5
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Tree, ptr %47, i32 0, i32 1
  store ptr %46, ptr %48, align 8, !tbaa !10
  %49 = load i8, ptr %6, align 1, !tbaa !9
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Tree, ptr %50, i32 0, i32 0
  store i8 %49, ptr %51, align 8, !tbaa !13
  %52 = load i8, ptr %6, align 1, !tbaa !9
  %53 = sext i8 %52 to i32
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %53)
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Tree, ptr %55, i32 0, i32 1
  store ptr null, ptr %56, align 8, !tbaa !10
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Tree, ptr %57, i32 0, i32 2
  store ptr null, ptr %58, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %61

59:                                               ; preds = %39
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %61

61:                                               ; preds = %59, %44
  br label %85

62:                                               ; preds = %35
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Tree, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !12
  %66 = icmp eq ptr %65, null
  br i1 %66, label %67, label %82

67:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %68 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %68, ptr %11, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.Tree, ptr %70, i32 0, i32 2
  store ptr %69, ptr %71, align 8, !tbaa !12
  %72 = load i8, ptr %6, align 1, !tbaa !9
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Tree, ptr %73, i32 0, i32 0
  store i8 %72, ptr %74, align 8, !tbaa !13
  %75 = load i8, ptr %6, align 1, !tbaa !9
  %76 = sext i8 %75 to i32
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %76)
  %78 = load ptr, ptr %11, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.Tree, ptr %78, i32 0, i32 1
  store ptr null, ptr %79, align 8, !tbaa !10
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Tree, ptr %80, i32 0, i32 2
  store ptr null, ptr %81, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %84

82:                                               ; preds = %62
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %84

84:                                               ; preds = %82, %67
  br label %85

85:                                               ; preds = %84, %61
  br label %88

86:                                               ; preds = %24
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %88

88:                                               ; preds = %86, %85
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  store i32 0, ptr %8, align 4
  br label %89

89:                                               ; preds = %88, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %90 = load i32, ptr %8, align 4
  switch i32 %90, label %92 [
    i32 0, label %91
    i32 1, label %91
  ]

91:                                               ; preds = %89, %89
  ret void

92:                                               ; preds = %89
  unreachable
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 8}
!11 = !{!"Tree", !7, i64 0, !6, i64 8, !6, i64 16}
!12 = !{!11, !6, i64 16}
!13 = !{!11, !7, i64 0}


; 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 [36 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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 #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @Search_Link(ptr noundef, i8 noundef signext) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @insert(ptr noundef %0, i8 noundef signext %1, i8 noundef signext %2) local_unnamed_addr #3 {
  %4 = alloca i8, align 1
  %5 = tail call ptr @Search_Link(ptr noundef %0, i8 noundef signext %1)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %46

9:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #5
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %17, label %13

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %5, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %43

17:                                               ; preds = %13, %9
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %4)
  %20 = load i8, ptr %4, align 1
  %21 = and i8 %20, -33
  %or.cond = icmp eq i8 %21, 76
  br i1 %or.cond, label %22, label %32

22:                                               ; preds = %17
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %30

25:                                               ; preds = %22
  %26 = call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #6
  store ptr %26, ptr %10, align 8, !tbaa !5
  store i8 %2, ptr %26, align 8, !tbaa !11
  %27 = sext i8 %2 to i32
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %27)
  %29 = getelementptr inbounds i8, ptr %26, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %29, i8 0, i64 16, i1 false)
  br label %45

30:                                               ; preds = %22
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %45

32:                                               ; preds = %17
  %33 = getelementptr inbounds i8, ptr %5, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !10
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %41

36:                                               ; preds = %32
  %37 = call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #6
  store ptr %37, ptr %33, align 8, !tbaa !10
  store i8 %2, ptr %37, align 8, !tbaa !11
  %38 = sext i8 %2 to i32
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %38)
  %40 = getelementptr inbounds i8, ptr %37, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %40, i8 0, i64 16, i1 false)
  br label %45

41:                                               ; preds = %32
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %45

43:                                               ; preds = %13
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  br label %45

45:                                               ; preds = %30, %25, %41, %36, %43
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #5
  br label %46

46:                                               ; preds = %45, %7
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { 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, !9, i64 8}
!6 = !{!"Tree", !7, i64 0, !9, i64 8, !9, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!6, !9, i64 16}
!11 = !{!6, !7, i64 0}


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