; LLVM IR from tangjz/acm-icpc :: uoj (2)

; 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
@m = external dso_local global i32, align 4
@f = external dso_local global [2 x i32], align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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 [4 x i8], align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  store i32 1073741823, ptr getelementptr inbounds ([2 x i32], ptr @f, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %54, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %57

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %18 = getelementptr inbounds [4 x i8], ptr %5, i64 0, i64 0
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %18, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %50, %17
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 2
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %53

24:                                               ; preds = %20
  %25 = getelementptr inbounds [4 x i8], ptr %5, i64 0, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  switch i32 %27, label %49 [
    i32 79, label %28
    i32 88, label %35
    i32 65, label %42
  ]

28:                                               ; preds = %24
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2 x i32], ptr @f, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = or i32 %33, %29
  store i32 %34, ptr %32, align 4, !tbaa !5
  br label %49

35:                                               ; preds = %24
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2 x i32], ptr @f, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = xor i32 %40, %36
  store i32 %41, ptr %39, align 4, !tbaa !5
  br label %49

42:                                               ; preds = %24
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [2 x i32], ptr @f, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = and i32 %47, %43
  store i32 %48, ptr %46, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %42, %35, %28, %24
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !10

53:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !12

57:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 29, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %107, %57
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = icmp sge i32 %59, 0
  br i1 %60, label %62, label %61

61:                                               ; preds = %58
  store i32 9, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %110

62:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %63 = load i32, ptr @f, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = ashr i32 %63, %64
  %66 = and i32 %65, 1
  store i32 %66, ptr %10, align 4, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %75, label %69

69:                                               ; preds = %62
  %70 = load i32, ptr @m, align 4, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = ashr i32 %70, %71
  %73 = and i32 %72, 1
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %87

75:                                               ; preds = %69, %62
  %76 = load i32, ptr %10, align 4, !tbaa !5
  %77 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @f, i64 0, i64 1), align 4, !tbaa !5
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = ashr i32 %77, %78
  %80 = and i32 %79, 1
  %81 = icmp slt i32 %76, %80
  br i1 %81, label %82, label %87

82:                                               ; preds = %75
  store i32 1, ptr %9, align 4, !tbaa !5
  %83 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @f, i64 0, i64 1), align 4, !tbaa !5
  %84 = load i32, ptr %7, align 4, !tbaa !5
  %85 = ashr i32 %83, %84
  %86 = and i32 %85, 1
  store i32 %86, ptr %10, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %82, %75, %69
  %88 = load i32, ptr %10, align 4, !tbaa !5
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = shl i32 %88, %89
  %91 = load i32, ptr @ans, align 4, !tbaa !5
  %92 = or i32 %91, %90
  store i32 %92, ptr @ans, align 4, !tbaa !5
  %93 = load i32, ptr @m, align 4, !tbaa !5
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = ashr i32 %93, %94
  %96 = and i32 %95, 1
  %97 = icmp ne i32 %96, 0
  br i1 %97, label %98, label %102

98:                                               ; preds = %87
  %99 = load i32, ptr %9, align 4, !tbaa !5
  %100 = icmp ne i32 %99, 0
  %101 = xor i1 %100, true
  br label %102

102:                                              ; preds = %98, %87
  %103 = phi i1 [ false, %87 ], [ %101, %98 ]
  %104 = zext i1 %103 to i32
  %105 = load i32, ptr %8, align 4, !tbaa !5
  %106 = or i32 %105, %104
  store i32 %106, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %107

107:                                              ; preds = %102
  %108 = load i32, ptr %7, align 4, !tbaa !5
  %109 = add nsw i32 %108, -1
  store i32 %109, ptr %7, align 4, !tbaa !5
  br label %58, !llvm.loop !13

110:                                              ; preds = %61
  %111 = load i32, ptr @ans, align 4, !tbaa !5
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %111)
  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

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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


; 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
@m = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [2 x i32], align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca [4 x i8], align 1
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  store i32 1073741823, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not38 = icmp slt i32 %4, 1
  br i1 %.not38, label %.preheader, label %.lr.ph

.preheader.loopexit:                              ; preds = %.split33.us
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %0
  %5 = phi i32 [ %.pre, %.preheader.loopexit ], [ 1073741823, %0 ]
  %6 = load i32, ptr @f, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  br label %27

.lr.ph:                                           ; preds = %0, %.split33.us
  %.02439 = phi i32 [ %23, %.split33.us ], [ 1, %0 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %1)
  %9 = load i8, ptr %2, align 1, !tbaa !9
  %10 = load i32, ptr %1, align 4
  switch i8 %9, label %.split33.us [
    i8 79, label %.split.us.preheader
    i8 88, label %.split.us34.preheader
    i8 65, label %.split.us36.preheader
  ]

.split.us36.preheader:                            ; preds = %.lr.ph
  %11 = load i32, ptr @f, align 4, !tbaa !5
  %12 = and i32 %11, %10
  store i32 %12, ptr @f, align 4, !tbaa !5
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  %14 = and i32 %13, %10
  br label %.split33.us.sink.split

.split.us34.preheader:                            ; preds = %.lr.ph
  %15 = load i32, ptr @f, align 4, !tbaa !5
  %16 = xor i32 %15, %10
  store i32 %16, ptr @f, align 4, !tbaa !5
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  %18 = xor i32 %17, %10
  br label %.split33.us.sink.split

.split.us.preheader:                              ; preds = %.lr.ph
  %19 = load i32, ptr @f, align 4, !tbaa !5
  %20 = or i32 %19, %10
  store i32 %20, ptr @f, align 4, !tbaa !5
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  %22 = or i32 %21, %10
  br label %.split33.us.sink.split

.split33.us.sink.split:                           ; preds = %.split.us.preheader, %.split.us34.preheader, %.split.us36.preheader
  %.sink = phi i32 [ %14, %.split.us36.preheader ], [ %18, %.split.us34.preheader ], [ %22, %.split.us.preheader ]
  store i32 %.sink, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  br label %.split33.us

.split33.us:                                      ; preds = %.split33.us.sink.split, %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %23 = add nuw nsw i32 %.02439, 1
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.02439, %24
  br i1 %.not.not, label %.lr.ph, label %.preheader.loopexit, !llvm.loop !10

25:                                               ; preds = %27
  store i32 %38, ptr @ans, align 4, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %38)
  ret i32 0

27:                                               ; preds = %.preheader, %27
  %.02141 = phi i32 [ 0, %.preheader ], [ %42, %27 ]
  %.02240 = phi i32 [ 29, %.preheader ], [ %43, %27 ]
  %28 = phi i32 [ %ans.promoted, %.preheader ], [ %38, %27 ]
  %29 = lshr i32 %6, %.02240
  %30 = and i32 %29, 1
  %.not27 = icmp eq i32 %.02141, 0
  %31 = shl nuw i32 1, %.02240
  %32 = and i32 %7, %31
  %.not28 = icmp eq i32 %32, 0
  %or.cond = select i1 %.not27, i1 %.not28, i1 false
  %33 = lshr i32 %5, %.02240
  %34 = and i32 %33, 1
  %35 = icmp uge i32 %30, %34
  %36 = select i1 %or.cond, i1 true, i1 %35
  %.0 = select i1 %36, i32 %30, i32 1
  %37 = shl nuw i32 %.0, %.02240
  %38 = or i32 %28, %37
  %39 = icmp ne i32 %32, 0
  %40 = select i1 %39, i1 %35, i1 false
  %41 = zext i1 %40 to i32
  %42 = or i32 %.02141, %41
  %43 = add nsw i32 %.02240, -1
  %.not = icmp eq i32 %.02240, 0
  br i1 %.not, label %25, label %27, !llvm.loop !12
}

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

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

attributes #0 = { mustprogress nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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