; LLVM IR from tangjz/acm-icpc :: hackerrank (xor-matrix)

; 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
@f = external dso_local global [2 x [100001 x i32]], align 16
@cur = external dso_local global i32, align 4
@nxt = external dso_local global i32, align 4
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %9 = load i64, ptr @m, align 8, !tbaa !5
  %10 = add nsw i64 %9, -1
  store i64 %10, ptr @m, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %25, %0
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = load i32, ptr @n, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  %17 = load i32, ptr @cur, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %18
  %20 = getelementptr inbounds [100001 x i32], ptr %19, i64 0, i64 0
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %23)
  br label %25

25:                                               ; preds = %16
  %26 = load i32, ptr %2, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %2, align 4, !tbaa !9
  br label %11, !llvm.loop !11

28:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %78, %28
  %30 = load i64, ptr @m, align 8, !tbaa !5
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %87

33:                                               ; preds = %29
  %34 = load i64, ptr @m, align 8, !tbaa !5
  %35 = xor i64 %34, -1
  %36 = and i64 %35, 1
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %33
  br label %78

39:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %70, %39
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = load i32, ptr @n, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %73

45:                                               ; preds = %40
  %46 = load i32, ptr @cur, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %47
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100001 x i32], ptr %48, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = load i32, ptr @cur, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = load i32, ptr @n, align 4, !tbaa !9
  %59 = call noundef i32 @_Z7mod_addiii(i32 noundef %56, i32 noundef %57, i32 noundef %58)
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100001 x i32], ptr %55, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = xor i32 %52, %62
  %64 = load i32, ptr @nxt, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %65
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100001 x i32], ptr %66, i64 0, i64 %68
  store i32 %63, ptr %69, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %45
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %6, align 4, !tbaa !9
  br label %40, !llvm.loop !13

73:                                               ; preds = %44
  %74 = load i32, ptr @cur, align 4, !tbaa !9
  %75 = xor i32 %74, 1
  store i32 %75, ptr @cur, align 4, !tbaa !9
  %76 = load i32, ptr @nxt, align 4, !tbaa !9
  %77 = xor i32 %76, 1
  store i32 %77, ptr @nxt, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %73, %38
  %79 = load i32, ptr %3, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %3, align 4, !tbaa !9
  %81 = load i32, ptr %4, align 4, !tbaa !9
  %82 = load i32, ptr %4, align 4, !tbaa !9
  %83 = load i32, ptr @n, align 4, !tbaa !9
  %84 = call noundef i32 @_Z7mod_addiii(i32 noundef %81, i32 noundef %82, i32 noundef %83)
  store i32 %84, ptr %4, align 4, !tbaa !9
  %85 = load i64, ptr @m, align 8, !tbaa !5
  %86 = ashr i64 %85, 1
  store i64 %86, ptr @m, align 8, !tbaa !5
  br label %29, !llvm.loop !14

87:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %110, %87
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = load i32, ptr @n, align 4, !tbaa !9
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %93, label %92

92:                                               ; preds = %88
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %113

93:                                               ; preds = %88
  %94 = load i32, ptr @cur, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %95
  %97 = load i32, ptr %7, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [100001 x i32], ptr %96, i64 0, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !9
  %101 = load i32, ptr %7, align 4, !tbaa !9
  %102 = load i32, ptr @n, align 4, !tbaa !9
  %103 = sub nsw i32 %102, 1
  %104 = icmp eq i32 %101, %103
  %105 = zext i1 %104 to i64
  %106 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %105
  %107 = load i8, ptr %106, align 1, !tbaa !15
  %108 = sext i8 %107 to i32
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %100, i32 noundef %108)
  br label %110

110:                                              ; preds = %93
  %111 = load i32, ptr %7, align 4, !tbaa !9
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %7, align 4, !tbaa !9
  br label %88, !llvm.loop !16

113:                                              ; preds = %92
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_addiii(i32 noundef, i32 noundef, i32 noundef) #3

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { 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 #1 = { "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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !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 global i32, align 4
@f = external dso_local global [2 x [100001 x i32]], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4
@nxt = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i64, ptr @m, align 8, !tbaa !5
  %3 = add nsw i64 %2, -1
  store i64 %3, ptr @m, align 8, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %thread-pre-split

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %6 = load i32, ptr @cur, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %7
  %9 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %thread-pre-split.loopexit, !llvm.loop !11

thread-pre-split.loopexit:                        ; preds = %.lr.ph
  %.pr.pre = load i64, ptr @m, align 8, !tbaa !5
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %thread-pre-split.loopexit, %0
  %14 = phi i32 [ %11, %thread-pre-split.loopexit ], [ %4, %0 ]
  %.pr = phi i64 [ %.pr.pre, %thread-pre-split.loopexit ], [ %3, %0 ]
  %.not28 = icmp eq i64 %.pr, 0
  br i1 %.not28, label %.preheader, label %.lr.ph31

.preheader.loopexit:                              ; preds = %42
  %.pre44 = load i32, ptr @n, align 4, !tbaa !9
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %thread-pre-split
  %15 = phi i32 [ %.pre44, %.preheader.loopexit ], [ %14, %thread-pre-split ]
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph33, label %._crit_edge34

.lr.ph31:                                         ; preds = %thread-pre-split, %42
  %.01729 = phi i32 [ %44, %42 ], [ 1, %thread-pre-split ]
  %17 = phi i64 [ %46, %42 ], [ %.pr, %thread-pre-split ]
  %18 = and i64 %17, 1
  %.not23.not = icmp eq i64 %18, 0
  %.pre43 = load i32, ptr @n, align 4, !tbaa !9
  br i1 %.not23.not, label %42, label %.preheader24

.preheader24:                                     ; preds = %.lr.ph31
  %19 = icmp sgt i32 %.pre43, 0
  br i1 %19, label %.lr.ph27, label %.preheader24.._crit_edge_crit_edge

.preheader24.._crit_edge_crit_edge:               ; preds = %.preheader24
  %.pre = load i32, ptr @nxt, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph27, %.preheader24.._crit_edge_crit_edge
  %20 = phi i32 [ %.pre43, %.preheader24.._crit_edge_crit_edge ], [ %39, %.lr.ph27 ]
  %21 = phi i32 [ %.pre, %.preheader24.._crit_edge_crit_edge ], [ %36, %.lr.ph27 ]
  %22 = load i32, ptr @cur, align 4, !tbaa !9
  %23 = xor i32 %22, 1
  store i32 %23, ptr @cur, align 4, !tbaa !9
  %24 = xor i32 %21, 1
  store i32 %24, ptr @nxt, align 4, !tbaa !9
  br label %42

.lr.ph27:                                         ; preds = %.preheader24, %.lr.ph27
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %.lr.ph27 ], [ 0, %.preheader24 ]
  %25 = phi i32 [ %39, %.lr.ph27 ], [ %.pre43, %.preheader24 ]
  %26 = load i32, ptr @cur, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %27, i64 %indvars.iv36
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = trunc nuw nsw i64 %indvars.iv36 to i32
  %31 = tail call noundef i32 @_Z7mod_addiii(i32 noundef %30, i32 noundef %.01729, i32 noundef %25)
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %27, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = xor i32 %34, %29
  %36 = load i32, ptr @nxt, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %37, i64 %indvars.iv36
  store i32 %35, ptr %38, align 4, !tbaa !9
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %39 = load i32, ptr @n, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next37, %40
  br i1 %41, label %.lr.ph27, label %._crit_edge, !llvm.loop !13

42:                                               ; preds = %.lr.ph31, %._crit_edge
  %43 = phi i32 [ %.pre43, %.lr.ph31 ], [ %20, %._crit_edge ]
  %44 = tail call noundef i32 @_Z7mod_addiii(i32 noundef %.01729, i32 noundef %.01729, i32 noundef %43)
  %45 = load i64, ptr @m, align 8, !tbaa !5
  %46 = ashr i64 %45, 1
  store i64 %46, ptr @m, align 8, !tbaa !5
  %.not = icmp ult i64 %45, 2
  br i1 %.not, label %.preheader.loopexit, label %.lr.ph31, !llvm.loop !14

._crit_edge34:                                    ; preds = %.lr.ph33, %.preheader
  ret i32 0

.lr.ph33:                                         ; preds = %.preheader, %.lr.ph33
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.lr.ph33 ], [ 0, %.preheader ]
  %47 = phi i32 [ %60, %.lr.ph33 ], [ %15, %.preheader ]
  %48 = load i32, ptr @cur, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2 x [100001 x i32]], ptr @f, i64 0, i64 %49, i64 %indvars.iv39
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = add nsw i32 %47, -1
  %53 = zext i32 %52 to i64
  %54 = icmp eq i64 %indvars.iv39, %53
  %55 = zext i1 %54 to i64
  %56 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !15
  %58 = sext i8 %57 to i32
  %59 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %51, i32 noundef %58)
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %60 = load i32, ptr @n, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = icmp slt i64 %indvars.iv.next40, %61
  br i1 %62, label %.lr.ph33, label %._crit_edge34, !llvm.loop !16
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_addiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress norecurse 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 = { nofree nounwind "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 = { 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" }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !12}


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