; LLVM IR from tangjz/acm-icpc :: 51nod/1150.ll (Z7solve_1iii)

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

@Log10 = external dso_local global [61 x i32], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4findiii(i32 noundef, 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 uwtable
declare dso_local void @_Z7solve_2iiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7solve_1iii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = 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
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 3
  br i1 %9, label %14, label %10

10:                                               ; preds = %3
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp sge i32 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %10, %3
  br label %77

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = call noundef i32 @_Z4findiii(i32 noundef %16, i32 noundef %17, i32 noundef %18)
  store i32 %19, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %67

23:                                               ; preds = %15
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %27, label %67

27:                                               ; preds = %23
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %33, label %53

33:                                               ; preds = %27
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sub nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %41, 1
  %43 = mul nsw i64 %37, %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %43, %49
  %51 = load i64, ptr @ans, align 8, !tbaa !9
  %52 = add nsw i64 %51, %50
  store i64 %52, ptr @ans, align 8, !tbaa !9
  br label %66

53:                                               ; preds = %27
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sub nsw i32 %54, 1
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sub nsw i32 0, %59
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sub nsw i32 %62, 1
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z7solve_2iiiiii(i32 noundef %55, i32 noundef %60, i32 noundef %61, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  br label %66

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

67:                                               ; preds = %66, %23, %15
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = sub nsw i32 %71, 1
  call void @_Z7solve_1iii(i32 noundef %69, i32 noundef %70, i32 noundef %72)
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sub nsw i32 %73, 1
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z7solve_1iii(i32 noundef %74, i32 noundef %75, i32 noundef %76)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %77

77:                                               ; preds = %67, %14
  ret void
}

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 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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

@Log10 = external dso_local local_unnamed_addr global [61 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7solve_2iiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7solve_1iii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp sgt i32 %0, 2
  %.not36 = icmp slt i32 %1, %2
  %or.cond37 = and i1 %4, %.not36
  br i1 %or.cond37, label %.lr.ph.preheader, label %tailrecurse._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %5 = zext nneg i32 %0 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse
  %indvars.iv = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %.tr3439 = phi i32 [ %1, %.lr.ph.preheader ], [ %7, %tailrecurse ]
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  %7 = tail call noundef i32 @_Z4findiii(i32 noundef %.tr3439, i32 noundef %2, i32 noundef %6)
  %8 = icmp sle i32 %7, %.tr3439
  %.not32 = icmp sgt i32 %7, %2
  %or.cond33 = or i1 %8, %.not32
  br i1 %or.cond33, label %tailrecurse, label %9

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, -1
  br i1 %12, label %13, label %25

13:                                               ; preds = %9
  %14 = sub nsw i32 %7, %.tr3439
  %15 = sext i32 %14 to i64
  %16 = sub nsw i32 %2, %7
  %17 = sext i32 %16 to i64
  %18 = add nsw i64 %17, 1
  %19 = mul nsw i64 %18, %15
  %20 = add nsw i32 %11, -1
  %21 = sext i32 %20 to i64
  %22 = mul nsw i64 %19, %21
  %23 = load i64, ptr @ans, align 8, !tbaa !9
  %24 = add nsw i64 %23, %22
  store i64 %24, ptr @ans, align 8, !tbaa !9
  br label %tailrecurse

25:                                               ; preds = %9
  %26 = sub nsw i32 0, %11
  %27 = add nsw i32 %7, -1
  %28 = trunc i64 %indvars.iv to i32
  %29 = add i32 %28, -1
  tail call void @_Z7solve_2iiiiii(i32 noundef %29, i32 noundef %26, i32 noundef %.tr3439, i32 noundef %27, i32 noundef %7, i32 noundef %2)
  br label %tailrecurse

tailrecurse:                                      ; preds = %13, %25, %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %30 = add nsw i32 %7, -1
  %31 = trunc nuw nsw i64 %indvars.iv.next to i32
  tail call void @_Z7solve_1iii(i32 noundef %31, i32 noundef %.tr3439, i32 noundef %30)
  %32 = icmp sgt i64 %indvars.iv, 3
  %.not = icmp slt i32 %7, %2
  %or.cond = and i1 %32, %.not
  br i1 %or.cond, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %3
  ret void
}

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 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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