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

@n_grid_arc = external dso_local global i64, align 8
@n_arc = 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 void @gen_more_arcs(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca [2 x float], align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %5 = getelementptr inbounds [2 x float], ptr %4, i64 0, i64 0
  store float 0x3FECCCCCC0000000, ptr %5, align 4, !tbaa !9
  %6 = load i64, ptr @n_node, align 8, !tbaa !11
  %7 = sitofp i64 %6 to double
  %8 = fsub double %7, 0x3FEFAE147AE147AE
  %9 = fptrunc double %8 to float
  %10 = getelementptr inbounds [2 x float], ptr %4, i64 0, i64 1
  store float %9, ptr %10, align 4, !tbaa !9
  %11 = load i64, ptr @n_grid_arc, align 8, !tbaa !11
  store i64 %11, ptr %3, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %38, %1
  %13 = load i64, ptr %3, align 8, !tbaa !11
  %14 = load i64, ptr @n_arc, align 8, !tbaa !11
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %16, label %43

16:                                               ; preds = %12
  %17 = getelementptr inbounds [2 x float], ptr %4, i64 0, i64 0
  %18 = call i64 @uniform(ptr noundef %17)
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.arcs, ptr %19, i32 0, i32 0
  store i64 %18, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds [2 x float], ptr %4, i64 0, i64 0
  %22 = call i64 @uniform(ptr noundef %21)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.arcs, ptr %23, i32 0, i32 1
  store i64 %22, ptr %24, align 8, !tbaa !15
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.arcs, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.arcs, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = icmp eq i64 %27, %30
  br i1 %31, label %32, label %37

32:                                               ; preds = %16
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.arcs, ptr %33, i32 -1
  store ptr %34, ptr %2, align 8, !tbaa !5
  %35 = load i64, ptr %3, align 8, !tbaa !11
  %36 = add nsw i64 %35, -1
  store i64 %36, ptr %3, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %32, %16
  br label %38

38:                                               ; preds = %37
  %39 = load i64, ptr %3, align 8, !tbaa !11
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %3, align 8, !tbaa !11
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.arcs, ptr %41, i32 1
  store ptr %42, ptr %2, align 8, !tbaa !5
  br label %12, !llvm.loop !16

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

; 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"arcs", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!15 = !{!14, !12, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@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
@n_node = external dso_local local_unnamed_addr global i64, align 8

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

; Function Attrs: mustprogress 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 @gen_more_arcs(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = alloca [2 x float], align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #2
  store float 0x3FECCCCCC0000000, ptr %2, align 4, !tbaa !5
  %3 = load i64, ptr @n_node, align 8, !tbaa !9
  %4 = sitofp i64 %3 to double
  %5 = fadd double %4, 0xBFEFAE147AE147AE
  %6 = fptrunc double %5 to float
  %7 = getelementptr inbounds i8, ptr %2, i64 4
  store float %6, ptr %7, align 4, !tbaa !5
  %8 = load i64, ptr @n_grid_arc, align 8, !tbaa !9
  %9 = load i64, ptr @n_arc, align 8, !tbaa !9
  %10 = icmp slt i64 %8, %9
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.011 = phi i64 [ %17, %.lr.ph ], [ %8, %1 ]
  %.0810 = phi ptr [ %18, %.lr.ph ], [ %0, %1 ]
  %11 = call i64 @uniform(ptr noundef nonnull %2)
  store i64 %11, ptr %.0810, align 8, !tbaa !11
  %12 = call i64 @uniform(ptr noundef nonnull %2)
  %13 = getelementptr inbounds i8, ptr %.0810, i64 8
  store i64 %12, ptr %13, align 8, !tbaa !13
  %14 = load i64, ptr %.0810, align 8, !tbaa !11
  %15 = icmp eq i64 %14, %12
  %.19.idx = select i1 %15, i64 -32, i64 0
  %.19 = getelementptr inbounds i8, ptr %.0810, i64 %.19.idx
  %16 = sext i1 %15 to i64
  %.1 = add nsw i64 %.011, 1
  %17 = add nsw i64 %.1, %16
  %18 = getelementptr inbounds i8, ptr %.19, i64 32
  %19 = load i64, ptr @n_arc, align 8, !tbaa !9
  %20 = icmp slt i64 %17, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #2
  ret void
}

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

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


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