; LLVM IR from ksw2000/Data-Structure-in-C :: Stack (05-用堆疊來計算後序式)

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

; Function Attrs: nounwind uwtable
declare dso_local void @push(ptr noundef, i32 noundef) #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 i32 @pop(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @getToken(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @eval(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call i32 @getToken(ptr noundef %9, ptr noundef %8, ptr noundef %7)
  store i32 %10, ptr %4, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %46, %1
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 5
  br i1 %13, label %14, label %49

14:                                               ; preds = %11
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 6
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load i8, ptr %8, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = sub nsw i32 %19, 48
  call void @push(ptr noundef %3, i32 noundef %20)
  br label %46

21:                                               ; preds = %14
  %22 = call i32 @pop(ptr noundef %3)
  store i32 %22, ptr %6, align 4, !tbaa !9
  %23 = call i32 @pop(ptr noundef %3)
  store i32 %23, ptr %5, align 4, !tbaa !9
  %24 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %24, label %45 [
    i32 0, label %25
    i32 1, label %29
    i32 2, label %33
    i32 3, label %37
    i32 4, label %41
  ]

25:                                               ; preds = %21
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add nsw i32 %26, %27
  call void @push(ptr noundef %3, i32 noundef %28)
  br label %45

29:                                               ; preds = %21
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sub nsw i32 %30, %31
  call void @push(ptr noundef %3, i32 noundef %32)
  br label %45

33:                                               ; preds = %21
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = mul nsw i32 %34, %35
  call void @push(ptr noundef %3, i32 noundef %36)
  br label %45

37:                                               ; preds = %21
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = sdiv i32 %38, %39
  call void @push(ptr noundef %3, i32 noundef %40)
  br label %45

41:                                               ; preds = %21
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = srem i32 %42, %43
  call void @push(ptr noundef %3, i32 noundef %44)
  br label %45

45:                                               ; preds = %41, %37, %33, %29, %25, %21
  br label %46

46:                                               ; preds = %45, %17
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = call i32 @getToken(ptr noundef %47, ptr noundef %8, ptr noundef %7)
  store i32 %48, ptr %4, align 4, !tbaa !9
  br label %11, !llvm.loop !12

49:                                               ; preds = %11
  %50 = call i32 @pop(ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i32 %50
}

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 = { 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 = !{!"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 = distinct !{!12, !13}
!13 = !{!"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: nounwind uwtable
declare dso_local void @push(ptr noundef, i32 noundef) local_unnamed_addr #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: mustprogress 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 i32 @pop(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @getToken(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @eval(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #2
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #2
  br label %5

5:                                                ; preds = %.backedge, %1
  %6 = call i32 @getToken(ptr noundef %0, ptr noundef nonnull %4, ptr noundef nonnull %3)
  switch i32 %6, label %11 [
    i32 5, label %24
    i32 6, label %7
  ]

7:                                                ; preds = %5
  %8 = load i8, ptr %4, align 1, !tbaa !11
  %9 = sext i8 %8 to i32
  %10 = add nsw i32 %9, -48
  br label %.sink.split

11:                                               ; preds = %5
  %12 = call i32 @pop(ptr noundef nonnull %2)
  %13 = call i32 @pop(ptr noundef nonnull %2)
  switch i32 %6, label %.backedge [
    i32 0, label %14
    i32 1, label %16
    i32 2, label %18
    i32 3, label %20
    i32 4, label %22
  ]

14:                                               ; preds = %11
  %15 = add nsw i32 %13, %12
  br label %.sink.split

16:                                               ; preds = %11
  %17 = sub nsw i32 %13, %12
  br label %.sink.split

18:                                               ; preds = %11
  %19 = mul nsw i32 %13, %12
  br label %.sink.split

20:                                               ; preds = %11
  %21 = sdiv i32 %13, %12
  br label %.sink.split

22:                                               ; preds = %11
  %23 = srem i32 %13, %12
  br label %.sink.split

.sink.split:                                      ; preds = %7, %22, %20, %18, %16, %14
  %.sink = phi i32 [ %15, %14 ], [ %17, %16 ], [ %19, %18 ], [ %21, %20 ], [ %23, %22 ], [ %10, %7 ]
  call void @push(ptr noundef nonnull %2, i32 noundef %.sink)
  br label %.backedge

.backedge:                                        ; preds = %.sink.split, %11
  br label %5, !llvm.loop !12

24:                                               ; preds = %5
  %25 = call i32 @pop(ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #2
  ret i32 %25
}

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 = { 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 = !{!"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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopUnrollPass,SROAPass,SimplifyCFGPass