; LLVM IR from wuzhouhui/leetcode :: 150_eval_rever_polish_nota (evalRPN)

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

%struct.StringArray = type { ptr, i32 }
%struct.stack = type { i32, ptr }

@stackptr = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @evalRPN(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %18

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.StringArray, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %18

13:                                               ; preds = %8
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.StringArray, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %13, %8, %1
  store i32 0, ptr %2, align 4
  br label %95

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %86, %19
  %21 = load i32, ptr %4, align 4, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.StringArray, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !12
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %26, label %89

26:                                               ; preds = %20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.StringArray, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr %4, align 4, !tbaa !13
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 0
  %35 = load i8, ptr %34, align 1, !tbaa !14
  %36 = sext i8 %35 to i32
  switch i32 %36, label %76 [
    i32 43, label %37
    i32 47, label %41
    i32 42, label %46
    i32 45, label %50
  ]

37:                                               ; preds = %26
  %38 = call i32 @pop()
  %39 = call i32 @pop()
  %40 = add nsw i32 %38, %39
  call void @push(i32 noundef %40)
  br label %85

41:                                               ; preds = %26
  %42 = call i32 @pop()
  store i32 %42, ptr %5, align 4, !tbaa !13
  %43 = call i32 @pop()
  %44 = load i32, ptr %5, align 4, !tbaa !13
  %45 = sdiv i32 %43, %44
  call void @push(i32 noundef %45)
  br label %85

46:                                               ; preds = %26
  %47 = call i32 @pop()
  %48 = call i32 @pop()
  %49 = mul nsw i32 %47, %48
  call void @push(i32 noundef %49)
  br label %85

50:                                               ; preds = %26
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.StringArray, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = load i32, ptr %4, align 4, !tbaa !13
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %53, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 1
  %59 = load i8, ptr %58, align 1, !tbaa !14
  %60 = icmp ne i8 %59, 0
  br i1 %60, label %61, label %70

61:                                               ; preds = %50
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.StringArray, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = load i32, ptr %4, align 4, !tbaa !13
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = call i32 @atoi(ptr noundef %68) #5
  call void @push(i32 noundef %69)
  br label %75

70:                                               ; preds = %50
  %71 = call i32 @pop()
  store i32 %71, ptr %5, align 4, !tbaa !13
  %72 = call i32 @pop()
  %73 = load i32, ptr %5, align 4, !tbaa !13
  %74 = sub nsw i32 %72, %73
  call void @push(i32 noundef %74)
  br label %75

75:                                               ; preds = %70, %61
  br label %85

76:                                               ; preds = %26
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.StringArray, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !9
  %80 = load i32, ptr %4, align 4, !tbaa !13
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %79, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = call i32 @atoi(ptr noundef %83) #5
  call void @push(i32 noundef %84)
  br label %85

85:                                               ; preds = %76, %75, %46, %41, %37
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %4, align 4, !tbaa !13
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %4, align 4, !tbaa !13
  br label %20, !llvm.loop !15

89:                                               ; preds = %20
  %90 = load ptr, ptr @stackptr, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.stack, ptr %90, i32 0, i32 0
  %92 = load i32, ptr %91, align 8, !tbaa !17
  store i32 %92, ptr %4, align 4, !tbaa !13
  %93 = load ptr, ptr @stackptr, align 8, !tbaa !5
  call void @free(ptr noundef %93) #4
  %94 = load i32, ptr %4, align 4, !tbaa !13
  store i32 %94, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %95

95:                                               ; preds = %89, %18
  %96 = load i32, ptr %2, align 4
  ret i32 %96
}

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

; Function Attrs: nounwind uwtable
declare hidden void @push(i32 noundef) #0

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; 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 hidden i32 @pop() #0

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 = { inlinehint nounwind willreturn memory(read) 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 "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(read) }

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


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

@stackptr = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @evalRPN(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %41, label %2

2:                                                ; preds = %1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not19 = icmp eq ptr %3, null
  br i1 %.not19, label %41, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %.not20 = icmp eq i32 %6, 0
  br i1 %.not20, label %41, label %.preheader

.preheader:                                       ; preds = %4
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %35
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ 0, %.preheader ]
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = load i8, ptr %10, align 1, !tbaa !13
  switch i8 %11, label %33 [
    i8 43, label %12
    i8 47, label %16
    i8 42, label %20
    i8 45, label %24
  ]

12:                                               ; preds = %.lr.ph
  %13 = tail call i32 @pop()
  %14 = tail call i32 @pop()
  %15 = add nsw i32 %14, %13
  br label %35

16:                                               ; preds = %.lr.ph
  %17 = tail call i32 @pop()
  %18 = tail call i32 @pop()
  %19 = sdiv i32 %18, %17
  br label %35

20:                                               ; preds = %.lr.ph
  %21 = tail call i32 @pop()
  %22 = tail call i32 @pop()
  %23 = mul nsw i32 %22, %21
  br label %35

24:                                               ; preds = %.lr.ph
  %25 = getelementptr inbounds i8, ptr %10, i64 1
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %.not21 = icmp eq i8 %26, 0
  br i1 %.not21, label %29, label %27

27:                                               ; preds = %24
  %28 = tail call i32 @atoi(ptr nocapture noundef %10) #3
  br label %35

29:                                               ; preds = %24
  %30 = tail call i32 @pop()
  %31 = tail call i32 @pop()
  %32 = sub nsw i32 %31, %30
  br label %35

33:                                               ; preds = %.lr.ph
  %34 = tail call i32 @atoi(ptr nocapture noundef %10) #3
  br label %35

35:                                               ; preds = %12, %16, %20, %33, %29, %27
  %.sink = phi i32 [ %15, %12 ], [ %19, %16 ], [ %23, %20 ], [ %34, %33 ], [ %32, %29 ], [ %28, %27 ]
  tail call void @push(i32 noundef %.sink)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = load i32, ptr %5, align 8, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next, %37
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %35, %.preheader
  %39 = load ptr, ptr @stackptr, align 8, !tbaa !12
  %40 = load i32, ptr %39, align 8, !tbaa !16
  tail call void @free(ptr noundef %39) #4
  br label %41

41:                                               ; preds = %1, %2, %4, %._crit_edge
  %.017 = phi i32 [ %40, %._crit_edge ], [ 0, %4 ], [ 0, %2 ], [ 0, %1 ]
  ret i32 %.017
}

; Function Attrs: nounwind uwtable
declare hidden void @push(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @pop() local_unnamed_addr #0

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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #2 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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(read) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"StringArray", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 0}
!17 = !{!"stack", !10, i64 0, !7, i64 8}


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