; LLVM IR from mahendramahara/DSA-in-C-Programing :: STACK (infixtopostfix)

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

@top = external dso_local global i32, align 4
@stack = external dso_local global [100 x i8], align 16
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [100 x i8], align 16
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 100, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %8 = getelementptr inbounds [100 x i8], ptr %2, i64 0, i64 0
  store ptr %8, ptr %3, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %74, %0
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %77

14:                                               ; preds = %9
  %15 = call ptr @__ctype_b_loc() #5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i16, ptr %16, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !10
  %23 = zext i16 %22 to i32
  %24 = and i32 %23, 8
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %14
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %29)
  br label %74

31:                                               ; preds = %14
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 40
  br i1 %35, label %36, label %39

36:                                               ; preds = %31
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !9
  call void @push(i8 noundef signext %38)
  br label %73

39:                                               ; preds = %31
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = icmp eq i32 %42, 41
  br i1 %43, label %44, label %54

44:                                               ; preds = %39
  br label %45

45:                                               ; preds = %49, %44
  %46 = call signext i8 @pop()
  store i8 %46, ptr %4, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = icmp ne i32 %47, 40
  br i1 %48, label %49, label %53

49:                                               ; preds = %45
  %50 = load i8, ptr %4, align 1, !tbaa !9
  %51 = sext i8 %50 to i32
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %51)
  br label %45, !llvm.loop !12

53:                                               ; preds = %45
  br label %72

54:                                               ; preds = %39
  br label %55

55:                                               ; preds = %65, %54
  %56 = load i32, ptr @top, align 4, !tbaa !14
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100 x i8], ptr @stack, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !9
  %60 = call i32 @priority(i8 noundef signext %59)
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load i8, ptr %61, align 1, !tbaa !9
  %63 = call i32 @priority(i8 noundef signext %62)
  %64 = icmp sge i32 %60, %63
  br i1 %64, label %65, label %69

65:                                               ; preds = %55
  %66 = call signext i8 @pop()
  %67 = sext i8 %66 to i32
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %67)
  br label %55, !llvm.loop !16

69:                                               ; preds = %55
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = load i8, ptr %70, align 1, !tbaa !9
  call void @push(i8 noundef signext %71)
  br label %72

72:                                               ; preds = %69, %53
  br label %73

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

74:                                               ; preds = %73, %26
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i32 1
  store ptr %76, ptr %3, align 8, !tbaa !5
  br label %9, !llvm.loop !17

77:                                               ; preds = %9
  br label %78

78:                                               ; preds = %81, %77
  %79 = load i32, ptr @top, align 4, !tbaa !14
  %80 = icmp ne i32 %79, -1
  br i1 %80, label %81, label %85

81:                                               ; preds = %78
  %82 = call signext i8 @pop()
  %83 = sext i8 %82 to i32
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %83)
  br label %78, !llvm.loop !18

85:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr %2) #4
  ret i32 0
}

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

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

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #3

; 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 = { "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 willreturn memory(none) "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 willreturn memory(none) }

!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, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}
!18 = distinct !{!18, !13}


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

@top = external dso_local local_unnamed_addr global i32, align 4
@stack = external dso_local local_unnamed_addr global [100 x i8], align 16
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [100 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %1) #4
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %5 = load i8, ptr %1, align 16, !tbaa !5
  %.not20 = icmp eq i8 %5, 0
  br i1 %.not20, label %.preheader, label %.lr.ph23

.lr.ph23:                                         ; preds = %0
  %6 = tail call ptr @__ctype_b_loc() #5
  br label %8

.preheader:                                       ; preds = %.loopexit, %0
  %7 = load i32, ptr @top, align 4, !tbaa !8
  %.not1124 = icmp eq i32 %7, -1
  br i1 %.not1124, label %._crit_edge26, label %.lr.ph25

8:                                                ; preds = %.lr.ph23, %.loopexit
  %9 = phi i8 [ %5, %.lr.ph23 ], [ %44, %.loopexit ]
  %.021 = phi ptr [ %1, %.lr.ph23 ], [ %43, %.loopexit ]
  %10 = load ptr, ptr %6, align 8, !tbaa !10
  %11 = sext i8 %9 to i64
  %12 = getelementptr inbounds i16, ptr %10, i64 %11
  %13 = load i16, ptr %12, align 2, !tbaa !12
  %14 = and i16 %13, 8
  %.not12 = icmp eq i16 %14, 0
  br i1 %.not12, label %18, label %15

15:                                               ; preds = %8
  %16 = sext i8 %9 to i32
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %16)
  br label %.loopexit

18:                                               ; preds = %8
  switch i8 %9, label %.preheader15 [
    i8 40, label %27
    i8 41, label %.preheader16
  ]

.preheader16:                                     ; preds = %18
  %19 = call signext i8 @pop()
  %.not1417 = icmp eq i8 %19, 40
  br i1 %.not1417, label %.loopexit, label %.lr.ph

.preheader15:                                     ; preds = %18
  %20 = load i32, ptr @top, align 4, !tbaa !8
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100 x i8], ptr @stack, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = call i32 @priority(i8 noundef signext %23)
  %25 = load i8, ptr %.021, align 1, !tbaa !5
  %26 = call i32 @priority(i8 noundef signext %25)
  %.not1318 = icmp slt i32 %24, %26
  br i1 %.not1318, label %._crit_edge, label %.lr.ph19

27:                                               ; preds = %18
  call void @push(i8 noundef signext 40)
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader16, %.lr.ph
  %28 = phi i8 [ %31, %.lr.ph ], [ %19, %.preheader16 ]
  %29 = sext i8 %28 to i32
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %29)
  %31 = call signext i8 @pop()
  %.not14 = icmp eq i8 %31, 40
  br i1 %.not14, label %.loopexit, label %.lr.ph, !llvm.loop !14

.lr.ph19:                                         ; preds = %.preheader15, %.lr.ph19
  %32 = call signext i8 @pop()
  %33 = sext i8 %32 to i32
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %33)
  %35 = load i32, ptr @top, align 4, !tbaa !8
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x i8], ptr @stack, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = call i32 @priority(i8 noundef signext %38)
  %40 = load i8, ptr %.021, align 1, !tbaa !5
  %41 = call i32 @priority(i8 noundef signext %40)
  %.not13 = icmp slt i32 %39, %41
  br i1 %.not13, label %._crit_edge, label %.lr.ph19, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph19, %.preheader15
  %42 = load i8, ptr %.021, align 1, !tbaa !5
  call void @push(i8 noundef signext %42)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader16, %27, %._crit_edge, %15
  %43 = getelementptr inbounds i8, ptr %.021, i64 1
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %.not = icmp eq i8 %44, 0
  br i1 %.not, label %.preheader, label %8, !llvm.loop !17

.lr.ph25:                                         ; preds = %.preheader, %.lr.ph25
  %45 = call signext i8 @pop()
  %46 = sext i8 %45 to i32
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %46)
  %48 = load i32, ptr @top, align 4, !tbaa !8
  %.not11 = icmp eq i32 %48, -1
  br i1 %.not11, label %._crit_edge26, label %.lr.ph25, !llvm.loop !18

._crit_edge26:                                    ; preds = %.lr.ph25, %.preheader
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %1) #4
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #3

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 willreturn memory(none) }

!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 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}


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