; LLVM IR from eyangch/competitive-programming :: USACOcontests/silver/2016.02/pails.ll (Z3dfsiii)

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

@X = external dso_local global i32, align 4
@Y = external dso_local global i32, align 4
@K = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@vis = external dso_local global [101 x [101 x [101 x i8]]], align 16
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr @K, align 4, !tbaa !5
  %10 = icmp sgt i32 %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  br label %92

12:                                               ; preds = %3
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [101 x [101 x [101 x i8]]], ptr @vis, i64 0, i64 %14
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [101 x [101 x i8]], ptr %15, i64 0, i64 %17
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [101 x i8], ptr %18, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9, !range !11, !noundef !12
  %23 = trunc i8 %22 to i1
  br i1 %23, label %24, label %25

24:                                               ; preds = %12
  br label %92

25:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = load i32, ptr @M, align 4, !tbaa !5
  %30 = sub nsw i32 %28, %29
  %31 = call i32 @llvm.abs.i32(i32 %30, i1 true)
  store i32 %31, ptr %7, align 4, !tbaa !5
  %32 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [101 x [101 x [101 x i8]]], ptr @vis, i64 0, i64 %35
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [101 x [101 x i8]], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [101 x i8], ptr %39, i64 0, i64 %41
  store i8 1, ptr %42, align 1, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr @X, align 4, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %45, i32 noundef %46, i32 noundef %47)
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr @Y, align 4, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %48, i32 noundef %49, i32 noundef %50)
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef 0, i32 noundef %51, i32 noundef %52)
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %53, i32 noundef 0, i32 noundef %54)
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = load i32, ptr @X, align 4, !tbaa !5
  %59 = icmp sle i32 %57, %58
  br i1 %59, label %60, label %65

60:                                               ; preds = %25
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %61, %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %63, i32 noundef 0, i32 noundef %64)
  br label %73

65:                                               ; preds = %25
  %66 = load i32, ptr @X, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr @X, align 4, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sub nsw i32 %68, %69
  %71 = sub nsw i32 %67, %70
  %72 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %66, i32 noundef %71, i32 noundef %72)
  br label %73

73:                                               ; preds = %65, %60
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = add nsw i32 %74, %75
  %77 = load i32, ptr @Y, align 4, !tbaa !5
  %78 = icmp sle i32 %76, %77
  br i1 %78, label %79, label %84

79:                                               ; preds = %73
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %80, %81
  %83 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef 0, i32 noundef %82, i32 noundef %83)
  br label %92

84:                                               ; preds = %73
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = load i32, ptr @Y, align 4, !tbaa !5
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = sub nsw i32 %86, %87
  %89 = sub nsw i32 %85, %88
  %90 = load i32, ptr @Y, align 4, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %89, i32 noundef %90, i32 noundef %91)
  br label %92

92:                                               ; preds = %84, %79, %24, %11
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

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

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 = { inlinehint mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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"

@X = external dso_local local_unnamed_addr global i32, align 4
@Y = external dso_local local_unnamed_addr global i32, align 4
@K = external dso_local local_unnamed_addr global i32, align 4
@M = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [101 x [101 x [101 x i8]]], align 16
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  %5 = load i32, ptr @K, align 4, !tbaa !5
  %6 = icmp slt i32 %5, %2
  br i1 %6, label %33, label %7

7:                                                ; preds = %3
  %8 = sext i32 %0 to i64
  %9 = sext i32 %1 to i64
  %10 = sext i32 %2 to i64
  %11 = getelementptr inbounds [101 x [101 x [101 x i8]]], ptr @vis, i64 0, i64 %8, i64 %9, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !9, !range !11, !noundef !12
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %33, label %14

14:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %15 = add i32 %1, %0
  %16 = load i32, ptr @M, align 4, !tbaa !5
  %17 = sub nsw i32 %15, %16
  %18 = tail call i32 @llvm.abs.i32(i32 %17, i1 true)
  store i32 %18, ptr %4, align 4, !tbaa !5
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %20 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %20, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  store i8 1, ptr %11, align 1, !tbaa !9
  %21 = add nsw i32 %2, 1
  %22 = load i32, ptr @X, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %22, i32 noundef %1, i32 noundef %21)
  %23 = load i32, ptr @Y, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %0, i32 noundef %23, i32 noundef %21)
  call void @_Z3dfsiii(i32 noundef 0, i32 noundef %1, i32 noundef %21)
  call void @_Z3dfsiii(i32 noundef %0, i32 noundef 0, i32 noundef %21)
  %24 = load i32, ptr @X, align 4, !tbaa !5
  %.not = icmp sgt i32 %15, %24
  br i1 %.not, label %26, label %25

25:                                               ; preds = %14
  call void @_Z3dfsiii(i32 noundef %15, i32 noundef 0, i32 noundef %21)
  br label %28

26:                                               ; preds = %14
  %27 = sub i32 %15, %24
  call void @_Z3dfsiii(i32 noundef %24, i32 noundef %27, i32 noundef %21)
  br label %28

28:                                               ; preds = %26, %25
  %29 = load i32, ptr @Y, align 4, !tbaa !5
  %.not37 = icmp sgt i32 %15, %29
  br i1 %.not37, label %31, label %30

30:                                               ; preds = %28
  call void @_Z3dfsiii(i32 noundef 0, i32 noundef %15, i32 noundef %21)
  br label %33

31:                                               ; preds = %28
  %32 = sub i32 %15, %29
  call void @_Z3dfsiii(i32 noundef %32, i32 noundef %29, i32 noundef %21)
  br label %33

33:                                               ; preds = %7, %3, %31, %30
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass