; LLVM IR from tangjz/acm-icpc :: hdu/4754.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"

%struct.Edge = type { i32, i32, double }

@lnk = external dso_local global [303 x i32], align 16
@e = external dso_local global [181203 x %struct.Edge], align 16
@n = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@vis = external dso_local global [303 x i8], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnd(double noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3pfsi(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [303 x i8], ptr @vis, i64 0, i64 %5
  store i8 1, ptr %6, align 1, !tbaa !9
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  %10 = zext i1 %9 to i32
  %11 = load i32, ptr @cnt, align 4, !tbaa !5
  %12 = sub nsw i32 %11, %10
  store i32 %12, ptr @cnt, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [303 x i32], ptr @lnk, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %16, ptr %3, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %47, %1
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = icmp ne i32 %18, -1
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %53

21:                                               ; preds = %17
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.Edge, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [303 x i8], ptr @vis, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9, !range !14, !noundef !15
  %30 = trunc i8 %29 to i1
  br i1 %30, label %46, label %31

31:                                               ; preds = %21
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = xor i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Edge, ptr %35, i32 0, i32 2
  %37 = load double, ptr %36, align 8, !tbaa !16
  %38 = call noundef i32 @_Z3sgnd(double noundef %37)
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %31
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Edge, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !11
  call void @_Z3pfsi(i32 noundef %45)
  br label %46

46:                                               ; preds = %40, %31, %21
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.Edge, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 16, !tbaa !17
  store i32 %52, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !18

53:                                               ; preds = %20
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"bool", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !13, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!12, !13, i64 8}
!17 = !{!12, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.Edge = type { i32, i32, double }

@lnk = external dso_local local_unnamed_addr global [303 x i32], align 16
@e = external dso_local local_unnamed_addr global [181203 x %struct.Edge], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [303 x i8], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3pfsi(i32 noundef %0) local_unnamed_addr #1 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [303 x i8], ptr @vis, i64 0, i64 %2
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %5 = icmp sgt i32 %4, %0
  %.neg = sext i1 %5 to i32
  %6 = load i32, ptr @cnt, align 4, !tbaa !9
  %7 = add i32 %6, %.neg
  store i32 %7, ptr @cnt, align 4, !tbaa !9
  %8 = getelementptr inbounds [303 x i32], ptr @lnk, i64 0, i64 %2
  %.08 = load i32, ptr %8, align 4, !tbaa !9
  %.not9 = icmp eq i32 %.08, -1
  br i1 %.not9, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %26, %1
  ret void

.lr.ph:                                           ; preds = %1, %26
  %.010 = phi i32 [ %.0, %26 ], [ %.08, %1 ]
  %9 = sext i32 %.010 to i64
  %10 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [303 x i8], ptr @vis, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5, !range !14, !noundef !15
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %26, label %17

17:                                               ; preds = %.lr.ph
  %18 = xor i32 %.010, 1
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %19, i32 2
  %21 = load double, ptr %20, align 8, !tbaa !16
  %22 = tail call noundef i32 @_Z3sgnd(double noundef %21)
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %17
  %25 = load i32, ptr %11, align 4, !tbaa !11
  tail call void @_Z3pfsi(i32 noundef %25)
  br label %26

26:                                               ; preds = %.lr.ph, %17, %24
  %.0 = load i32, ptr %10, align 16, !tbaa !9
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17
}

attributes #0 = { 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" }
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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS4Edge", !10, i64 0, !10, i64 4, !13, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!12, !13, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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