; LLVM IR from MinhasKamal/AlgorithmImplementations :: dataStructures/stack (StackImplementation)

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

@c = external dso_local global [5 x i8], align 1
@stdin = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 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

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

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

declare i32 @fflush(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @stack_push() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %4 = load i8, ptr getelementptr inbounds ([5 x i8], ptr @c, i64 0, i64 4), align 1, !tbaa !5
  %5 = sext i8 %4 to i32
  %6 = icmp ne i32 %5, 42
  br i1 %6, label %7, label %9

7:                                                ; preds = %0
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i32 1, ptr %2, align 4
  br label %35

9:                                                ; preds = %0
  store i32 4, ptr %1, align 4, !tbaa !8
  br label %10

10:                                               ; preds = %22, %9
  %11 = load i32, ptr %1, align 4, !tbaa !8
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %13, label %25

13:                                               ; preds = %10
  %14 = load i32, ptr %1, align 4, !tbaa !8
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [5 x i8], ptr @c, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %18, 42
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  br label %25

21:                                               ; preds = %13
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %1, align 4, !tbaa !8
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %1, align 4, !tbaa !8
  br label %10, !llvm.loop !10

25:                                               ; preds = %20, %10
  %26 = load ptr, ptr @stdin, align 8, !tbaa !12
  %27 = call i32 @fflush(ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.7, ptr noundef %3)
  %30 = load i8, ptr %3, align 1, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !8
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [5 x i8], ptr @c, i64 0, i64 %33
  store i8 %30, ptr %34, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  store i32 0, ptr %2, align 4
  br label %35

35:                                               ; preds = %25, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  %36 = load i32, ptr %2, align 4
  switch i32 %36, label %38 [
    i32 0, label %37
    i32 1, label %37
  ]

37:                                               ; preds = %35, %35
  ret void

38:                                               ; preds = %35
  unreachable
}

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

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

@c = external dso_local local_unnamed_addr global [5 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind uwtable
define dso_local void @stack_push() local_unnamed_addr #2 {
  %1 = alloca i8, align 1
  %2 = load i8, ptr getelementptr inbounds (i8, ptr @c, i64 4), align 1, !tbaa !5
  %.not = icmp eq i8 %2, 42
  br i1 %.not, label %.preheader.1, label %3

3:                                                ; preds = %0
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %16

.preheader.1:                                     ; preds = %0
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @c, i64 3), align 1, !tbaa !5
  %.not4.1 = icmp eq i8 %5, 42
  br i1 %.not4.1, label %.preheader.2, label %9

.preheader.2:                                     ; preds = %.preheader.1
  %6 = load i8, ptr getelementptr inbounds (i8, ptr @c, i64 2), align 1, !tbaa !5
  %.not4.2 = icmp eq i8 %6, 42
  br i1 %.not4.2, label %.preheader.3, label %9

.preheader.3:                                     ; preds = %.preheader.2
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @c, i64 1), align 1, !tbaa !5
  %.not4.3 = icmp eq i8 %7, 42
  br i1 %.not4.3, label %.preheader.4, label %9

.preheader.4:                                     ; preds = %.preheader.3
  %8 = load i8, ptr @c, align 1, !tbaa !5
  %.not4.4 = icmp ne i8 %8, 42
  %spec.select = zext i1 %.not4.4 to i64
  br label %9

9:                                                ; preds = %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1
  %.0.lcssa = phi i64 [ 4, %.preheader.1 ], [ 3, %.preheader.2 ], [ 2, %.preheader.3 ], [ %spec.select, %.preheader.4 ]
  %10 = load ptr, ptr @stdin, align 8, !tbaa !8
  %11 = tail call i32 @fflush(ptr noundef %10)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #3
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.7, ptr noundef nonnull %1)
  %14 = load i8, ptr %1, align 1, !tbaa !5
  %15 = getelementptr inbounds [5 x i8], ptr @c, i64 0, i64 %.0.lcssa
  store i8 %14, ptr %15, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #3
  br label %16

16:                                               ; preds = %9, %3
  ret void
}

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

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


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass