; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 11. Stack (Infix_to_Postfix_and_Evaluation)

; 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 i32 @isoprator(i8 noundef signext) #0

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

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @pop(ptr noundef, ptr 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
define dso_local i32 @evaluate(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [20 x i8], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 -1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  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 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  %10 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  call void @push(ptr noundef %10, ptr noundef %4, i8 noundef signext 40)
  br label %11

11:                                               ; preds = %93, %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %94

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = call i32 @isoprator(i8 noundef signext %18)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %82

21:                                               ; preds = %16
  %22 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %23 = call signext i8 @pop(ptr noundef %22, ptr noundef %4)
  %24 = sext i8 %23 to i32
  store i32 %24, ptr %6, align 4, !tbaa !9
  %25 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %26 = call signext i8 @pop(ptr noundef %25, ptr noundef %4)
  %27 = sext i8 %26 to i32
  store i32 %27, ptr %5, align 4, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = sext i8 %29 to i32
  switch i32 %30, label %81 [
    i32 43, label %31
    i32 45, label %41
    i32 42, label %51
    i32 47, label %61
    i32 94, label %71
  ]

31:                                               ; preds = %21
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = add nsw i32 %32, %33
  store i32 %34, ptr %7, align 4, !tbaa !9
  %35 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = trunc i32 %36 to i8
  call void @push(ptr noundef %35, ptr noundef %4, i8 noundef signext %37)
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %2, align 8, !tbaa !5
  %40 = load i8, ptr %38, align 1, !tbaa !11
  br label %81

41:                                               ; preds = %21
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sub nsw i32 %42, %43
  store i32 %44, ptr %7, align 4, !tbaa !9
  %45 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = trunc i32 %46 to i8
  call void @push(ptr noundef %45, ptr noundef %4, i8 noundef signext %47)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %2, align 8, !tbaa !5
  %50 = load i8, ptr %48, align 1, !tbaa !11
  br label %81

51:                                               ; preds = %21
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = mul nsw i32 %52, %53
  store i32 %54, ptr %7, align 4, !tbaa !9
  %55 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = trunc i32 %56 to i8
  call void @push(ptr noundef %55, ptr noundef %4, i8 noundef signext %57)
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr %2, align 8, !tbaa !5
  %60 = load i8, ptr %58, align 1, !tbaa !11
  br label %81

61:                                               ; preds = %21
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sdiv i32 %62, %63
  store i32 %64, ptr %7, align 4, !tbaa !9
  %65 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = trunc i32 %66 to i8
  call void @push(ptr noundef %65, ptr noundef %4, i8 noundef signext %67)
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %2, align 8, !tbaa !5
  %70 = load i8, ptr %68, align 1, !tbaa !11
  br label %81

71:                                               ; preds = %21
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = xor i32 %72, %73
  store i32 %74, ptr %7, align 4, !tbaa !9
  %75 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = trunc i32 %76 to i8
  call void @push(ptr noundef %75, ptr noundef %4, i8 noundef signext %77)
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i32 1
  store ptr %79, ptr %2, align 8, !tbaa !5
  %80 = load i8, ptr %78, align 1, !tbaa !11
  br label %81

81:                                               ; preds = %71, %61, %51, %41, %31, %21
  br label %93

82:                                               ; preds = %16
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = sext i8 %84 to i32
  %86 = sub nsw i32 %85, 48
  store i32 %86, ptr %8, align 4, !tbaa !9
  %87 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = trunc i32 %88 to i8
  call void @push(ptr noundef %87, ptr noundef %4, i8 noundef signext %89)
  %90 = load ptr, ptr %2, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i32 1
  store ptr %91, ptr %2, align 8, !tbaa !5
  %92 = load i8, ptr %90, align 1, !tbaa !11
  br label %93

93:                                               ; preds = %82, %81
  br label %11, !llvm.loop !12

94:                                               ; preds = %11
  %95 = getelementptr inbounds [20 x i8], ptr %3, i64 0, i64 0
  %96 = call signext i8 @pop(ptr noundef %95, ptr noundef %4)
  %97 = sext i8 %96 to i32
  store i32 %97, ptr %9, align 4, !tbaa !9
  %98 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, 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 20, ptr %3) #2
  ret i32 %98
}

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 i32 @isoprator(i8 noundef signext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @pop(ptr noundef, ptr 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
define dso_local range(i32 -128, 128) i32 @evaluate(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [20 x i8], align 16
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 -1, ptr %3, align 4, !tbaa !5
  call void @push(ptr noundef nonnull %2, ptr noundef nonnull %3, i8 noundef signext 40)
  %4 = load i8, ptr %0, align 1, !tbaa !9
  %.not27 = icmp eq i8 %4, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %26
  %5 = phi i8 [ %27, %26 ], [ %4, %1 ]
  %.028 = phi ptr [ %.1, %26 ], [ %0, %1 ]
  %6 = call i32 @isoprator(i8 noundef signext %5)
  %.not26 = icmp eq i32 %6, 0
  br i1 %.not26, label %22, label %7

7:                                                ; preds = %.lr.ph
  %8 = call signext i8 @pop(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %9 = call signext i8 @pop(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %10 = load i8, ptr %.028, align 1, !tbaa !9
  switch i8 %10, label %26 [
    i8 43, label %11
    i8 45, label %13
    i8 42, label %15
    i8 47, label %17
    i8 94, label %20
  ]

11:                                               ; preds = %7
  %12 = add i8 %9, %8
  br label %thread-pre-split

13:                                               ; preds = %7
  %14 = sub i8 %9, %8
  br label %thread-pre-split

15:                                               ; preds = %7
  %16 = mul i8 %9, %8
  br label %thread-pre-split

17:                                               ; preds = %7
  %.lhs.trunc = sext i8 %9 to i16
  %.rhs.trunc = sext i8 %8 to i16
  %18 = sdiv i16 %.lhs.trunc, %.rhs.trunc
  %19 = trunc i16 %18 to i8
  br label %thread-pre-split

20:                                               ; preds = %7
  %21 = xor i8 %9, %8
  br label %thread-pre-split

22:                                               ; preds = %.lr.ph
  %23 = load i8, ptr %.028, align 1, !tbaa !9
  %24 = add i8 %23, -48
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %22, %20, %17, %15, %13, %11
  %.sink = phi i8 [ %24, %22 ], [ %21, %20 ], [ %19, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ]
  call void @push(ptr noundef nonnull %2, ptr noundef nonnull %3, i8 noundef signext %.sink)
  %25 = getelementptr inbounds i8, ptr %.028, i64 1
  %.pr = load i8, ptr %25, align 1, !tbaa !9
  br label %26

26:                                               ; preds = %thread-pre-split, %7
  %27 = phi i8 [ %.pr, %thread-pre-split ], [ %10, %7 ]
  %.1 = phi ptr [ %25, %thread-pre-split ], [ %.028, %7 ]
  %.not = icmp eq i8 %27, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %26, %1
  %28 = call signext i8 @pop(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %29 = sext i8 %28 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #2
  ret i32 %29
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass