; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-10-21 (A - Alter Board - dby)

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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %6 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %6)
  %8 = load ptr, ptr @stdout, align 8, !tbaa !5
  %9 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %8)
  br label %10

10:                                               ; preds = %47, %0
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %2, ptr noundef %3)
  %12 = icmp ne i32 %11, -1
  br i1 %12, label %13, label %48

13:                                               ; preds = %10
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = sdiv i32 %14, 2
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sdiv i32 %16, 2
  %18 = add nsw i32 %15, %17
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 2, ptr %4, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %30, %13
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %33

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %26, i32 noundef 1, i32 noundef %27, i32 noundef %28)
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = add nsw i32 %31, 2
  store i32 %32, ptr %4, align 4, !tbaa !9
  br label %20, !llvm.loop !11

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 2, ptr %5, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %44, %33
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %39, label %38

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

39:                                               ; preds = %34
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = load i32, ptr %2, align 4, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef 1, i32 noundef %40, i32 noundef %41, i32 noundef %42)
  br label %44

44:                                               ; preds = %39
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = add nsw i32 %45, 2
  store i32 %46, ptr %5, align 4, !tbaa !9
  br label %34, !llvm.loop !13

47:                                               ; preds = %38
  br label %10, !llvm.loop !14

48:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"any pointer", !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}


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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %3 = load ptr, ptr @stdin, align 8, !tbaa !5
  %4 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %3)
  %5 = load ptr, ptr @stdout, align 8, !tbaa !5
  %6 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %5)
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not16 = icmp eq i32 %7, -1
  br i1 %.not16, label %._crit_edge, label %.lr.ph17

.loopexit:                                        ; preds = %.lr.ph15, %.preheader
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not = icmp eq i32 %8, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph17, !llvm.loop !9

.lr.ph17:                                         ; preds = %0, %.loopexit
  %9 = load i32, ptr %1, align 4, !tbaa !11
  %10 = sdiv i32 %9, 2
  %11 = load i32, ptr %2, align 4, !tbaa !11
  %12 = sdiv i32 %11, 2
  %13 = add nsw i32 %12, %10
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %13)
  %15 = load i32, ptr %1, align 4, !tbaa !11
  %.not911 = icmp slt i32 %15, 2
  br i1 %.not911, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.lr.ph17
  %16 = load i32, ptr %2, align 4, !tbaa !11
  %.not1013 = icmp slt i32 %16, 2
  br i1 %.not1013, label %.loopexit, label %.lr.ph15

.lr.ph:                                           ; preds = %.lr.ph17, %.lr.ph
  %.0812 = phi i32 [ %19, %.lr.ph ], [ 2, %.lr.ph17 ]
  %17 = load i32, ptr %2, align 4, !tbaa !11
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %.0812, i32 noundef 1, i32 noundef %.0812, i32 noundef %17)
  %19 = add nuw nsw i32 %.0812, 2
  %20 = load i32, ptr %1, align 4, !tbaa !11
  %.not9 = icmp sgt i32 %19, %20
  br i1 %.not9, label %.preheader, label %.lr.ph, !llvm.loop !13

.lr.ph15:                                         ; preds = %.preheader, %.lr.ph15
  %.014 = phi i32 [ %23, %.lr.ph15 ], [ 2, %.preheader ]
  %21 = load i32, ptr %1, align 4, !tbaa !11
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef 1, i32 noundef %.014, i32 noundef %21, i32 noundef %.014)
  %23 = add nuw nsw i32 %.014, 2
  %24 = load i32, ptr %2, align 4, !tbaa !11
  %.not10 = icmp sgt i32 %23, %24
  br i1 %.not10, label %.loopexit, label %.lr.ph15, !llvm.loop !14

._crit_edge:                                      ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass