; LLVM IR from gokcehan/pns :: generators/gridgen-patched (gridgen)

; 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.stat_para = type { i64, [5 x float] }
%struct.arcs = type { i64, i64, i64, i64 }

@arc_list = external dso_local global ptr, align 8
@arc_costs = external dso_local global %struct.stat_para, align 8
@n_source = external dso_local global i64, align 8
@n_sink = external dso_local global i64, align 8
@n_grid_arc = external dso_local global i64, align 8
@n_arc = external dso_local global i64, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local void @assign_costs() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %6 = load ptr, ptr @arc_list, align 8, !tbaa !5
  store ptr %6, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  %7 = load i64, ptr @arc_costs, align 8, !tbaa !11
  switch i64 %7, label %10 [
    i64 1, label %8
    i64 2, label %9
  ]

8:                                                ; preds = %0
  store ptr @uniform, ptr %2, align 8, !tbaa !5
  br label %10

9:                                                ; preds = %0
  store ptr @exponential, ptr %2, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %9, %8, %0
  %11 = load i64, ptr @n_source, align 8, !tbaa !9
  %12 = load i64, ptr @n_sink, align 8, !tbaa !9
  %13 = add nsw i64 %11, %12
  store i64 %13, ptr %3, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %33, %10
  %15 = load i64, ptr %3, align 8, !tbaa !9
  %16 = load i64, ptr @n_grid_arc, align 8, !tbaa !9
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %18, label %38

18:                                               ; preds = %14
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = call i64 (ptr, ...) %19(ptr noundef getelementptr inbounds (%struct.stat_para, ptr @arc_costs, i32 0, i32 1))
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.arcs, ptr %21, i32 0, i32 2
  store i64 %20, ptr %22, align 8, !tbaa !13
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.arcs, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !13
  %27 = icmp slt i64 %23, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %18
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.arcs, ptr %29, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !13
  store i64 %31, ptr %5, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %28, %18
  br label %33

33:                                               ; preds = %32
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %3, align 8, !tbaa !9
  %36 = load ptr, ptr %1, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.arcs, ptr %36, i32 1
  store ptr %37, ptr %1, align 8, !tbaa !5
  br label %14, !llvm.loop !15

38:                                               ; preds = %14
  %39 = load i64, ptr %3, align 8, !tbaa !9
  %40 = load i64, ptr @n_source, align 8, !tbaa !9
  %41 = sub nsw i64 %39, %40
  %42 = load i64, ptr @n_sink, align 8, !tbaa !9
  %43 = sub nsw i64 %41, %42
  store i64 %43, ptr %3, align 8, !tbaa !9
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = mul nsw i64 %44, 2
  store i64 %45, ptr %4, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %54, %38
  %47 = load i64, ptr %3, align 8, !tbaa !9
  %48 = load i64, ptr @n_grid_arc, align 8, !tbaa !9
  %49 = icmp slt i64 %47, %48
  br i1 %49, label %50, label %59

50:                                               ; preds = %46
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = load ptr, ptr %1, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.arcs, ptr %52, i32 0, i32 2
  store i64 %51, ptr %53, align 8, !tbaa !13
  br label %54

54:                                               ; preds = %50
  %55 = load i64, ptr %3, align 8, !tbaa !9
  %56 = add nsw i64 %55, 1
  store i64 %56, ptr %3, align 8, !tbaa !9
  %57 = load ptr, ptr %1, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.arcs, ptr %57, i32 1
  store ptr %58, ptr %1, align 8, !tbaa !5
  br label %46, !llvm.loop !17

59:                                               ; preds = %46
  br label %60

60:                                               ; preds = %69, %59
  %61 = load i64, ptr %3, align 8, !tbaa !9
  %62 = load i64, ptr @n_arc, align 8, !tbaa !9
  %63 = icmp slt i64 %61, %62
  br i1 %63, label %64, label %74

64:                                               ; preds = %60
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = call i64 (ptr, ...) %65(ptr noundef getelementptr inbounds (%struct.stat_para, ptr @arc_costs, i32 0, i32 1))
  %67 = load ptr, ptr %1, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.arcs, ptr %67, i32 0, i32 2
  store i64 %66, ptr %68, align 8, !tbaa !13
  br label %69

69:                                               ; preds = %64
  %70 = load i64, ptr %3, align 8, !tbaa !9
  %71 = add nsw i64 %70, 1
  store i64 %71, ptr %3, align 8, !tbaa !9
  %72 = load ptr, ptr %1, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.arcs, ptr %72, i32 1
  store ptr %73, ptr %1, align 8, !tbaa !5
  br label %60, !llvm.loop !18

74:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @exponential(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @uniform(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"stat_para", !10, i64 0, !7, i64 8}
!13 = !{!14, !10, i64 16}
!14 = !{!"arcs", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


; 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.stat_para = type { i64, [5 x float] }

@arc_list = external dso_local local_unnamed_addr global ptr, align 8
@arc_costs = external dso_local global %struct.stat_para, align 8
@n_source = external dso_local local_unnamed_addr global i64, align 8
@n_sink = external dso_local local_unnamed_addr global i64, align 8
@n_grid_arc = external dso_local local_unnamed_addr global i64, align 8
@n_arc = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local void @assign_costs() local_unnamed_addr #0 {
  %1 = load ptr, ptr @arc_list, align 8, !tbaa !5
  %2 = load i64, ptr @arc_costs, align 8, !tbaa !9
  %switch.selectcmp26 = icmp eq i64 %2, 1
  %switch.select27 = select i1 %switch.selectcmp26, ptr @uniform, ptr @exponential
  %3 = load i64, ptr @n_source, align 8, !tbaa !12
  %4 = load i64, ptr @n_sink, align 8, !tbaa !12
  %5 = add i64 %4, %3
  %6 = load i64, ptr @n_grid_arc, align 8, !tbaa !12
  %7 = icmp slt i64 %5, %6
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.032 = phi i64 [ %spec.select, %.lr.ph ], [ 0, %0 ]
  %.01931 = phi ptr [ %11, %.lr.ph ], [ %1, %0 ]
  %.02130 = phi i64 [ %10, %.lr.ph ], [ %5, %0 ]
  %8 = tail call i64 (ptr, ...) %switch.select27(ptr noundef nonnull getelementptr inbounds (i8, ptr @arc_costs, i64 8)) #2
  %9 = getelementptr inbounds i8, ptr %.01931, i64 16
  store i64 %8, ptr %9, align 8, !tbaa !13
  %spec.select = tail call i64 @llvm.smax.i64(i64 %.032, i64 %8)
  %10 = add nsw i64 %.02130, 1
  %11 = getelementptr inbounds i8, ptr %.01931, i64 32
  %12 = load i64, ptr @n_grid_arc, align 8, !tbaa !12
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr @n_source, align 8, !tbaa !12
  %.pre51 = load i64, ptr @n_sink, align 8, !tbaa !12
  %.pre52 = add i64 %.pre, %.pre51
  %14 = shl nuw nsw i64 %spec.select, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.pre-phi = phi i64 [ %.pre52, %._crit_edge.loopexit ], [ %5, %0 ]
  %.021.lcssa = phi i64 [ %10, %._crit_edge.loopexit ], [ %5, %0 ]
  %.019.lcssa = phi ptr [ %11, %._crit_edge.loopexit ], [ %1, %0 ]
  %.0.lcssa = phi i64 [ %14, %._crit_edge.loopexit ], [ 0, %0 ]
  %.lcssa = phi i64 [ %12, %._crit_edge.loopexit ], [ %6, %0 ]
  %15 = sub i64 %.021.lcssa, %.pre-phi
  %16 = icmp slt i64 %15, %.lcssa
  br i1 %16, label %.lr.ph39.preheader, label %.preheader

.lr.ph39.preheader:                               ; preds = %._crit_edge
  %17 = add i64 %.lcssa, %.pre-phi
  %18 = sub i64 %17, %.021.lcssa
  %xtraiter = and i64 %18, 7
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph39.prol.loopexit, label %.lr.ph39.prol

.lr.ph39.prol:                                    ; preds = %.lr.ph39.preheader, %.lr.ph39.prol
  %.12037.prol = phi ptr [ %21, %.lr.ph39.prol ], [ %.019.lcssa, %.lr.ph39.preheader ]
  %.12236.prol = phi i64 [ %20, %.lr.ph39.prol ], [ %15, %.lr.ph39.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph39.prol ], [ 0, %.lr.ph39.preheader ]
  %19 = getelementptr inbounds i8, ptr %.12037.prol, i64 16
  store i64 %.0.lcssa, ptr %19, align 8, !tbaa !13
  %20 = add nsw i64 %.12236.prol, 1
  %21 = getelementptr inbounds i8, ptr %.12037.prol, i64 32
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph39.prol.loopexit, label %.lr.ph39.prol, !llvm.loop !17

.lr.ph39.prol.loopexit:                           ; preds = %.lr.ph39.prol, %.lr.ph39.preheader
  %.12037.unr = phi ptr [ %.019.lcssa, %.lr.ph39.preheader ], [ %21, %.lr.ph39.prol ]
  %.12236.unr = phi i64 [ %15, %.lr.ph39.preheader ], [ %20, %.lr.ph39.prol ]
  %.lcssa61.unr = phi ptr [ poison, %.lr.ph39.preheader ], [ %21, %.lr.ph39.prol ]
  %22 = sub i64 %.021.lcssa, %17
  %23 = icmp ugt i64 %22, -8
  br i1 %23, label %.preheader, label %.lr.ph39

.preheader:                                       ; preds = %.lr.ph39.prol.loopexit, %.lr.ph39, %._crit_edge
  %.122.lcssa = phi i64 [ %15, %._crit_edge ], [ %.lcssa, %.lr.ph39 ], [ %.lcssa, %.lr.ph39.prol.loopexit ]
  %.120.lcssa = phi ptr [ %.019.lcssa, %._crit_edge ], [ %.lcssa61.unr, %.lr.ph39.prol.loopexit ], [ %35, %.lr.ph39 ]
  %24 = load i64, ptr @n_arc, align 8, !tbaa !12
  %25 = icmp slt i64 %.122.lcssa, %24
  br i1 %25, label %.lr.ph44, label %._crit_edge45

.lr.ph39:                                         ; preds = %.lr.ph39.prol.loopexit, %.lr.ph39
  %.12037 = phi ptr [ %35, %.lr.ph39 ], [ %.12037.unr, %.lr.ph39.prol.loopexit ]
  %.12236 = phi i64 [ %34, %.lr.ph39 ], [ %.12236.unr, %.lr.ph39.prol.loopexit ]
  %26 = getelementptr inbounds i8, ptr %.12037, i64 16
  store i64 %.0.lcssa, ptr %26, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %.12037, i64 48
  store i64 %.0.lcssa, ptr %27, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %.12037, i64 80
  store i64 %.0.lcssa, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %.12037, i64 112
  store i64 %.0.lcssa, ptr %29, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %.12037, i64 144
  store i64 %.0.lcssa, ptr %30, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %.12037, i64 176
  store i64 %.0.lcssa, ptr %31, align 8, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %.12037, i64 208
  store i64 %.0.lcssa, ptr %32, align 8, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %.12037, i64 240
  store i64 %.0.lcssa, ptr %33, align 8, !tbaa !13
  %34 = add nsw i64 %.12236, 8
  %35 = getelementptr inbounds i8, ptr %.12037, i64 256
  %36 = icmp slt i64 %34, %.lcssa
  br i1 %36, label %.lr.ph39, label %.preheader, !llvm.loop !19

.lr.ph44:                                         ; preds = %.preheader, %.lr.ph44
  %.243 = phi ptr [ %40, %.lr.ph44 ], [ %.120.lcssa, %.preheader ]
  %.22342 = phi i64 [ %39, %.lr.ph44 ], [ %.122.lcssa, %.preheader ]
  %37 = tail call i64 (ptr, ...) %switch.select27(ptr noundef nonnull getelementptr inbounds (i8, ptr @arc_costs, i64 8)) #2
  %38 = getelementptr inbounds i8, ptr %.243, i64 16
  store i64 %37, ptr %38, align 8, !tbaa !13
  %39 = add nsw i64 %.22342, 1
  %40 = getelementptr inbounds i8, ptr %.243, i64 32
  %41 = load i64, ptr @n_arc, align 8, !tbaa !12
  %42 = icmp slt i64 %39, %41
  br i1 %42, label %.lr.ph44, label %._crit_edge45, !llvm.loop !20

._crit_edge45:                                    ; preds = %.lr.ph44, %.preheader
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @exponential(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @uniform(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #1

attributes #0 = { 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 speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"stat_para", !11, i64 0, !7, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 16}
!14 = !{!"arcs", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !16}


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