; LLVM IR from JessonYue/LeetCodeLearning :: Array/linchuanxin/Algorithm/day64_0803_leetcode20_有效的括号 (day64_leetcode20)

; 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
define dso_local zeroext i1 @isValid(ptr noundef %0) #0 {
  %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 i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %1
  store i1 true, ptr %2, align 1
  br label %113

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #5
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %4, align 4, !tbaa !10
  %20 = load i32, ptr %4, align 4, !tbaa !10
  %21 = srem i32 %20, 2
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %112

24:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %25 = load i32, ptr %4, align 4, !tbaa !10
  %26 = sext i32 %25 to i64
  %27 = call noalias ptr @malloc(i64 noundef %26) #6
  store ptr %27, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 -1, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !10
  br label %28

28:                                               ; preds = %103, %24
  %29 = load i32, ptr %8, align 4, !tbaa !10
  %30 = load i32, ptr %4, align 4, !tbaa !10
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 2, ptr %5, align 4
  br label %106

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !10
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !9
  store i8 %38, ptr %9, align 1, !tbaa !9
  %39 = load i8, ptr %9, align 1, !tbaa !9
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 40
  br i1 %41, label %50, label %42

42:                                               ; preds = %33
  %43 = load i8, ptr %9, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 91
  br i1 %45, label %50, label %46

46:                                               ; preds = %42
  %47 = load i8, ptr %9, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %48, 123
  br i1 %49, label %50, label %57

50:                                               ; preds = %46, %42, %33
  %51 = load i8, ptr %9, align 1, !tbaa !9
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !10
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !10
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %52, i64 %55
  store i8 %51, ptr %56, align 1, !tbaa !9
  br label %99

57:                                               ; preds = %46
  %58 = load i32, ptr %7, align 4, !tbaa !10
  %59 = icmp eq i32 %58, -1
  br i1 %59, label %60, label %61

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

61:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !10
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !9
  store i8 %66, ptr %10, align 1, !tbaa !9
  %67 = load i8, ptr %10, align 1, !tbaa !9
  %68 = sext i8 %67 to i32
  %69 = icmp ne i32 %68, 40
  br i1 %69, label %70, label %75

70:                                               ; preds = %61
  %71 = load i8, ptr %9, align 1, !tbaa !9
  %72 = sext i8 %71 to i32
  %73 = icmp eq i32 %72, 41
  br i1 %73, label %74, label %75

74:                                               ; preds = %70
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %96

75:                                               ; preds = %70, %61
  %76 = load i8, ptr %10, align 1, !tbaa !9
  %77 = sext i8 %76 to i32
  %78 = icmp ne i32 %77, 91
  br i1 %78, label %79, label %84

79:                                               ; preds = %75
  %80 = load i8, ptr %9, align 1, !tbaa !9
  %81 = sext i8 %80 to i32
  %82 = icmp eq i32 %81, 93
  br i1 %82, label %83, label %84

83:                                               ; preds = %79
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %96

84:                                               ; preds = %79, %75
  %85 = load i8, ptr %10, align 1, !tbaa !9
  %86 = sext i8 %85 to i32
  %87 = icmp ne i32 %86, 123
  br i1 %87, label %88, label %93

88:                                               ; preds = %84
  %89 = load i8, ptr %9, align 1, !tbaa !9
  %90 = sext i8 %89 to i32
  %91 = icmp eq i32 %90, 125
  br i1 %91, label %92, label %93

92:                                               ; preds = %88
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %96

93:                                               ; preds = %88, %84
  %94 = load i32, ptr %7, align 4, !tbaa !10
  %95 = add nsw i32 %94, -1
  store i32 %95, ptr %7, align 4, !tbaa !10
  store i32 0, ptr %5, align 4
  br label %96

