; 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.imbalance = type { i64, i64 }
%struct.arcs = type { i64, i64, i64, i64 }

@source_list = external dso_local global ptr, align 8
@sink_list = external dso_local global ptr, align 8
@n_source = external dso_local global i64, align 8
@n_sink = external dso_local global i64, align 8
@n_node = 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 ptr @gen_additional_arcs(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %4

4:                                                ; preds = %19, %1
  %5 = load i64, ptr %3, align 8, !tbaa !9
  %6 = load i64, ptr @n_source, align 8, !tbaa !9
  %7 = icmp slt i64 %5, %6
  br i1 %7, label %8, label %24

8:                                                ; preds = %4
  %9 = load ptr, ptr @source_list, align 8, !tbaa !5
  %10 = load i64, ptr %3, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.imbalance, ptr %9, i64 %10
  %12 = getelementptr inbounds %struct.imbalance, ptr %11, i32 0, i32 0
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.arcs, ptr %14, i32 0, i32 0
  store i64 %13, ptr %15, align 8, !tbaa !13
  %16 = load i64, ptr @n_node, align 8, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.arcs, ptr %17, i32 0, i32 1
  store i64 %16, ptr %18, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %8
  %20 = load i64, ptr %3, align 8, !tbaa !9
  %21 = add nsw i64 %20, 1
  store i64 %21, ptr %3, align 8, !tbaa !9
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.arcs, ptr %22, i32 1
  store ptr %23, ptr %2, align 8, !tbaa !5
  br label %4, !llvm.loop !16

24:                                               ; preds = %4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %40, %24
  %26 = load i64, ptr %3, align 8, !tbaa !9
  %27 = load i64, ptr @n_sink, align 8, !tbaa !9
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %29, label %45

29:                                               ; preds = %25
  %30 = load ptr, ptr @sink_list, align 8, !tbaa !5
  %31 = load i64, ptr %3, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.imbalance, ptr %30, i64 %31
  %33 = getelementptr inbounds %struct.imbalance, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.arcs, ptr %35, i32 0, i32 1
  store i64 %34, ptr %36, align 8, !tbaa !15
  %37 = load i64, ptr @n_node, align 8, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.arcs, ptr %38, i32 0, i32 0
  store i64 %37, ptr %39, align 8, !tbaa !13
  br label %40

40:                                               ; preds = %29
  %41 = load i64, ptr %3, align 8, !tbaa !9
  %42 = add nsw i64 %41, 1
  store i64 %42, ptr %3, align 8, !tbaa !9
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.arcs, ptr %43, i32 1
  store ptr %44, ptr %2, align 8, !tbaa !5
  br label %25, !llvm.loop !18

45:                                               ; preds = %25
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret ptr %46
}

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 = !{!"imbalance", !10, i64 0, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"arcs", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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.imbalance = type { i64, i64 }

@source_list = external dso_local local_unnamed_addr global ptr, align 8
@sink_list = external dso_local local_unnamed_addr global ptr, 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_node = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @gen_additional_arcs(ptr noundef writeonly %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @n_source, align 8, !tbaa !5
  %3 = icmp sgt i64 %2, 0
  br i1 %3, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %1
  %4 = load ptr, ptr @source_list, align 8, !tbaa !9
  br label %8

.preheader:                                       ; preds = %8, %1
  %.012.lcssa = phi ptr [ %0, %1 ], [ %14, %8 ]
  %5 = load i64, ptr @n_sink, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph18, label %._crit_edge

.lr.ph18:                                         ; preds = %.preheader
  %7 = load ptr, ptr @sink_list, align 8, !tbaa !9
  %.pre = load i64, ptr @n_node, align 8, !tbaa !5
  br label %17

8:                                                ; preds = %.lr.ph, %8
  %.015 = phi i64 [ 0, %.lr.ph ], [ %13, %8 ]
  %.01214 = phi ptr [ %0, %.lr.ph ], [ %14, %8 ]
  %9 = getelementptr inbounds %struct.imbalance, ptr %4, i64 %.015
  %10 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %10, ptr %.01214, align 8, !tbaa !13
  %11 = load i64, ptr @n_node, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.01214, i64 8
  store i64 %11, ptr %12, align 8, !tbaa !15
  %13 = add nuw nsw i64 %.015, 1
  %14 = getelementptr inbounds i8, ptr %.01214, i64 32
  %15 = load i64, ptr @n_source, align 8, !tbaa !5
  %16 = icmp slt i64 %13, %15
  br i1 %16, label %8, label %.preheader, !llvm.loop !16

17:                                               ; preds = %.lr.ph18, %17
  %.117 = phi i64 [ 0, %.lr.ph18 ], [ %21, %17 ]
  %.11316 = phi ptr [ %.012.lcssa, %.lr.ph18 ], [ %22, %17 ]
  %18 = getelementptr inbounds %struct.imbalance, ptr %7, i64 %.117
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %.11316, i64 8
  store i64 %19, ptr %20, align 8, !tbaa !15
  store i64 %.pre, ptr %.11316, align 8, !tbaa !13
  %21 = add nuw nsw i64 %.117, 1
  %22 = getelementptr inbounds i8, ptr %.11316, i64 32
  %23 = load i64, ptr @n_sink, align 8, !tbaa !5
  %24 = icmp slt i64 %21, %23
  br i1 %24, label %17, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %17, %.preheader
  %.113.lcssa = phi ptr [ %.012.lcssa, %.preheader ], [ %22, %17 ]
  ret ptr %.113.lcssa
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass