; LLVM IR from mahendramahara/DSA-in-C-Programing :: TREE (Binary-Expression-Tree)

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

@__const.main.t = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @newnode(i8 noundef signext) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @Inorder(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @push(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @pop() #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [7 x i8], align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 7, ptr %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %2, ptr align 1 @__const.main.t, i64 7, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 7, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %70, %0
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %73

12:                                               ; preds = %8
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [7 x i8], ptr %2, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %17, 43
  br i1 %18, label %47, label %19

19:                                               ; preds = %12
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [7 x i8], ptr %2, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 45
  br i1 %25, label %47, label %26

26:                                               ; preds = %19
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [7 x i8], ptr %2, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = icmp eq i32 %31, 42
  br i1 %32, label %47, label %33

33:                                               ; preds = %26
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [7 x i8], ptr %2, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = icmp eq i32 %38, 47
  br i1 %39, label %47, label %40

40:                                               ; preds = %33
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [7 x i8], ptr %2, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 94
  br i1 %46, label %47, label %62

47:                                               ; preds = %40, %33, %26, %19, %12
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [7 x i8], ptr %2, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = call ptr @newnode(i8 noundef signext %51)
  store ptr %52, ptr %7, align 8, !tbaa !10
  %53 = call ptr @pop()
  store ptr %53, ptr %5, align 8, !tbaa !10
  %54 = call ptr @pop()
  store ptr %54, ptr %6, align 8, !tbaa !10
  %55 = load ptr, ptr %6, align 8, !tbaa !10
  %56 = load ptr, ptr %7, align 8, !tbaa !10
  %57 = getelementptr inbounds %struct.node, ptr %56, i32 0, i32 1
  store ptr %55, ptr %57, align 8, !tbaa !12
  %58 = load ptr, ptr %5, align 8, !tbaa !10
  %59 = load ptr, ptr %7, align 8, !tbaa !10
  %60 = getelementptr inbounds %struct.node, ptr %59, i32 0, i32 2
  store ptr %58, ptr %60, align 8, !tbaa !14
  %61 = load ptr, ptr %7, align 8, !tbaa !10
  call void @push(ptr noundef %61)
  br label %69

62:                                               ; preds = %40
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [7 x i8], ptr %2, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !9
  %67 = call ptr @newnode(i8 noundef signext %66)
  store ptr %67, ptr %7, align 8, !tbaa !10
  %68 = load ptr, ptr %7, align 8, !tbaa !10
  call void @push(ptr noundef %68)
  br label %69

69:                                               ; preds = %62, %47
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !15

73:                                               ; preds = %8
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %75 = load ptr, ptr %7, align 8, !tbaa !10
  call void @Inorder(ptr noundef %75)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 7, ptr %2) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

@__const.main.t = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @newnode(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @Inorder(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @push(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @pop() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = load i8, ptr @__const.main.t, align 1, !tbaa !5
  switch i8 %1, label %8 [
    i8 43, label %2
    i8 45, label %2
    i8 42, label %2
    i8 47, label %2
    i8 94, label %2
  ]

2:                                                ; preds = %0, %0, %0, %0, %0
  %3 = tail call ptr @newnode(i8 noundef signext %1)
  %4 = tail call ptr @pop()
  %5 = tail call ptr @pop()
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %5, ptr %6, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %4, ptr %7, align 8, !tbaa !11
  br label %10

8:                                                ; preds = %0
  %9 = tail call ptr @newnode(i8 noundef signext %1)
  br label %10

10:                                               ; preds = %2, %8
  %.sink = phi ptr [ %3, %2 ], [ %9, %8 ]
  tail call void @push(ptr noundef %.sink)
  %11 = load i8, ptr getelementptr inbounds (i8, ptr @__const.main.t, i64 1), align 1, !tbaa !5
  switch i8 %11, label %18 [
    i8 43, label %12
    i8 45, label %12
    i8 42, label %12
    i8 47, label %12
    i8 94, label %12
  ]

12:                                               ; preds = %10, %10, %10, %10, %10
  %13 = tail call ptr @newnode(i8 noundef signext %11)
  %14 = tail call ptr @pop()
  %15 = tail call ptr @pop()
  %16 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !8
  %17 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %14, ptr %17, align 8, !tbaa !11
  br label %20

18:                                               ; preds = %10
  %19 = tail call ptr @newnode(i8 noundef signext %11)
  br label %20

20:                                               ; preds = %18, %12
  %.sink20 = phi ptr [ %19, %18 ], [ %13, %12 ]
  tail call void @push(ptr noundef %.sink20)
  %21 = load i8, ptr getelementptr inbounds (i8, ptr @__const.main.t, i64 2), align 1, !tbaa !5
  switch i8 %21, label %28 [
    i8 43, label %22
    i8 45, label %22
    i8 42, label %22
    i8 47, label %22
    i8 94, label %22
  ]

22:                                               ; preds = %20, %20, %20, %20, %20
  %23 = tail call ptr @newnode(i8 noundef signext %21)
  %24 = tail call ptr @pop()
  %25 = tail call ptr @pop()
  %26 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %25, ptr %26, align 8, !tbaa !8
  %27 = getelementptr inbounds i8, ptr %23, i64 16
  store ptr %24, ptr %27, align 8, !tbaa !11
  br label %30

28:                                               ; preds = %20
  %29 = tail call ptr @newnode(i8 noundef signext %21)
  br label %30

30:                                               ; preds = %28, %22
  %.sink21 = phi ptr [ %29, %28 ], [ %23, %22 ]
  tail call void @push(ptr noundef %.sink21)
  %31 = load i8, ptr getelementptr inbounds (i8, ptr @__const.main.t, i64 3), align 1, !tbaa !5
  switch i8 %31, label %38 [
    i8 43, label %32
    i8 45, label %32
    i8 42, label %32
    i8 47, label %32
    i8 94, label %32
  ]

32:                                               ; preds = %30, %30, %30, %30, %30
  %33 = tail call ptr @newnode(i8 noundef signext %31)
  %34 = tail call ptr @pop()
  %35 = tail call ptr @pop()
  %36 = getelementptr inbounds i8, ptr %33, i64 8
  store ptr %35, ptr %36, align 8, !tbaa !8
  %37 = getelementptr inbounds i8, ptr %33, i64 16
  store ptr %34, ptr %37, align 8, !tbaa !11
  br label %40

38:                                               ; preds = %30
  %39 = tail call ptr @newnode(i8 noundef signext %31)
  br label %40

40:                                               ; preds = %38, %32
  %.sink22 = phi ptr [ %39, %38 ], [ %33, %32 ]
  tail call void @push(ptr noundef %.sink22)
  %41 = load i8, ptr getelementptr inbounds (i8, ptr @__const.main.t, i64 4), align 1, !tbaa !5
  switch i8 %41, label %48 [
    i8 43, label %42
    i8 45, label %42
    i8 42, label %42
    i8 47, label %42
    i8 94, label %42
  ]

42:                                               ; preds = %40, %40, %40, %40, %40
  %43 = tail call ptr @newnode(i8 noundef signext %41)
  %44 = tail call ptr @pop()
  %45 = tail call ptr @pop()
  %46 = getelementptr inbounds i8, ptr %43, i64 8
  store ptr %45, ptr %46, align 8, !tbaa !8
  %47 = getelementptr inbounds i8, ptr %43, i64 16
  store ptr %44, ptr %47, align 8, !tbaa !11
  br label %50

48:                                               ; preds = %40
  %49 = tail call ptr @newnode(i8 noundef signext %41)
  br label %50

50:                                               ; preds = %48, %42
  %.sink23 = phi ptr [ %49, %48 ], [ %43, %42 ]
  tail call void @push(ptr noundef %.sink23)
  %51 = load i8, ptr getelementptr inbounds (i8, ptr @__const.main.t, i64 5), align 1, !tbaa !5
  switch i8 %51, label %58 [
    i8 43, label %52
    i8 45, label %52
    i8 42, label %52
    i8 47, label %52
    i8 94, label %52
  ]

52:                                               ; preds = %50, %50, %50, %50, %50
  %53 = tail call ptr @newnode(i8 noundef signext %51)
  %54 = tail call ptr @pop()
  %55 = tail call ptr @pop()
  %56 = getelementptr inbounds i8, ptr %53, i64 8
  store ptr %55, ptr %56, align 8, !tbaa !8
  %57 = getelementptr inbounds i8, ptr %53, i64 16
  store ptr %54, ptr %57, align 8, !tbaa !11
  br label %60

58:                                               ; preds = %50
  %59 = tail call ptr @newnode(i8 noundef signext %51)
  br label %60

60:                                               ; preds = %58, %52
  %.sink24 = phi ptr [ %59, %58 ], [ %53, %52 ]
  tail call void @push(ptr noundef %.sink24)
  %61 = load i8, ptr getelementptr inbounds (i8, ptr @__const.main.t, i64 6), align 1, !tbaa !5
  switch i8 %61, label %68 [
    i8 43, label %62
    i8 45, label %62
    i8 42, label %62
    i8 47, label %62
    i8 94, label %62
  ]

62:                                               ; preds = %60, %60, %60, %60, %60
  %63 = tail call ptr @newnode(i8 noundef signext %61)
  %64 = tail call ptr @pop()
  %65 = tail call ptr @pop()
  %66 = getelementptr inbounds i8, ptr %63, i64 8
  store ptr %65, ptr %66, align 8, !tbaa !8
  %67 = getelementptr inbounds i8, ptr %63, i64 16
  store ptr %64, ptr %67, align 8, !tbaa !11
  br label %70

68:                                               ; preds = %60
  %69 = tail call ptr @newnode(i8 noundef signext %61)
  br label %70

70:                                               ; preds = %68, %62
  %.sink25 = phi ptr [ %69, %68 ], [ %63, %62 ]
  tail call void @push(ptr noundef %.sink25)
  %71 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  tail call void @Inorder(ptr noundef %.sink25)
  ret i32 0
}

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 = { 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" }

!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, !10, i64 8}
!9 = !{!"node", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!9, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass