; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2009-10 (rocks)

; 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
@T = external dso_local global i32, align 4
@L = external dso_local global i32, align 4
@depth = external dso_local global [10001 x i32], align 16
@P = external dso_local global [10001 x i32], align 16
@R = external dso_local global [10001 x i32], align 16
@cur = external dso_local global i32, align 4
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @_ZN2io2reIiJiiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) @N, ptr noundef nonnull align 4 dereferenceable(4) @T, ptr noundef nonnull align 4 dereferenceable(4) @L)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %47, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @N, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  %10 = icmp slt i32 %7, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %50

12:                                               ; preds = %6
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [10001 x i32], ptr @P, i64 0, i64 %14
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %17
  call void @_ZN2io2reIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %18)
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10001 x i32], ptr @P, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = and i32 %33, 1
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %46

36:                                               ; preds = %12
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr @L, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = srem i32 %40, %42
  %44 = load i32, ptr @cur, align 4, !tbaa !5
  %45 = xor i32 %44, %43
  store i32 %45, ptr @cur, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %36, %12
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

50:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %100, %50
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = load i32, ptr @T, align 4, !tbaa !5
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %103

56:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @_ZN2io2reIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = and i32 %60, 1
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %73

63:                                               ; preds = %56
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr @L, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = srem i32 %67, %69
  %71 = load i32, ptr @cur, align 4, !tbaa !5
  %72 = xor i32 %71, %70
  store i32 %72, ptr @cur, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %63, %56
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %76
  store i32 %74, ptr %77, align 4, !tbaa !5
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = and i32 %81, 1
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %94

84:                                               ; preds = %73
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = load i32, ptr @L, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  %91 = srem i32 %88, %90
  %92 = load i32, ptr @cur, align 4, !tbaa !5
  %93 = xor i32 %92, %91
  store i32 %93, ptr @cur, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %84, %73
  %95 = load i32, ptr @cur, align 4, !tbaa !5
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %98

97:                                               ; preds = %94
  call void @_ZN2io2prIA4_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(4) @.str.5)
  br label %99

98:                                               ; preds = %94
  call void @_ZN2io2prIA3_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(3) @.str.6)
  br label %99

99:                                               ; preds = %98, %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %3, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %3, align 4, !tbaa !5
  br label %51, !llvm.loop !11

103:                                              ; preds = %55
  %104 = load i32, ptr %1, align 4
  ret i32 %104
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2reIiJiiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2reIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2prIA4_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2prIA3_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(3)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress norecurse 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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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 global i32, align 4
@T = external dso_local global i32, align 4
@L = external dso_local global i32, align 4
@depth = external dso_local local_unnamed_addr global [10001 x i32], align 16
@P = external dso_local global [10001 x i32], align 16
@R = external dso_local global [10001 x i32], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  tail call void @_ZN2io2reIiJiiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) @N, ptr noundef nonnull align 4 dereferenceable(4) @T, ptr noundef nonnull align 4 dereferenceable(4) @L)
  %3 = load i32, ptr @N, align 4, !tbaa !5
  %.not16 = icmp slt i32 %3, 2
  br i1 %.not16, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %22, %0
  %4 = load i32, ptr @T, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph19, label %._crit_edge

.lr.ph:                                           ; preds = %0, %22
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ 2, %0 ]
  %6 = getelementptr inbounds [10001 x i32], ptr @P, i64 0, i64 %indvars.iv
  %7 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %indvars.iv
  tail call void @_ZN2io2reIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %8 = load i32, ptr %6, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %indvars.iv
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = and i32 %11, 1
  %.not15.not = icmp eq i32 %14, 0
  br i1 %.not15.not, label %15, label %22

15:                                               ; preds = %.lr.ph
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr @L, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = srem i32 %16, %18
  %20 = load i32, ptr @cur, align 4, !tbaa !5
  %21 = xor i32 %20, %19
  store i32 %21, ptr @cur, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %.lr.ph, %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr @N, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %.not.not = icmp slt i64 %indvars.iv, %24
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %47, %.preheader
  ret i32 0

.lr.ph19:                                         ; preds = %.preheader, %47
  %.018 = phi i32 [ %48, %47 ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @_ZN2io2reIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [10001 x i32], ptr @depth, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = and i32 %28, 1
  %.not12 = icmp eq i32 %29, 0
  br i1 %.not12, label %.thread, label %31

.thread:                                          ; preds = %.lr.ph19
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %.pr = load i32, ptr @cur, align 4, !tbaa !5
  br label %42

31:                                               ; preds = %.lr.ph19
  %32 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %26
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load i32, ptr @L, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = srem i32 %33, %35
  %37 = load i32, ptr @cur, align 4, !tbaa !5
  %38 = xor i32 %37, %36
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = srem i32 %39, %35
  %41 = xor i32 %38, %40
  store i32 %41, ptr @cur, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.thread, %31
  %.sink = phi i32 [ %30, %.thread ], [ %39, %31 ]
  %43 = phi i32 [ %.pr, %.thread ], [ %41, %31 ]
  %44 = getelementptr inbounds [10001 x i32], ptr @R, i64 0, i64 %26
  store i32 %.sink, ptr %44, align 4
  %.not14 = icmp eq i32 %43, 0
  br i1 %.not14, label %46, label %45

45:                                               ; preds = %42
  call void @_ZN2io2prIA4_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(4) @.str.5)
  br label %47

46:                                               ; preds = %42
  call void @_ZN2io2prIA3_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(3) @.str.6)
  br label %47

47:                                               ; preds = %46, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %48 = add nuw nsw i32 %.018, 1
  %49 = load i32, ptr @T, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %.lr.ph19, label %._crit_edge, !llvm.loop !11
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2reIiJiiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2reIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2prIA4_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2io2prIA3_cEEvRKT_(ptr noundef nonnull align 1 dereferenceable(3)) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress norecurse 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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass