; 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
@capacities = external dso_local global %struct.stat_para, align 8
@supply = 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_capacities() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %4 = load ptr, ptr @arc_list, align 8, !tbaa !5
  store ptr %4, 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
  %5 = load i64, ptr @arc_costs, align 8, !tbaa !9
  switch i64 %5, label %8 [
    i64 1, label %6
    i64 2, label %7
  ]

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

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

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

12:                                               ; preds = %21, %8
  %13 = load i64, ptr %3, align 8, !tbaa !12
  %14 = load i64, ptr @n_grid_arc, align 8, !tbaa !12
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %16, label %26

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call i64 (ptr, ...) %17(ptr noundef getelementptr inbounds (%struct.stat_para, ptr @capacities, i32 0, i32 1))
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.arcs, ptr %19, i32 0, i32 3
  store i64 %18, ptr %20, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %16
  %22 = load i64, ptr %3, align 8, !tbaa !12
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %3, align 8, !tbaa !12
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.arcs, ptr %24, i32 1
  store ptr %25, ptr %1, align 8, !tbaa !5
  br label %12, !llvm.loop !15

26:                                               ; preds = %12
  %27 = load i64, ptr %3, align 8, !tbaa !12
  %28 = load i64, ptr @n_source, align 8, !tbaa !12
  %29 = sub nsw i64 %27, %28
  %30 = load i64, ptr @n_sink, align 8, !tbaa !12
  %31 = sub nsw i64 %29, %30
  store i64 %31, ptr %3, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %40, %26
  %33 = load i64, ptr %3, align 8, !tbaa !12
  %34 = load i64, ptr @n_grid_arc, align 8, !tbaa !12
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %36, label %45

36:                                               ; preds = %32
  %37 = load i64, ptr @supply, align 8, !tbaa !12
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.arcs, ptr %38, i32 0, i32 3
  store i64 %37, ptr %39, align 8, !tbaa !13
  br label %40

40:                                               ; preds = %36
  %41 = load i64, ptr %3, align 8, !tbaa !12
  %42 = add nsw i64 %41, 1
  store i64 %42, ptr %3, align 8, !tbaa !12
  %43 = load ptr, ptr %1, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.arcs, ptr %43, i32 1
  store ptr %44, ptr %1, align 8, !tbaa !5
  br label %32, !llvm.loop !17

45:                                               ; preds = %32
  br label %46

46:                                               ; preds = %55, %45
  %47 = load i64, ptr %3, align 8, !tbaa !12
  %48 = load i64, ptr @n_arc, align 8, !tbaa !12
  %49 = icmp slt i64 %47, %48
  br i1 %49, label %50, label %60

50:                                               ; preds = %46
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = call i64 (ptr, ...) %51(ptr noundef getelementptr inbounds (%struct.stat_para, ptr @capacities, i32 0, i32 1))
  %53 = load ptr, ptr %1, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.arcs, ptr %53, i32 0, i32 3
  store i64 %52, ptr %54, align 8, !tbaa !13
  br label %55

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

60:                                               ; preds = %46
  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, !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 24}
!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, !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 local_unnamed_addr 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
@capacities = external dso_local global %struct.stat_para, align 8
@supply = 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_capacities() 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.selectcmp18 = icmp eq i64 %2, 1
  %switch.select19 = select i1 %switch.selectcmp18, 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
  %.023 = phi i64 [ %10, %.lr.ph ], [ %5, %0 ]
  %.01522 = phi ptr [ %11, %.lr.ph ], [ %1, %0 ]
  %8 = tail call i64 (ptr, ...) %switch.select19(ptr noundef nonnull getelementptr inbounds (i8, ptr @capacities, i64 8)) #1
  %9 = getelementptr inbounds i8, ptr %.01522, i64 24
  store i64 %8, ptr %9, align 8, !tbaa !13
  %10 = add nsw i64 %.023, 1
  %11 = getelementptr inbounds i8, ptr %.01522, 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
  %.pre41 = load i64, ptr @n_sink, align 8, !tbaa !12
  %.pre42 = add i64 %.pre, %.pre41
  br label %._crit_edge

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

.lr.ph29:                                         ; preds = %._crit_edge
  %16 = load i64, ptr @supply, align 8, !tbaa !12
  %17 = add i64 %.lcssa, %.pre-phi
  %18 = sub i64 %17, %.0.lcssa
  %xtraiter = and i64 %18, 7
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph29, %.prol.preheader
  %.127.prol = phi i64 [ %20, %.prol.preheader ], [ %14, %.lr.ph29 ]
  %.11626.prol = phi ptr [ %21, %.prol.preheader ], [ %.015.lcssa, %.lr.ph29 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph29 ]
  %19 = getelementptr inbounds i8, ptr %.11626.prol, i64 24
  store i64 %16, ptr %19, align 8, !tbaa !13
  %20 = add nsw i64 %.127.prol, 1
  %21 = getelementptr inbounds i8, ptr %.11626.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 %.prol.loopexit, label %.prol.preheader, !llvm.loop !17

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph29
  %.127.unr = phi i64 [ %14, %.lr.ph29 ], [ %20, %.prol.preheader ]
  %.11626.unr = phi ptr [ %.015.lcssa, %.lr.ph29 ], [ %21, %.prol.preheader ]
  %.lcssa51.unr = phi ptr [ poison, %.lr.ph29 ], [ %21, %.prol.preheader ]
  %22 = sub i64 %.0.lcssa, %17
  %23 = icmp ugt i64 %22, -8
  br i1 %23, label %.preheader, label %.lr.ph29.new

.preheader:                                       ; preds = %.prol.loopexit, %.lr.ph29.new, %._crit_edge
  %.116.lcssa = phi ptr [ %.015.lcssa, %._crit_edge ], [ %.lcssa51.unr, %.prol.loopexit ], [ %35, %.lr.ph29.new ]
  %.1.lcssa = phi i64 [ %14, %._crit_edge ], [ %.lcssa, %.lr.ph29.new ], [ %.lcssa, %.prol.loopexit ]
  %24 = load i64, ptr @n_arc, align 8, !tbaa !12
  %25 = icmp slt i64 %.1.lcssa, %24
  br i1 %25, label %.lr.ph34, label %._crit_edge35

.lr.ph29.new:                                     ; preds = %.prol.loopexit, %.lr.ph29.new
  %.127 = phi i64 [ %34, %.lr.ph29.new ], [ %.127.unr, %.prol.loopexit ]
  %.11626 = phi ptr [ %35, %.lr.ph29.new ], [ %.11626.unr, %.prol.loopexit ]
  %26 = getelementptr inbounds i8, ptr %.11626, i64 24
  store i64 %16, ptr %26, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %.11626, i64 56
  store i64 %16, ptr %27, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %.11626, i64 88
  store i64 %16, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %.11626, i64 120
  store i64 %16, ptr %29, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %.11626, i64 152
  store i64 %16, ptr %30, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %.11626, i64 184
  store i64 %16, ptr %31, align 8, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %.11626, i64 216
  store i64 %16, ptr %32, align 8, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %.11626, i64 248
  store i64 %16, ptr %33, align 8, !tbaa !13
  %34 = add nsw i64 %.127, 8
  %35 = getelementptr inbounds i8, ptr %.11626, i64 256
  %36 = icmp slt i64 %34, %.lcssa
  br i1 %36, label %.lr.ph29.new, label %.preheader, !llvm.loop !19

.lr.ph34:                                         ; preds = %.preheader, %.lr.ph34
  %.233 = phi i64 [ %39, %.lr.ph34 ], [ %.1.lcssa, %.preheader ]
  %.21732 = phi ptr [ %40, %.lr.ph34 ], [ %.116.lcssa, %.preheader ]
  %37 = tail call i64 (ptr, ...) %switch.select19(ptr noundef nonnull getelementptr inbounds (i8, ptr @capacities, i64 8)) #1
  %38 = getelementptr inbounds i8, ptr %.21732, i64 24
  store i64 %37, ptr %38, align 8, !tbaa !13
  %39 = add nsw i64 %.233, 1
  %40 = getelementptr inbounds i8, ptr %.21732, i64 32
  %41 = load i64, ptr @n_arc, align 8, !tbaa !12
  %42 = icmp slt i64 %39, %41
  br i1 %42, label %.lr.ph34, label %._crit_edge35, !llvm.loop !20

._crit_edge35:                                    ; preds = %.lr.ph34, %.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

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 = { 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 24}
!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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass