; LLVM IR from kazunetakahashi/atcoder :: 201411_201509/0329_UTPC2014/B.ll (Z3gcdii)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3gcdii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sub nsw i32 0, %9
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = call noundef i32 @_Z3gcdii(i32 noundef %10, i32 noundef %11)
  store i32 %12, ptr %3, align 4
  br label %40

13:                                               ; preds = %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sub nsw i32 0, %18
  %20 = call noundef i32 @_Z3gcdii(i32 noundef %17, i32 noundef %19)
  store i32 %20, ptr %3, align 4
  br label %40

21:                                               ; preds = %13
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %29

25:                                               ; preds = %21
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = call noundef i32 @_Z3gcdii(i32 noundef %26, i32 noundef %27)
  store i32 %28, ptr %3, align 4
  br label %40

29:                                               ; preds = %21
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %33, ptr %3, align 4
  br label %40

34:                                               ; preds = %29
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = srem i32 %36, %37
  %39 = call noundef i32 @_Z3gcdii(i32 noundef %35, i32 noundef %38)
  store i32 %39, ptr %3, align 4
  br label %40

40:                                               ; preds = %34, %32, %25, %16, %8
  %41 = load i32, ptr %3, align 4
  ret i32 %41
}

attributes #0 = { 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" }

!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"}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef range(i32 0, -2147483648) i32 @_Z3gcdii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse.outer.outer

tailrecurse.outer.outer:                          ; preds = %tailrecurse.outer.outer.backedge, %2
  %.tr.ph.ph = phi i32 [ %0, %2 ], [ %.tr1921, %tailrecurse.outer.outer.backedge ]
  %.tr19.ph.ph = phi i32 [ %1, %2 ], [ %.tr19.ph.ph.be, %tailrecurse.outer.outer.backedge ]
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %tailrecurse.outer.outer, %4
  %.tr.ph = phi i32 [ %5, %4 ], [ %.tr.ph.ph, %tailrecurse.outer.outer ]
  %3 = icmp slt i32 %.tr.ph, 0
  br i1 %3, label %4, label %tailrecurse

4:                                                ; preds = %tailrecurse.outer
  %5 = sub nsw i32 0, %.tr.ph
  br label %tailrecurse.outer

tailrecurse:                                      ; preds = %tailrecurse.outer, %tailrecurse
  %.tr1921 = phi i32 [ %7, %tailrecurse ], [ %.tr19.ph.ph, %tailrecurse.outer ]
  %6 = icmp slt i32 %.tr1921, 0
  %7 = sub nsw i32 0, %.tr1921
  br i1 %6, label %tailrecurse, label %.split

.split:                                           ; preds = %tailrecurse
  %8 = icmp ult i32 %.tr.ph, %.tr1921
  br i1 %8, label %tailrecurse.outer.outer.backedge, label %9

tailrecurse.outer.outer.backedge:                 ; preds = %.split, %11
  %.tr19.ph.ph.be = phi i32 [ %12, %11 ], [ %.tr.ph, %.split ]
  br label %tailrecurse.outer.outer

9:                                                ; preds = %.split
  %10 = icmp eq i32 %.tr1921, 0
  br i1 %10, label %13, label %11

11:                                               ; preds = %9
  %12 = urem i32 %.tr.ph, %.tr1921
  br label %tailrecurse.outer.outer.backedge

13:                                               ; preds = %9
  ret i32 %.tr.ph
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass