; LLVM IR from xxks-kkk/algo :: stack/generic (postfix)

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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @evaluate_postfix(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 20, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call noalias ptr @fopen(ptr noundef %10, ptr noundef @.str)
  store ptr %11, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %18

14:                                               ; preds = %1
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.1, ptr noundef %16) #6
  call void @exit(i32 noundef 1) #7
  unreachable

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = call ptr @createStack(i32 noundef %19)
  store ptr %20, ptr %9, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %81, %18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 @getc(ptr noundef %22)
  store i32 %23, ptr %5, align 4, !tbaa !9
  %24 = icmp ne i32 %23, -1
  br i1 %24, label %25, label %82

25:                                               ; preds = %21
  %26 = call ptr @__ctype_b_loc() #8
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i16, ptr %27, i64 %29
  %31 = load i16, ptr %30, align 2, !tbaa !11
  %32 = zext i16 %31 to i32
  %33 = and i32 %32, 2048
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %39

35:                                               ; preds = %25
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = sub nsw i32 %36, 48
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  call void @push(i32 noundef %37, ptr noundef %38)
  br label %81

39:                                               ; preds = %25
  %40 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %40, label %77 [
    i32 47, label %41
    i32 42, label %50
    i32 43, label %59
    i32 45, label %68
    i32 32, label %80
  ]

41:                                               ; preds = %39
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = call i32 @topAndPop(ptr noundef %42)
  store i32 %43, ptr %7, align 4, !tbaa !9
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = call i32 @topAndPop(ptr noundef %44)
  store i32 %45, ptr %8, align 4, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sdiv i32 %46, %47
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  call void @push(i32 noundef %48, ptr noundef %49)
  br label %80

50:                                               ; preds = %39
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = call i32 @topAndPop(ptr noundef %51)
  store i32 %52, ptr %7, align 4, !tbaa !9
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = call i32 @topAndPop(ptr noundef %53)
  store i32 %54, ptr %8, align 4, !tbaa !9
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = mul nsw i32 %55, %56
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  call void @push(i32 noundef %57, ptr noundef %58)
  br label %80

59:                                               ; preds = %39
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = call i32 @topAndPop(ptr noundef %60)
  store i32 %61, ptr %7, align 4, !tbaa !9
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call i32 @topAndPop(ptr noundef %62)
  store i32 %63, ptr %8, align 4, !tbaa !9
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = add nsw i32 %64, %65
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  call void @push(i32 noundef %66, ptr noundef %67)
  br label %80

68:                                               ; preds = %39
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = call i32 @topAndPop(ptr noundef %69)
  store i32 %70, ptr %7, align 4, !tbaa !9
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = call i32 @topAndPop(ptr noundef %71)
  store i32 %72, ptr %8, align 4, !tbaa !9
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = sub nsw i32 %73, %74
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  call void @push(i32 noundef %75, ptr noundef %76)
  br label %80

77:                                               ; preds = %39
  %78 = load ptr, ptr @stderr, align 8, !tbaa !5
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %78, ptr noundef @.str.2) #6
  call void @exit(i32 noundef 1) #7
  unreachable

80:                                               ; preds = %68, %59, %50, %41, %39
  br label %81

81:                                               ; preds = %80, %35
  br label %21, !llvm.loop !13

82:                                               ; preds = %21
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = call i32 @topAndPop(ptr noundef %83)
  store i32 %84, ptr %6, align 4, !tbaa !9
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  call void @disposeStack(ptr noundef %85)
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = call i32 @fclose(ptr noundef %86)
  %88 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  ret i32 %88
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

declare ptr @createStack(i32 noundef) #2

declare i32 @getc(ptr noundef) #2

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

declare void @push(i32 noundef, ptr noundef) #2

declare i32 @topAndPop(ptr noundef) #2

declare void @disposeStack(ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

; 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 "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 = { noreturn 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @evaluate_postfix(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str)
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %7

4:                                                ; preds = %1
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.1, ptr noundef %0) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

7:                                                ; preds = %1
  %8 = tail call ptr @createStack(i32 noundef 20) #7
  %9 = tail call i32 @getc(ptr noundef nonnull %2)
  %.not34 = icmp eq i32 %9, -1
  br i1 %.not34, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %10 = tail call ptr @__ctype_b_loc() #8
  br label %11

11:                                               ; preds = %.lr.ph, %40
  %12 = phi i32 [ %9, %.lr.ph ], [ %41, %40 ]
  %13 = load ptr, ptr %10, align 8, !tbaa !5
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds i16, ptr %13, i64 %14
  %16 = load i16, ptr %15, align 2, !tbaa !9
  %17 = and i16 %16, 2048
  %.not33 = icmp eq i16 %17, 0
  br i1 %.not33, label %20, label %18

18:                                               ; preds = %11
  %19 = add nsw i32 %12, -48
  br label %.sink.split

20:                                               ; preds = %11
  switch i32 %12, label %37 [
    i32 47, label %21
    i32 42, label %25
    i32 43, label %29
    i32 45, label %33
    i32 32, label %40
  ]

21:                                               ; preds = %20
  %22 = tail call i32 @topAndPop(ptr noundef %8) #7
  %23 = tail call i32 @topAndPop(ptr noundef %8) #7
  %24 = sdiv i32 %23, %22
  br label %.sink.split

25:                                               ; preds = %20
  %26 = tail call i32 @topAndPop(ptr noundef %8) #7
  %27 = tail call i32 @topAndPop(ptr noundef %8) #7
  %28 = mul nsw i32 %27, %26
  br label %.sink.split

29:                                               ; preds = %20
  %30 = tail call i32 @topAndPop(ptr noundef %8) #7
  %31 = tail call i32 @topAndPop(ptr noundef %8) #7
  %32 = add nsw i32 %31, %30
  br label %.sink.split

33:                                               ; preds = %20
  %34 = tail call i32 @topAndPop(ptr noundef %8) #7
  %35 = tail call i32 @topAndPop(ptr noundef %8) #7
  %36 = sub nsw i32 %35, %34
  br label %.sink.split

37:                                               ; preds = %20
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.2) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

.sink.split:                                      ; preds = %18, %33, %29, %25, %21
  %.sink = phi i32 [ %24, %21 ], [ %28, %25 ], [ %32, %29 ], [ %36, %33 ], [ %19, %18 ]
  tail call void @push(i32 noundef %.sink, ptr noundef %8) #7
  br label %40

40:                                               ; preds = %.sink.split, %20
  %41 = tail call i32 @getc(ptr noundef nonnull %2)
  %.not = icmp eq i32 %41, -1
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !11

._crit_edge:                                      ; preds = %40, %7
  %42 = tail call i32 @topAndPop(ptr noundef %8) #7
  tail call void @disposeStack(ptr noundef %8) #7
  %43 = tail call i32 @fclose(ptr noundef nonnull %2)
  ret i32 %42
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

declare ptr @createStack(i32 noundef) local_unnamed_addr #3

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

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

declare void @push(i32 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @topAndPop(ptr noundef) local_unnamed_addr #3

declare void @disposeStack(ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #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 = { 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 = { noreturn 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 = { "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 = { 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 #5 = { cold nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind }
attributes #8 = { 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 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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