; LLVM IR from JessonYue/LeetCodeLearning :: Array/wuchao/stack/6-16括号匹配 (BracketsMatch)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @myStackCreate() #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @isEmpty(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @myStackPop(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @stackTop(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isValid(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i64 @strlen(ptr noundef %9) #4
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %4, align 4, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = srem i32 %12, 2
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %59

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = call ptr @myStackCreate()
  store ptr %17, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %52, %16
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %53

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11
  store i8 %27, ptr %8, align 1, !tbaa !11
  %28 = load i8, ptr %8, align 1, !tbaa !11
  %29 = call zeroext i1 @isLeft(i8 noundef signext %28)
  br i1 %29, label %30, label %33

30:                                               ; preds = %22
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i8, ptr %8, align 1, !tbaa !11
  call void @myStackPush(ptr noundef %31, i8 noundef signext %32)
  br label %47

33:                                               ; preds = %22
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call zeroext i1 @isEmpty(ptr noundef %34)
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %50

37:                                               ; preds = %33
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call signext i8 @stackTop(ptr noundef %38)
  %40 = load i8, ptr %8, align 1, !tbaa !11
  %41 = call zeroext i1 @isMatch(i8 noundef signext %39, i8 noundef signext %40)
  br i1 %41, label %42, label %45

42:                                               ; preds = %37
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call signext i8 @myStackPop(ptr noundef %43)
  br label %46

45:                                               ; preds = %37
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %50

46:                                               ; preds = %42
  br label %47

47:                                               ; preds = %46, %30
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %5, align 4
  br label %50

50:                                               ; preds = %47, %45, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %51 = load i32, ptr %5, align 4
  switch i32 %51, label %58 [
    i32 0, label %52
  ]

52:                                               ; preds = %50
  br label %18, !llvm.loop !12

53:                                               ; preds = %18
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call zeroext i1 @isEmpty(ptr noundef %54)
  br i1 %55, label %56, label %57

56:                                               ; preds = %53
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %58

57:                                               ; preds = %53
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %58

58:                                               ; preds = %57, %56, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %59

59:                                               ; preds = %58, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %60 = load i1, ptr %2, align 1
  ret i1 %60
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @isLeft(i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @isMatch(i8 noundef signext, i8 noundef signext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind willreturn memory(read) "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 }
attributes #4 = { 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, !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 ptr @myStackCreate() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @isEmpty(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isValid(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %3 = trunc i64 %2 to i32
  %4 = and i32 %3, 1
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %.thread

5:                                                ; preds = %1
  %6 = tail call ptr @myStackCreate()
  %7 = icmp sgt i32 %3, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = and i64 %2, 2147483647
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %19 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = tail call zeroext i1 @isLeft(i8 noundef signext %9)
  br i1 %10, label %11, label %12

11:                                               ; preds = %.lr.ph
  tail call void @myStackPush(ptr noundef %6, i8 noundef signext %9)
  br label %19

12:                                               ; preds = %.lr.ph
  %13 = tail call zeroext i1 @isEmpty(ptr noundef %6)
  br i1 %13, label %.thread, label %14

14:                                               ; preds = %12
  %15 = tail call signext i8 @stackTop(ptr noundef %6)
  %16 = tail call zeroext i1 @isMatch(i8 noundef signext %15, i8 noundef signext %9)
  br i1 %16, label %17, label %.thread

17:                                               ; preds = %14
  %18 = tail call signext i8 @myStackPop(ptr noundef %6)
  br label %19

19:                                               ; preds = %11, %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %19, %5
  %20 = tail call zeroext i1 @isEmpty(ptr noundef %6)
  br label %.thread

.thread:                                          ; preds = %14, %12, %._crit_edge, %1
  %.3 = phi i1 [ false, %1 ], [ %20, %._crit_edge ], [ false, %12 ], [ false, %14 ]
  ret i1 %.3
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @isLeft(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @isMatch(i8 noundef signext, i8 noundef signext) 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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