96:                                               ; preds = %93, %92, %83, %74
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  %97 = load i32, ptr %5, align 4
  switch i32 %97, label %100 [
    i32 0, label %98
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98, %50
  store i32 0, ptr %5, align 4
  br label %100

100:                                              ; preds = %99, %96, %60
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  %101 = load i32, ptr %5, align 4
  switch i32 %101, label %106 [
    i32 0, label %102
  ]

102:                                              ; preds = %100
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %8, align 4, !tbaa !10
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %8, align 4, !tbaa !10
  br label %28, !llvm.loop !12

106:                                              ; preds = %100, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %107 = load i32, ptr %5, align 4
  switch i32 %107, label %111 [
    i32 2, label %108
  ]

108:                                              ; preds = %106
  %109 = load i32, ptr %7, align 4, !tbaa !10
  %110 = icmp eq i32 %109, -1
  store i1 %110, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %111

111:                                              ; preds = %108, %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %112

112:                                              ; preds = %111, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %113

113:                                              ; preds = %112, %15
  %114 = load i1, ptr %2, align 1
  ret i1 %114
}

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; 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 = { 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 allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !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: nofree nounwind memory(readwrite, argmem: read) uwtable
define dso_local zeroext i1 @isValid(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = icmp eq i8 %2, 0
  br i1 %3, label %.thread, label %4

4:                                                ; preds = %1
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %6 = trunc i64 %5 to i32
  %7 = and i32 %6, 1
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %.thread

8:                                                ; preds = %4
  %sext = shl i64 %5, 32
  %9 = ashr exact i64 %sext, 32
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #4
  %.not5566 = icmp slt i32 %6, 1
  br i1 %.not5566, label %.thread, label %.lr.ph.preheader

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %32
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %32 ]
  %.not5569 = phi i1 [ false, %.lr.ph.preheader ], [ %.not55, %32 ]
  %.04967 = phi i32 [ -1, %.lr.ph.preheader ], [ %.35263, %32 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !5
  switch i8 %13, label %17 [
    i8 123, label %.thread60
    i8 91, label %.thread60
    i8 40, label %.thread60
  ]

.thread60:                                        ; preds = %.lr.ph, %.lr.ph, %.lr.ph
  %14 = add nsw i32 %.04967, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %10, i64 %15
  store i8 %13, ptr %16, align 1, !tbaa !5
  br label %32

17:                                               ; preds = %.lr.ph
  %18 = icmp eq i32 %.04967, -1
  br i1 %18, label %.thread.loopexit, label %19

19:                                               ; preds = %17
  %20 = sext i32 %.04967 to i64
  %21 = getelementptr inbounds i8, ptr %10, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = icmp ne i8 %22, 40
  %24 = icmp eq i8 %13, 41
  %or.cond10 = and i1 %24, %23
  br i1 %or.cond10, label %.thread.loopexit, label %25

25:                                               ; preds = %19
  %26 = icmp ne i8 %22, 91
  %27 = icmp eq i8 %13, 93
  %or.cond13 = and i1 %27, %26
  br i1 %or.cond13, label %.thread.loopexit, label %28

28:                                               ; preds = %25
  %29 = icmp eq i8 %22, 123
  %30 = icmp ne i8 %13, 125
  %or.cond16.not = or i1 %30, %29
  %31 = sext i1 %or.cond16.not to i32
  %spec.select = add nsw i32 %.04967, %31
  br i1 %or.cond16.not, label %32, label %.thread.loopexit

32:                                               ; preds = %.thread60, %28
  %.35263 = phi i32 [ %14, %.thread60 ], [ %spec.select, %28 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not55 = icmp uge i64 %indvars.iv.next, %11
  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond, label %.thread.loopexit, label %.lr.ph, !llvm.loop !8

.thread.loopexit:                                 ; preds = %25, %19, %17, %32, %28
  %.not55.lcssa.ph = phi i1 [ %.not5569, %28 ], [ %.not55, %32 ], [ %.not5569, %17 ], [ %.not5569, %19 ], [ %.not5569, %25 ]
  %.453.ph = phi i32 [ %spec.select, %28 ], [ %.35263, %32 ], [ -1, %17 ], [ %.04967, %19 ], [ %.04967, %25 ]
  %33 = icmp eq i32 %.453.ph, -1
  %34 = select i1 %.not55.lcssa.ph, i1 %33, i1 false
  br label %.thread

.thread:                                          ; preds = %8, %.thread.loopexit, %4, %1
  %.7 = phi i1 [ true, %1 ], [ false, %4 ], [ true, %8 ], [ %34, %.thread.loopexit ]
  ret i1 %.7
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

attributes #0 = { nofree nounwind memory(readwrite, argmem: 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 #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 allocsize(0) }

!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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass