; LLVM IR from xuxping/codelife :: algorthms/stack (isBracketsMatch)

; 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 [9 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @isLeftBrackets(i8 noundef signext) #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
declare dso_local i32 @isRightBrackets(i8 noundef signext) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @isLeftMatchRight(i8 noundef signext, i8 noundef signext) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @isBracketsMatch(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [100 x i8], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %15, label %10

10:                                               ; preds = %1
  %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 = %10, %1
  store i32 0, ptr %2, align 4
  br label %77

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

17:                                               ; preds = %67, %16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %70

22:                                               ; preds = %17
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = call i32 @isLeftBrackets(i8 noundef signext %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %22
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !10
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !10
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100 x i8], ptr %5, i64 0, i64 %32
  store i8 %29, ptr %33, align 1, !tbaa !9
  br label %67

34:                                               ; preds = %22
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = call i32 @isRightBrackets(i8 noundef signext %36)
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %66

39:                                               ; preds = %34
  %40 = load i32, ptr %6, align 4, !tbaa !10
  %41 = icmp sge i32 %40, 0
  br i1 %41, label %42, label %63

42:                                               ; preds = %39
  %43 = load i32, ptr %6, align 4, !tbaa !10
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100 x i8], ptr %5, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = call i32 @isLeftMatchRight(i8 noundef signext %46, i8 noundef signext %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %63

51:                                               ; preds = %42
  %52 = load i32, ptr %6, align 4, !tbaa !10
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100 x i8], ptr %5, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = sext i8 %58 to i32
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %56, i32 noundef %59)
  %61 = load i32, ptr %6, align 4, !tbaa !10
  %62 = add nsw i32 %61, -1
  store i32 %62, ptr %6, align 4, !tbaa !10
  br label %65

63:                                               ; preds = %42, %39
  store i32 0, ptr %4, align 4, !tbaa !10
  %64 = load i32, ptr %4, align 4, !tbaa !10
  store i32 %64, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %76

65:                                               ; preds = %51
  br label %66

66:                                               ; preds = %65, %34
  br label %67

67:                                               ; preds = %66, %27
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %3, align 8, !tbaa !5
  br label %17, !llvm.loop !12

70:                                               ; preds = %17
  %71 = load i32, ptr %6, align 4, !tbaa !10
  %72 = icmp slt i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %70
  store i32 1, ptr %4, align 4, !tbaa !10
  br label %74

74:                                               ; preds = %73, %70
  %75 = load i32, ptr %4, align 4, !tbaa !10
  store i32 %75, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %76

76:                                               ; preds = %74, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 100, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %77

77:                                               ; preds = %76, %15
  %78 = load i32, ptr %2, align 4
  ret i32 %78
}

declare i32 @printf(ptr noundef, ...) #2

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 }

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

@.str = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @isLeftBrackets(i8 noundef signext) 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
declare dso_local i32 @isRightBrackets(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @isLeftMatchRight(i8 noundef signext, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @isBracketsMatch(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [100 x i8], align 16
  %3 = icmp eq ptr %0, null
  br i1 %3, label %35, label %4

4:                                                ; preds = %1
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %35, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %2) #3
  br label %8

8:                                                ; preds = %7, %32
  %.027 = phi i32 [ -1, %7 ], [ %.1, %32 ]
  %.01826 = phi ptr [ %0, %7 ], [ %33, %32 ]
  %9 = phi i8 [ %5, %7 ], [ %.pr, %32 ]
  %10 = tail call i32 @isLeftBrackets(i8 noundef signext %9)
  %.not22 = icmp eq i32 %10, 0
  %11 = load i8, ptr %.01826, align 1, !tbaa !5
  br i1 %.not22, label %16, label %12

12:                                               ; preds = %8
  %13 = add nsw i32 %.027, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100 x i8], ptr %2, i64 0, i64 %14
  store i8 %11, ptr %15, align 1, !tbaa !5
  br label %32

16:                                               ; preds = %8
  %17 = tail call i32 @isRightBrackets(i8 noundef signext %11)
  %.not23 = icmp eq i32 %17, 0
  br i1 %.not23, label %32, label %18

18:                                               ; preds = %16
  %19 = icmp sgt i32 %.027, -1
  br i1 %19, label %20, label %.loopexit

20:                                               ; preds = %18
  %21 = zext nneg i32 %.027 to i64
  %22 = getelementptr inbounds [100 x i8], ptr %2, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = load i8, ptr %.01826, align 1, !tbaa !5
  %25 = tail call i32 @isLeftMatchRight(i8 noundef signext %23, i8 noundef signext %24)
  %.not24 = icmp eq i32 %25, 0
  br i1 %.not24, label %.loopexit, label %26

26:                                               ; preds = %20
  %27 = sext i8 %23 to i32
  %28 = load i8, ptr %.01826, align 1, !tbaa !5
  %29 = sext i8 %28 to i32
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %27, i32 noundef %29)
  %31 = add nsw i32 %.027, -1
  br label %32

32:                                               ; preds = %16, %26, %12
  %.1 = phi i32 [ %13, %12 ], [ %31, %26 ], [ %.027, %16 ]
  %33 = getelementptr inbounds i8, ptr %.01826, i64 1
  %.pr = load i8, ptr %33, align 1, !tbaa !5
  %.not = icmp eq i8 %.pr, 0
  br i1 %.not, label %34, label %8, !llvm.loop !8

34:                                               ; preds = %32
  %.0.lobit = lshr i32 %.1, 31
  br label %.loopexit

.loopexit:                                        ; preds = %18, %20, %34
  %.019 = phi i32 [ %.0.lobit, %34 ], [ 0, %20 ], [ 0, %18 ]
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %2) #3
  br label %35

35:                                               ; preds = %1, %4, %.loopexit
  %.120 = phi i32 [ %.019, %.loopexit ], [ 0, %4 ], [ 0, %1 ]
  ret i32 %.120
}

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

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 = { 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 #3 = { 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 = !{!"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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass