; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-03-20/J - Draw Straight Walk - tjz.ll (Z3pfsi)

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

@pre = external dso_local global [100001 x i32], align 16
@dep = external dso_local global [100001 x i32], align 16
@len = external dso_local global [100001 x i32], align 16
@dep_len = external dso_local global [100001 x i32], align 16
@delta = external dso_local global [100001 x i32], align 16
@e = external dso_local global [100001 x [2 x i32]], align 16
@last_len = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3pfsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [100001 x [2 x i32]], ptr @e, i64 0, i64 %4
  %6 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 0
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp ne i32 %7, -1
  br i1 %8, label %9, label %15

9:                                                ; preds = %1
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100001 x [2 x i32]], ptr @e, i64 0, i64 %11
  %13 = getelementptr inbounds [2 x i32], ptr %12, i64 0, i64 0
  %14 = load i32, ptr %13, align 8, !tbaa !5
  call void @_Z3pfsi(i32 noundef %14)
  br label %15

15:                                               ; preds = %9, %1
  %16 = load i32, ptr @last_len, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100001 x i32], ptr @dep, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x i32], ptr @dep_len, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sub nsw i32 %16, %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100001 x i32], ptr @delta, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr @last_len, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %42

34:                                               ; preds = %15
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = call noundef double @_ZSt5log10IiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %38)
  %40 = fptosi double %39 to i32
  %41 = add nsw i32 %40, 1
  br label %43

42:                                               ; preds = %15
  br label %43

43:                                               ; preds = %42, %34
  %44 = phi i32 [ %41, %34 ], [ 1, %42 ]
  %45 = add nsw i32 %28, %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100001 x i32], ptr @len, i64 0, i64 %47
  store i32 %45, ptr %48, align 4, !tbaa !5
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100001 x i32], ptr @len, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100001 x i32], ptr @dep, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100001 x i32], ptr @dep_len, i64 0, i64 %57
  store i32 %52, ptr %58, align 4, !tbaa !5
  store i32 %52, ptr @last_len, align 4, !tbaa !5
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100001 x [2 x i32]], ptr @e, i64 0, i64 %60
  %62 = getelementptr inbounds [2 x i32], ptr %61, i64 0, i64 1
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = icmp ne i32 %63, -1
  br i1 %64, label %65, label %71

65:                                               ; preds = %43
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x [2 x i32]], ptr @e, i64 0, i64 %67
  %69 = getelementptr inbounds [2 x i32], ptr %68, i64 0, i64 1
  %70 = load i32, ptr %69, align 4, !tbaa !5
  call void @_Z3pfsi(i32 noundef %70)
  br label %71

71:                                               ; preds = %65, %43
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5log10IiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 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 = { inlinehint 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 = !{!"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"

@pre = external dso_local local_unnamed_addr global [100001 x i32], align 16
@dep = external dso_local local_unnamed_addr global [100001 x i32], align 16
@len = external dso_local local_unnamed_addr global [100001 x i32], align 16
@dep_len = external dso_local local_unnamed_addr global [100001 x i32], align 16
@delta = external dso_local local_unnamed_addr global [100001 x i32], align 16
@e = external dso_local local_unnamed_addr global [100001 x [2 x i32]], align 16
@last_len = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3pfsi(i32 noundef %0) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %21, %1
  %.tr = phi i32 [ %0, %1 ], [ %27, %21 ]
  %2 = sext i32 %.tr to i64
  %3 = getelementptr inbounds [100001 x [2 x i32]], ptr @e, i64 0, i64 %2
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, -1
  br i1 %.not, label %6, label %5

5:                                                ; preds = %tailrecurse
  tail call void @_Z3pfsi(i32 noundef %4)
  br label %6

6:                                                ; preds = %5, %tailrecurse
  %7 = load i32, ptr @last_len, align 4, !tbaa !5
  %8 = getelementptr inbounds [100001 x i32], ptr @dep, i64 0, i64 %2
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100001 x i32], ptr @dep_len, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sub nsw i32 %7, %12
  %14 = getelementptr inbounds [100001 x i32], ptr @delta, i64 0, i64 %2
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [100001 x i32], ptr @pre, i64 0, i64 %2
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not13 = icmp eq i32 %16, 0
  br i1 %.not13, label %21, label %17

17:                                               ; preds = %6
  %18 = tail call noundef double @_ZSt5log10IiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %16)
  %19 = fptosi double %18 to i32
  %20 = add nsw i32 %19, 1
  %.pre = load i32, ptr %8, align 4, !tbaa !5
  %.pre15 = sext i32 %.pre to i64
  br label %21

21:                                               ; preds = %6, %17
  %.pre-phi = phi i64 [ %10, %6 ], [ %.pre15, %17 ]
  %22 = phi i32 [ 1, %6 ], [ %20, %17 ]
  %23 = add nsw i32 %22, %7
  %24 = getelementptr inbounds [100001 x i32], ptr @len, i64 0, i64 %2
  store i32 %23, ptr %24, align 4, !tbaa !5
  %25 = getelementptr inbounds [100001 x i32], ptr @dep_len, i64 0, i64 %.pre-phi
  store i32 %23, ptr %25, align 4, !tbaa !5
  store i32 %23, ptr @last_len, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %3, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not14 = icmp eq i32 %27, -1
  br i1 %.not14, label %28, label %tailrecurse

28:                                               ; preds = %21
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5log10IiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 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 = { inlinehint 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass