; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2020-21/Dec/Bronze/rut_bronze_brian_2.ll (Z9when_hitsiii)

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

%struct.Cow = type { i32, i32, i32, i8 }

@C = external dso_local global [50 x %struct.Cow], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9when_hitsiii(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 %struct.Cow, align 4
  %9 = alloca %struct.Cow, align 4
  %10 = 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
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [50 x %struct.Cow], ptr @C, i64 0, i64 %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 16 %13, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [50 x %struct.Cow], ptr @C, i64 0, i64 %15
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 16 %16, i64 16, i1 false), !tbaa.struct !9
  %17 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %98

21:                                               ; preds = %3
  %22 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 3
  %23 = load i8, ptr %22, align 4, !tbaa !13
  %24 = sext i8 %23 to i32
  %25 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 3
  %26 = load i8, ptr %25, align 4, !tbaa !13
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %24, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %21
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %98

30:                                               ; preds = %21
  %31 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 3
  %32 = load i8, ptr %31, align 4, !tbaa !13
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 69
  br i1 %34, label %35, label %40

35:                                               ; preds = %30
  %36 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 1
  %37 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 2
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %36, ptr noundef nonnull align 4 dereferenceable(4) %37) #4
  %38 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 1
  %39 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 2
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %38, ptr noundef nonnull align 4 dereferenceable(4) %39) #4
  br label %40

40:                                               ; preds = %35, %30
  %41 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = icmp sle i32 %42, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %40
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %98

47:                                               ; preds = %40
  %48 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !11
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %68

51:                                               ; preds = %47
  %52 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !15
  %54 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !15
  %56 = icmp sgt i32 %53, %55
  br i1 %56, label %66, label %57

57:                                               ; preds = %51
  %58 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !15
  %60 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !15
  %62 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = sub nsw i32 %61, %63
  %65 = icmp slt i32 %59, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %57, %51
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %98

67:                                               ; preds = %57
  br label %90

68:                                               ; preds = %47
  %69 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !15
  %71 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !15
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = sub nsw i32 %72, %73
  %75 = icmp slt i32 %70, %74
  br i1 %75, label %88, label %76

76:                                               ; preds = %68
  %77 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 1
  %78 = load i32, ptr %77, align 4, !tbaa !15
  %79 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !15
  %81 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 2
  %82 = load i32, ptr %81, align 4, !tbaa !14
  %83 = add nsw i32 %80, %82
  %84 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 2
  %85 = load i32, ptr %84, align 4, !tbaa !14
  %86 = sub nsw i32 %83, %85
  %87 = icmp sge i32 %78, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %76, %68
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %98

89:                                               ; preds = %76
  br label %90

90:                                               ; preds = %89, %67
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = getelementptr inbounds %struct.Cow, ptr %9, i32 0, i32 2
  %93 = load i32, ptr %92, align 4, !tbaa !14
  %94 = add nsw i32 %91, %93
  %95 = getelementptr inbounds %struct.Cow, ptr %8, i32 0, i32 2
  %96 = load i32, ptr %95, align 4, !tbaa !14
  %97 = sub nsw i32 %94, %96
  store i32 %97, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %98

98:                                               ; preds = %90, %88, %66, %46, %29, %20
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  %99 = load i32, ptr %4, align 4
  ret i32 %99
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 1, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS3Cow", !6, i64 0, !6, i64 4, !6, i64 8, !7, i64 12}
!13 = !{!12, !7, i64 12}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 4}


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

%struct.Cow = type { i32, i32, i32, i8 }

@C = external dso_local local_unnamed_addr global [50 x %struct.Cow], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9when_hitsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.Cow, align 4
  %5 = alloca %struct.Cow, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [50 x %struct.Cow], ptr @C, i64 0, i64 %6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %4, ptr noundef nonnull align 16 dereferenceable(16) %7, i64 16, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds [50 x %struct.Cow], ptr @C, i64 0, i64 %8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %5, ptr noundef nonnull align 16 dereferenceable(16) %9, i64 16, i1 false), !tbaa.struct !5
  %10 = load i32, ptr %4, align 4, !tbaa !11
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %48

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %4, i64 12
  %13 = load i8, ptr %12, align 4, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %5, i64 12
  %15 = load i8, ptr %14, align 4, !tbaa !13
  %16 = icmp eq i8 %13, %15
  br i1 %16, label %48, label %17

17:                                               ; preds = %11
  %18 = icmp eq i8 %13, 69
  br i1 %18, label %19, label %24

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %4, i64 4
  %21 = getelementptr inbounds i8, ptr %4, i64 8
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %20, ptr noundef nonnull align 4 dereferenceable(4) %21) #4
  %22 = getelementptr inbounds i8, ptr %5, i64 4
  %23 = getelementptr inbounds i8, ptr %5, i64 8
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %22, ptr noundef nonnull align 4 dereferenceable(4) %23) #4
  br label %24

24:                                               ; preds = %19, %17
  %25 = getelementptr inbounds i8, ptr %5, i64 8
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %4, i64 8
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %.not12 = icmp sgt i32 %26, %28
  br i1 %.not12, label %29, label %48

29:                                               ; preds = %24
  %30 = load i32, ptr %5, align 4, !tbaa !11
  %.not13 = icmp eq i32 %30, 0
  %31 = getelementptr inbounds i8, ptr %4, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %5, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !15
  br i1 %.not13, label %39, label %35

35:                                               ; preds = %29
  %36 = icmp sgt i32 %32, %34
  %37 = sub nsw i32 %34, %30
  %38 = icmp slt i32 %32, %37
  %or.cond = select i1 %36, i1 true, i1 %38
  br i1 %or.cond, label %48, label %45

39:                                               ; preds = %29
  %40 = sub nsw i32 %34, %2
  %41 = icmp slt i32 %32, %40
  br i1 %41, label %48, label %42

42:                                               ; preds = %39
  %43 = sub i32 %26, %28
  %44 = add i32 %43, %34
  %.not14 = icmp slt i32 %32, %44
  br i1 %.not14, label %45, label %48

45:                                               ; preds = %35, %42
  %46 = add nsw i32 %26, %2
  %47 = sub i32 %46, %28
  br label %48

48:                                               ; preds = %39, %42, %35, %24, %11, %3, %45
  %.0 = phi i32 [ %47, %45 ], [ 0, %3 ], [ 0, %11 ], [ 0, %24 ], [ 0, %35 ], [ 0, %42 ], [ 0, %39 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  ret i32 %.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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6, i64 12, i64 1, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTS3Cow", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12}
!13 = !{!12, !8, i64 12}
!14 = !{!12, !7, i64 8}
!15 = !{!12, !7, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass