; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/168 Division 2/Problem B/B.ll (Z7go_leftiiii)

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

@grid = external dso_local global [52 x [52 x i32]], align 16
@visited = external dso_local global [52 x [52 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5go_upiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7go_downiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7go_leftiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [52 x [52 x i32]], ptr @grid, i64 0, i64 %11
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [52 x i32], ptr %12, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %68

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

28:                                               ; preds = %19
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [52 x [52 x i32]], ptr @visited, i64 0, i64 %30
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [52 x i32], ptr %31, i64 0, i64 %33
  store i32 1, ptr %34, align 4, !tbaa !5
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %36

35:                                               ; preds = %19
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %35, %28
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = call noundef i32 @_Z7go_leftiiii(i32 noundef %37, i32 noundef %39, i32 noundef %40, i32 noundef %41)
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %8, align 4, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %66

47:                                               ; preds = %36
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  %54 = call noundef i32 @_Z5go_upiiii(i32 noundef %49, i32 noundef %50, i32 noundef %51, i32 noundef %53)
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = add nsw i32 %55, %54
  store i32 %56, ptr %8, align 4, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = call noundef i32 @_Z7go_downiiii(i32 noundef %58, i32 noundef %59, i32 noundef %60, i32 noundef %62)
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = add nsw i32 %64, %63
  store i32 %65, ptr %8, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %47, %36
  %67 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %67, ptr %5, align 4
  br label %68

68:                                               ; preds = %66, %18
  %69 = load i32, ptr %5, align 4
  ret i32 %69
}

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

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


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

@grid = external dso_local local_unnamed_addr global [52 x [52 x i32]], align 16
@visited = external dso_local local_unnamed_addr global [52 x [52 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5go_upiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7go_downiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7go_leftiiii(i32 noundef %0, i32 noundef %1, i32 %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [52 x [52 x i32]], ptr @grid, i64 0, i64 %5, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 1
  br i1 %.not, label %9, label %26

9:                                                ; preds = %4
  %10 = getelementptr inbounds [52 x [52 x i32]], ptr @visited, i64 0, i64 %5, i64 %6
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %9, %13
  %.024 = phi i32 [ 1, %13 ], [ 0, %9 ]
  %15 = add nsw i32 %1, -1
  %16 = tail call noundef i32 @_Z7go_leftiiii(i32 noundef %0, i32 noundef %15, i32 poison, i32 noundef %3)
  %17 = add nsw i32 %16, %.024
  %18 = icmp eq i32 %3, 0
  br i1 %18, label %19, label %26

19:                                               ; preds = %14
  %20 = add nsw i32 %0, -1
  %21 = tail call noundef i32 @_Z5go_upiiii(i32 noundef %20, i32 noundef %1, i32 noundef %17, i32 noundef 1)
  %22 = add nsw i32 %21, %17
  %23 = add nsw i32 %0, 1
  %24 = tail call noundef i32 @_Z7go_downiiii(i32 noundef %23, i32 noundef %1, i32 noundef %22, i32 noundef 1)
  %25 = add nsw i32 %22, %24
  br label %26

26:                                               ; preds = %14, %19, %4
  %.0 = phi i32 [ 0, %4 ], [ %25, %19 ], [ %17, %14 ]
  ret i32 %.0
}

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

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


; Effective O3 passes: DeadArgumentEliminationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass