; LLVM IR from tangjz/acm-icpc :: projecteuler/548.ll (Z3pfsiix)

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

%struct.FracExp = type { i32, [15 x i32] }

@cur = external dso_local global %struct.FracExp, align 4
@nxt = external dso_local global %struct.FracExp, align 4
@f = external dso_local global [172513 x i64], align 16
@ans = external dso_local global i64, align 8
@_ZL2pr = external hidden constant [15 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsx(i64 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
define dso_local void @_Z3pfsiix(i32 noundef %0, i32 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = call noundef i32 @_Z3dfsx(i64 noundef %10)
  store i32 %11, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [172513 x i64], ptr @f, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = icmp sgt i64 %15, 10000000000000000
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i32 1, ptr %8, align 4
  br label %78

18:                                               ; preds = %3
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [172513 x i64], ptr @f, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = icmp sge i64 %22, %23
  br i1 %24, label %25, label %41

25:                                               ; preds = %18
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [172513 x i64], ptr @f, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  call void @_ZN7FracExp5parseEx(ptr noundef nonnull align 4 dereferenceable(64) @nxt, i64 noundef %29)
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = call noundef i64 @_ZNK7FracExp5valueEv(ptr noundef nonnull align 4 dereferenceable(64) @nxt)
  %32 = icmp eq i64 %30, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %25
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [172513 x i64], ptr @f, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = load i64, ptr @ans, align 8, !tbaa !9
  %39 = add nsw i64 %38, %37
  store i64 %39, ptr @ans, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %33, %25
  br label %41

41:                                               ; preds = %40, %18
  %42 = load i32, ptr @cur, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr @cur, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %69, %41
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = icmp sle i32 %45, %46
  br i1 %47, label %48, label %57

48:                                               ; preds = %44
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [15 x i32], ptr @_ZL2pr, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = mul nsw i64 %54, %53
  store i64 %55, ptr %6, align 8, !tbaa !9
  %56 = icmp sle i64 %55, 10000000000000000
  br label %57

57:                                               ; preds = %48, %44
  %58 = phi i1 [ false, %44 ], [ %56, %48 ]
  br i1 %58, label %60, label %59

59:                                               ; preds = %57
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %72

60:                                               ; preds = %57
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [15 x i32], ptr getelementptr inbounds (%struct.FracExp, ptr @cur, i32 0, i32 1), i64 0, i64 %63
  store i32 %61, ptr %64, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = load i64, ptr %6, align 8, !tbaa !9
  call void @_Z3pfsiix(i32 noundef %66, i32 noundef %67, i64 noundef %68)
  br label %69

69:                                               ; preds = %60
  %70 = load i32, ptr %9, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %9, align 4, !tbaa !5
  br label %44, !llvm.loop !13

72:                                               ; preds = %59
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [15 x i32], ptr getelementptr inbounds (%struct.FracExp, ptr @cur, i32 0, i32 1), i64 0, i64 %74
  store i32 0, ptr %75, align 4, !tbaa !5
  %76 = load i32, ptr @cur, align 4, !tbaa !11
  %77 = add nsw i32 %76, -1
  store i32 %77, ptr @cur, align 4, !tbaa !11
  store i32 0, ptr %8, align 4
  br label %78

78:                                               ; preds = %72, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %79 = load i32, ptr %8, align 4
  switch i32 %79, label %81 [
    i32 0, label %80
    i32 1, label %80
  ]

80:                                               ; preds = %78, %78
  ret void

81:                                               ; preds = %78
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7FracExp5parseEx(ptr noundef nonnull align 4 dereferenceable(64), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7FracExp5valueEv(ptr noundef nonnull align 4 dereferenceable(64)) #2 align 2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS7FracExp", !6, i64 0, !7, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%struct.FracExp = type { i32, [15 x i32] }

@cur = external dso_local local_unnamed_addr global %struct.FracExp, align 4
@nxt = external dso_local global %struct.FracExp, align 4
@f = external dso_local local_unnamed_addr global [172513 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@_ZL2pr = external hidden local_unnamed_addr constant [15 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3pfsiix(i32 noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef i32 @_Z3dfsx(i64 noundef %2)
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [172513 x i64], ptr @f, i64 0, i64 %5
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 10000000000000000
  br i1 %8, label %33, label %9

9:                                                ; preds = %3
  %.not = icmp slt i64 %7, %2
  br i1 %.not, label %17, label %10

10:                                               ; preds = %9
  tail call void @_ZN7FracExp5parseEx(ptr noundef nonnull align 4 dereferenceable(64) @nxt, i64 noundef %7)
  %11 = tail call noundef i64 @_ZNK7FracExp5valueEv(ptr noundef nonnull align 4 dereferenceable(64) @nxt)
  %12 = icmp eq i64 %11, %2
  br i1 %12, label %13, label %17

13:                                               ; preds = %10
  %14 = load i64, ptr %6, align 8, !tbaa !5
  %15 = load i64, ptr @ans, align 8, !tbaa !5
  %16 = add nsw i64 %15, %14
  store i64 %16, ptr @ans, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %10, %13, %9
  %18 = load i32, ptr @cur, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @cur, align 4, !tbaa !9
  %.not2223 = icmp slt i32 %1, 1
  %.pre = sext i32 %0 to i64
  br i1 %.not2223, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %17
  %20 = getelementptr inbounds [15 x i32], ptr @_ZL2pr, i64 0, i64 %.pre
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [15 x i32], ptr getelementptr inbounds (i8, ptr @cur, i64 4), i64 0, i64 %.pre
  %24 = add nsw i32 %0, 1
  br label %25

25:                                               ; preds = %.lr.ph, %31
  %.025 = phi i32 [ 1, %.lr.ph ], [ %32, %31 ]
  %.01824 = phi i64 [ %2, %.lr.ph ], [ %26, %31 ]
  %26 = mul nsw i64 %.01824, %22
  %27 = icmp slt i64 %26, 10000000000000001
  br i1 %27, label %31, label %.critedge

.critedge:                                        ; preds = %25, %31, %17
  %28 = getelementptr inbounds [15 x i32], ptr getelementptr inbounds (i8, ptr @cur, i64 4), i64 0, i64 %.pre
  store i32 0, ptr %28, align 4, !tbaa !12
  %29 = load i32, ptr @cur, align 4, !tbaa !9
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @cur, align 4, !tbaa !9
  br label %33

31:                                               ; preds = %25
  store i32 %.025, ptr %23, align 4, !tbaa !12
  tail call void @_Z3pfsiix(i32 noundef %24, i32 noundef %.025, i64 noundef %26)
  %32 = add nuw i32 %.025, 1
  %exitcond.not = icmp eq i32 %.025, %1
  br i1 %exitcond.not, label %.critedge, label %25, !llvm.loop !13

33:                                               ; preds = %3, %.critedge
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7FracExp5parseEx(ptr noundef nonnull align 4 dereferenceable(64), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7FracExp5valueEv(ptr noundef nonnull align 4 dereferenceable(64)) local_unnamed_addr #1 align 2

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

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS7FracExp", !11, i64 0, !7, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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