; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 28. Codechef Problems/Fire-Escape-Routes.ll (Z9recursioniii)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [1001 x [1001 x i32]], align 16
@flag = external dso_local global [1001 x [1001 x i8]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9recursioniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [1001 x [1001 x i8]], ptr @flag, i64 0, i64 %10
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1001 x i8], ptr %11, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9, !range !11, !noundef !12
  %16 = trunc i8 %15 to i1
  br i1 %16, label %17, label %35

17:                                               ; preds = %3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1001 x [1001 x i32]], ptr @a, i64 0, i64 %19
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1001 x i32], ptr %20, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp ne i32 %24, %25
  br i1 %26, label %35, label %27

27:                                               ; preds = %17
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp sgt i32 %28, %29
  br i1 %30, label %35, label %31

31:                                               ; preds = %27
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = icmp sgt i32 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %31, %27, %17, %3
  store i32 0, ptr %4, align 4
  br label %68

36:                                               ; preds = %31
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1001 x [1001 x i8]], ptr @flag, i64 0, i64 %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1001 x i8], ptr %39, i64 0, i64 %41
  store i8 0, ptr %42, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = call noundef i32 @_Z9recursioniii(i32 noundef %44, i32 noundef %45, i32 noundef %46)
  %48 = add nsw i32 1, %47
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = call noundef i32 @_Z9recursioniii(i32 noundef %49, i32 noundef %51, i32 noundef %52)
  %54 = add nsw i32 %48, %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = call noundef i32 @_Z9recursioniii(i32 noundef %56, i32 noundef %57, i32 noundef %58)
  %60 = add nsw i32 %54, %59
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = call noundef i32 @_Z9recursioniii(i32 noundef %61, i32 noundef %63, i32 noundef %64)
  %66 = add nsw i32 %60, %65
  store i32 %66, ptr %8, align 4, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %67, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %68

68:                                               ; preds = %36, %35
  %69 = load i32, ptr %4, align 4
  ret i32 %69
}

; 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

attributes #0 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [1001 x [1001 x i32]], align 16
@flag = external dso_local local_unnamed_addr global [1001 x [1001 x i8]], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z9recursioniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds [1001 x [1001 x i8]], ptr @flag, i64 0, i64 %4, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5, !range !9, !noundef !10
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %3
  %9 = add nsw i32 %0, -1
  %10 = add nsw i32 %0, 1
  br label %11

11:                                               ; preds = %.lr.ph, %tailrecurse
  %indvars.iv = phi i64 [ %5, %.lr.ph ], [ %indvars.iv.next, %tailrecurse ]
  %12 = phi ptr [ %6, %.lr.ph ], [ %30, %tailrecurse ]
  %accumulator.tr31 = phi i32 [ 0, %.lr.ph ], [ %29, %tailrecurse ]
  %13 = getelementptr inbounds [1001 x [1001 x i32]], ptr @a, i64 0, i64 %4, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %.not = icmp ne i32 %14, %2
  %15 = load i32, ptr @n, align 4
  %16 = icmp slt i32 %15, %0
  %or.cond = select i1 %.not, i1 true, i1 %16
  %17 = load i32, ptr @m, align 4
  %18 = sext i32 %17 to i64
  %19 = icmp sgt i64 %indvars.iv, %18
  %or.cond28 = select i1 %or.cond, i1 true, i1 %19
  br i1 %or.cond28, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %11
  store i8 0, ptr %12, align 1, !tbaa !5
  %20 = trunc nsw i64 %indvars.iv to i32
  %21 = tail call noundef i32 @_Z9recursioniii(i32 noundef %9, i32 noundef %20, i32 noundef %2)
  %22 = trunc i64 %indvars.iv to i32
  %23 = add i32 %22, -1
  %24 = tail call noundef i32 @_Z9recursioniii(i32 noundef %0, i32 noundef %23, i32 noundef %2)
  %25 = tail call noundef i32 @_Z9recursioniii(i32 noundef %10, i32 noundef %20, i32 noundef %2)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %26 = add i32 %accumulator.tr31, 1
  %27 = add i32 %26, %21
  %28 = add i32 %27, %24
  %29 = add i32 %28, %25
  %30 = getelementptr inbounds [1001 x [1001 x i8]], ptr @flag, i64 0, i64 %4, i64 %indvars.iv.next
  %31 = load i8, ptr %30, align 1, !tbaa !5, !range !9, !noundef !10
  %32 = trunc nuw i8 %31 to i1
  br i1 %32, label %11, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %11, %tailrecurse, %3
  %accumulator.tr.lcssa = phi i32 [ 0, %3 ], [ %29, %tailrecurse ], [ %accumulator.tr31, %11 ]
  ret i32 %accumulator.tr.lcssa
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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