; LLVM IR from VastoLorde95/Competitive-Programming :: Codejam/2016/Round 2/Problem A/A.ll (Z3dfsiii)

; 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 [32768 x i32], align 16
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [106 x i8], align 1
@__PRETTY_FUNCTION__._Z3dfsiii = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  %10 = icmp eq i32 %7, %9
  br i1 %10, label %11, label %27

11:                                               ; preds = %3
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = shl i32 1, %13
  %15 = icmp sge i32 %12, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %11
  br label %19

17:                                               ; preds = %11
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 47, ptr noundef @__PRETTY_FUNCTION__._Z3dfsiii) #2
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = shl i32 1, %22
  %24 = sub nsw i32 %21, %23
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [32768 x i32], ptr @a, i64 0, i64 %25
  store i32 %20, ptr %26, align 4, !tbaa !5
  br label %68

27:                                               ; preds = %3
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %40

30:                                               ; preds = %27
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = mul nsw i32 2, %31
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  call void @_Z3dfsiii(i32 noundef 1, i32 noundef %32, i32 noundef %34)
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = mul nsw i32 2, %35
  %37 = add nsw i32 %36, 1
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  call void @_Z3dfsiii(i32 noundef 2, i32 noundef %37, i32 noundef %39)
  br label %68

40:                                               ; preds = %27
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = icmp eq i32 %41, 2
  br i1 %42, label %43, label %53

43:                                               ; preds = %40
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = mul nsw i32 2, %44
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  call void @_Z3dfsiii(i32 noundef 2, i32 noundef %45, i32 noundef %47)
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = mul nsw i32 2, %48
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  call void @_Z3dfsiii(i32 noundef 3, i32 noundef %50, i32 noundef %52)
  br label %67

53:                                               ; preds = %40
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 3
  br i1 %55, label %56, label %66

56:                                               ; preds = %53
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = mul nsw i32 2, %57
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  call void @_Z3dfsiii(i32 noundef 3, i32 noundef %59, i32 noundef %61)
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = mul nsw i32 2, %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  call void @_Z3dfsiii(i32 noundef 1, i32 noundef %63, i32 noundef %65)
  br label %66

66:                                               ; preds = %56, %53
  br label %67

67:                                               ; preds = %66, %43
  br label %68

68:                                               ; preds = %67, %30, %19
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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


; 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 local_unnamed_addr global [32768 x i32], align 16
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [106 x i8], align 1
@__PRETTY_FUNCTION__._Z3dfsiii = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  %6 = icmp eq i32 %5, %2
  br i1 %6, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse.backedge, %3
  %.tr.lcssa = phi i32 [ %0, %3 ], [ %.tr.be, %tailrecurse.backedge ]
  %.tr22.lcssa = phi i32 [ %1, %3 ], [ %.tr22.be, %tailrecurse.backedge ]
  %.lcssa = phi i32 [ %4, %3 ], [ %17, %tailrecurse.backedge ]
  %7 = shl nuw i32 1, %.lcssa
  %.not = icmp sgt i32 %7, %.tr22.lcssa
  br i1 %.not, label %8, label %9

8:                                                ; preds = %tailrecurse._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 47, ptr noundef nonnull @__PRETTY_FUNCTION__._Z3dfsiii) #2
  unreachable

9:                                                ; preds = %tailrecurse._crit_edge
  %10 = sub nsw i32 %.tr22.lcssa, %7
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [32768 x i32], ptr @a, i64 0, i64 %11
  store i32 %.tr.lcssa, ptr %12, align 4, !tbaa !5
  br label %.loopexit

.lr.ph:                                           ; preds = %3, %tailrecurse.backedge
  %.tr2329 = phi i32 [ %.tr23.be, %tailrecurse.backedge ], [ %2, %3 ]
  %.tr2228 = phi i32 [ %.tr22.be, %tailrecurse.backedge ], [ %1, %3 ]
  %.tr27 = phi i32 [ %.tr.be, %tailrecurse.backedge ], [ %0, %3 ]
  switch i32 %.tr27, label %.loopexit [
    i32 1, label %13
    i32 2, label %20
    i32 3, label %24
  ]

13:                                               ; preds = %.lr.ph
  %14 = shl nsw i32 %.tr2228, 1
  %15 = add nsw i32 %.tr2329, 1
  tail call void @_Z3dfsiii(i32 noundef 1, i32 noundef %14, i32 noundef %15)
  %16 = or disjoint i32 %14, 1
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %13, %20, %24
  %.tr.be = phi i32 [ 2, %13 ], [ 3, %20 ], [ 1, %24 ]
  %.tr22.be = phi i32 [ %16, %13 ], [ %23, %20 ], [ %25, %24 ]
  %.tr23.be = phi i32 [ %15, %13 ], [ %22, %20 ], [ %27, %24 ]
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = icmp eq i32 %18, %.tr23.be
  br i1 %19, label %tailrecurse._crit_edge, label %.lr.ph

20:                                               ; preds = %.lr.ph
  %21 = shl nsw i32 %.tr2228, 1
  %22 = add nsw i32 %.tr2329, 1
  tail call void @_Z3dfsiii(i32 noundef 2, i32 noundef %21, i32 noundef %22)
  %23 = or disjoint i32 %21, 1
  br label %tailrecurse.backedge

24:                                               ; preds = %.lr.ph
  %25 = shl nsw i32 %.tr2228, 1
  %26 = or disjoint i32 %25, 1
  %27 = add nsw i32 %.tr2329, 1
  tail call void @_Z3dfsiii(i32 noundef 3, i32 noundef %26, i32 noundef %27)
  br label %tailrecurse.backedge

.loopexit:                                        ; preds = %.lr.ph, %9
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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 = { noreturn 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 = { noreturn 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"}


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