; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-03-13 (F - GCD and LCM - tjz)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

5:                                                ; preds = %93, %13, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef @a, ptr noundef @b)
  %7 = icmp eq i32 %6, 3
  br i1 %7, label %8, label %96

8:                                                ; preds = %5
  %9 = load i32, ptr @b, align 4, !tbaa !5
  %10 = load i32, ptr @a, align 4, !tbaa !5
  %11 = srem i32 %9, %10
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %8
  %14 = call i32 @puts(ptr noundef @.str.1)
  br label %5, !llvm.loop !9

15:                                               ; preds = %8
  %16 = load i32, ptr @a, align 4, !tbaa !5
  %17 = load i32, ptr @b, align 4, !tbaa !5
  %18 = sdiv i32 %17, %16
  store i32 %18, ptr @b, align 4, !tbaa !5
  %19 = load i64, ptr %2, align 8, !tbaa !11
  %20 = srem i64 %19, 1000000008
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr @n, align 4, !tbaa !5
  store i32 1, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  br label %22

22:                                               ; preds = %71, %15
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @b, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sdiv i32 %24, %25
  %27 = icmp sle i32 %23, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %74

29:                                               ; preds = %22
  %30 = load i32, ptr @b, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = srem i32 %30, %31
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %70

34:                                               ; preds = %29
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %41, %34
  %36 = load i32, ptr @b, align 4, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = srem i32 %36, %37
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %35
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr @b, align 4, !tbaa !5
  %44 = sdiv i32 %43, %42
  store i32 %44, ptr @b, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %4, align 4, !tbaa !5
  br label %35, !llvm.loop !13

47:                                               ; preds = %35
  %48 = load i32, ptr @ans, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = call noundef i32 @_Z7mod_powii(i32 noundef %51, i32 noundef %52)
  %54 = sext i32 %53 to i64
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %57 = call noundef i32 @_Z7mod_powii(i32 noundef %55, i32 noundef %56)
  %58 = sext i32 %57 to i64
  %59 = mul nsw i64 2, %58
  %60 = sub nsw i64 %54, %59
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sub nsw i32 %61, 1
  %63 = load i32, ptr @n, align 4, !tbaa !5
  %64 = call noundef i32 @_Z7mod_powii(i32 noundef %62, i32 noundef %63)
  %65 = sext i32 %64 to i64
  %66 = add nsw i64 %60, %65
  %67 = mul nsw i64 %49, %66
  %68 = srem i64 %67, 1000000009
  %69 = trunc i64 %68 to i32
  store i32 %69, ptr @ans, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %47, %29
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !14

74:                                               ; preds = %28
  %75 = load i32, ptr @b, align 4, !tbaa !5
  %76 = icmp sgt i32 %75, 1
  br i1 %76, label %77, label %87

77:                                               ; preds = %74
  %78 = load i32, ptr @ans, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = load i32, ptr @n, align 4, !tbaa !5
  %81 = call noundef i32 @_Z7mod_powii(i32 noundef 2, i32 noundef %80)
  %82 = sub nsw i32 %81, 2
  %83 = sext i32 %82 to i64
  %84 = mul nsw i64 %79, %83
  %85 = srem i64 %84, 1000000009
  %86 = trunc i64 %85 to i32
  store i32 %86, ptr @ans, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %77, %74
  %88 = load i32, ptr @ans, align 4, !tbaa !5
  %89 = icmp slt i32 %88, 0
  br i1 %89, label %90, label %93

90:                                               ; preds = %87
  %91 = load i32, ptr @ans, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1000000009
  store i32 %92, ptr @ans, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %90, %87
  %94 = load i32, ptr @ans, align 4, !tbaa !5
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %94)
  br label %5, !llvm.loop !9

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

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

declare i32 @puts(ptr noundef) #3

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

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 = { 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 #3 = { "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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 local_unnamed_addr global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) local_unnamed_addr #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %3 = icmp eq i32 %2, 3
  br i1 %3, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %0, %.backedge
  %4 = load i32, ptr @b, align 4, !tbaa !5
  %5 = load i32, ptr @a, align 4, !tbaa !5
  %6 = srem i32 %4, %5
  %7 = sdiv i32 %4, %5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %12, label %8

8:                                                ; preds = %.lr.ph23
  %9 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.backedge

.backedge:                                        ; preds = %8, %63
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %11 = icmp eq i32 %10, 3
  br i1 %11, label %.lr.ph23, label %._crit_edge24, !llvm.loop !9

12:                                               ; preds = %.lr.ph23
  store i32 %7, ptr @b, align 4, !tbaa !5
  %13 = load i64, ptr %1, align 8, !tbaa !11
  %14 = srem i64 %13, 1000000008
  %15 = trunc nsw i64 %14 to i32
  store i32 %15, ptr @n, align 4, !tbaa !5
  store i32 1, ptr @ans, align 4, !tbaa !5
  %.not1215 = icmp slt i32 %7, 4
  br i1 %.not1215, label %._crit_edge20, label %.lr.ph19

._crit_edge20:                                    ; preds = %45, %12
  %16 = phi i32 [ 1, %12 ], [ %47, %45 ]
  %.lcssa = phi i32 [ %7, %12 ], [ %46, %45 ]
  %17 = icmp sgt i32 %.lcssa, 1
  br i1 %17, label %50, label %thread-pre-split

.lr.ph19:                                         ; preds = %12, %45
  %18 = phi i32 [ %46, %45 ], [ %7, %12 ]
  %19 = phi i32 [ %47, %45 ], [ 1, %12 ]
  %.01016 = phi i32 [ %48, %45 ], [ 2, %12 ]
  %20 = srem i32 %18, %.01016
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %.lr.ph, label %45

.lr.ph:                                           ; preds = %.lr.ph19, %.lr.ph
  %.013 = phi i32 [ %24, %.lr.ph ], [ 0, %.lr.ph19 ]
  %22 = phi i32 [ %23, %.lr.ph ], [ %18, %.lr.ph19 ]
  %23 = sdiv i32 %22, %.01016
  %24 = add nuw nsw i32 %.013, 1
  %25 = srem i32 %23, %.01016
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %.lr.ph, label %27, !llvm.loop !13

27:                                               ; preds = %.lr.ph
  store i32 %23, ptr @b, align 4, !tbaa !5
  %28 = sext i32 %19 to i64
  %29 = add nuw nsw i32 %.013, 2
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = call noundef i32 @_Z7mod_powii(i32 noundef %29, i32 noundef %30)
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = call noundef i32 @_Z7mod_powii(i32 noundef %24, i32 noundef %33)
  %35 = sext i32 %34 to i64
  %36 = shl nsw i64 %35, 1
  %37 = sub nsw i64 %32, %36
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = call noundef i32 @_Z7mod_powii(i32 noundef %.013, i32 noundef %38)
  %40 = sext i32 %39 to i64
  %41 = add nsw i64 %37, %40
  %42 = mul nsw i64 %41, %28
  %43 = srem i64 %42, 1000000009
  %44 = trunc nsw i64 %43 to i32
  store i32 %44, ptr @ans, align 4, !tbaa !5
  %.pre = load i32, ptr @b, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %.lr.ph19, %27
  %46 = phi i32 [ %18, %.lr.ph19 ], [ %.pre, %27 ]
  %47 = phi i32 [ %19, %.lr.ph19 ], [ %44, %27 ]
  %48 = add nuw nsw i32 %.01016, 1
  %49 = sdiv i32 %46, %48
  %.not12.not = icmp slt i32 %.01016, %49
  br i1 %.not12.not, label %.lr.ph19, label %._crit_edge20, !llvm.loop !14

50:                                               ; preds = %._crit_edge20
  %51 = sext i32 %16 to i64
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = call noundef i32 @_Z7mod_powii(i32 noundef 2, i32 noundef %52)
  %54 = add nsw i32 %53, -2
  %55 = sext i32 %54 to i64
  %56 = mul nsw i64 %55, %51
  %57 = srem i64 %56, 1000000009
  %58 = trunc nsw i64 %57 to i32
  store i32 %58, ptr @ans, align 4, !tbaa !5
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %._crit_edge20, %50
  %59 = phi i32 [ %58, %50 ], [ %16, %._crit_edge20 ]
  %60 = icmp slt i32 %59, 0
  br i1 %60, label %61, label %63

61:                                               ; preds = %thread-pre-split
  %62 = add nsw i32 %59, 1000000009
  store i32 %62, ptr @ans, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %61, %thread-pre-split
  %64 = phi i32 [ %62, %61 ], [ %59, %thread-pre-split ]
  %65 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %64)
  br label %.backedge

._crit_edge24:                                    ; preds = %.backedge, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0
}

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

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

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

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 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 #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 = !{!"int", !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 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass