; LLVM IR from caiozanatelli/MaxFlow :: src (Graph)

; 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.Queue = type { ptr, ptr, i32 }
%struct.Graph = type { ptr, ptr, ptr, i32, i32 }
%struct.NodeQueue = type { i32, ptr }
%struct.List = type { ptr, i32, i32 }
%struct.Edge = type { i32, i32, i32, i32 }

; 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 i32 @isMoreFlowPossible(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.Queue, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Graph, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %28, %3
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Graph, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %31

23:                                               ; preds = %17
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  store i32 -1, ptr %27, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %23
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !14

31:                                               ; preds = %17
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %32, i64 %34
  store i32 0, ptr %35, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #4
  call void @initQueue(ptr noundef %9)
  %36 = load i32, ptr %5, align 4, !tbaa !9
  call void @enqueue(ptr noundef %9, i32 noundef %36)
  br label %37

37:                                               ; preds = %112, %31
  %38 = call i32 @isQueueEmpty(ptr noundef %9)
  %39 = icmp ne i32 %38, 0
  %40 = xor i1 %39, true
  br i1 %40, label %41, label %113

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %42 = call ptr @dequeue(ptr noundef %9)
  store ptr %42, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NodeQueue, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !16
  store i32 %45, ptr %11, align 4, !tbaa !9
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %46) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %109, %41
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Graph, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct.List, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.List, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !19
  %57 = icmp slt i32 %48, %56
  br i1 %57, label %58, label %112

58:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Graph, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Graph, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !18
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.List, ptr %64, i64 %66
  %68 = getelementptr inbounds %struct.List, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !22
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds %struct.Edge, ptr %61, i64 %74
  store ptr %75, ptr %13, align 8, !tbaa !5
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Edge, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !23
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i32, ptr %76, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = icmp slt i32 %82, 0
  br i1 %83, label %84, label %108

84:                                               ; preds = %58
  %85 = load ptr, ptr %13, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.Edge, ptr %85, i32 0, i32 2
  %87 = load i32, ptr %86, align 4, !tbaa !25
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Edge, ptr %88, i32 0, i32 3
  %90 = load i32, ptr %89, align 4, !tbaa !26
  %91 = icmp slt i32 %87, %90
  br i1 %91, label %92, label %108

92:                                               ; preds = %84
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = load i32, ptr %11, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i32, ptr %93, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !9
  %98 = add nsw i32 %97, 1
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = load ptr, ptr %13, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.Edge, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 4, !tbaa !23
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i32, ptr %99, i64 %103
  store i32 %98, ptr %104, align 4, !tbaa !9
  %105 = load ptr, ptr %13, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.Edge, ptr %105, i32 0, i32 1
  %107 = load i32, ptr %106, align 4, !tbaa !23
  call void @enqueue(ptr noundef %9, i32 noundef %107)
  br label %108

108:                                              ; preds = %92, %84, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %109

109:                                              ; preds = %108
  %110 = load i32, ptr %12, align 4, !tbaa !9
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %12, align 4, !tbaa !9
  br label %47, !llvm.loop !27

112:                                              ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %37, !llvm.loop !28

113:                                              ; preds = %37
  call void @freeQueue(ptr noundef %9)
  %114 = load ptr, ptr %7, align 8, !tbaa !5
  %115 = load i32, ptr %6, align 4, !tbaa !9
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds i32, ptr %114, i64 %116
  %118 = load i32, ptr %117, align 4, !tbaa !9
  %119 = icmp ne i32 %118, -1
  %120 = zext i1 %119 to i32
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 %120
}

declare void @initQueue(ptr noundef) #2

declare void @enqueue(ptr noundef, i32 noundef) #2

declare i32 @isQueueEmpty(ptr noundef) #2

declare ptr @dequeue(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

declare void @freeQueue(ptr noundef) #2

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 = { "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 "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 #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28}
!13 = !{!12, !10, i64 28}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 0}
!17 = !{!"NodeQueue", !10, i64 0, !6, i64 8}
!18 = !{!12, !6, i64 0}
!19 = !{!20, !10, i64 12}
!20 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12}
!21 = !{!12, !6, i64 8}
!22 = !{!20, !6, i64 0}
!23 = !{!24, !10, i64 4}
!24 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!25 = !{!24, !10, i64 8}
!26 = !{!24, !10, i64 12}
!27 = distinct !{!27, !15}
!28 = distinct !{!28, !15}


; 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.Queue = type { ptr, ptr, i32 }
%struct.List = type { ptr, i32, i32 }
%struct.Edge = type { i32, i32, i32, i32 }

; 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 range(i32 0, 2) i32 @isMoreFlowPossible(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.Queue, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 28
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %3 ]
  %10 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  store i32 -1, ptr %10, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr %7, align 4, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %3
  %14 = sext i32 %1 to i64
  %15 = getelementptr inbounds i32, ptr %6, i64 %14
  store i32 0, ptr %15, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  call void @initQueue(ptr noundef nonnull %4) #4
  call void @enqueue(ptr noundef nonnull %4, i32 noundef %1) #4
  %16 = call i32 @isQueueEmpty(ptr noundef nonnull %4) #4
  %.not34 = icmp eq i32 %16, 0
  br i1 %.not34, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %._crit_edge
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  br label %19

.loopexit:                                        ; preds = %54, %19
  %18 = call i32 @isQueueEmpty(ptr noundef nonnull %4) #4
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %._crit_edge37, !llvm.loop !15

19:                                               ; preds = %.lr.ph36, %.loopexit
  %20 = call ptr @dequeue(ptr noundef nonnull %4) #4
  %21 = load i32, ptr %20, align 8, !tbaa !16
  call void @free(ptr noundef %20) #4
  %22 = sext i32 %21 to i64
  %23 = load ptr, ptr %0, align 8, !tbaa !18
  %24 = getelementptr inbounds %struct.List, ptr %23, i64 %22
  %25 = getelementptr inbounds i8, ptr %24, i64 12
  %26 = load i32, ptr %25, align 4, !tbaa !19
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph33, label %.loopexit

.lr.ph33:                                         ; preds = %19
  %28 = getelementptr inbounds i32, ptr %6, i64 %22
  br label %29

29:                                               ; preds = %.lr.ph33, %54
  %30 = phi ptr [ %23, %.lr.ph33 ], [ %55, %54 ]
  %indvars.iv39 = phi i64 [ 0, %.lr.ph33 ], [ %indvars.iv.next40, %54 ]
  %31 = phi ptr [ %24, %.lr.ph33 ], [ %56, %54 ]
  %32 = load ptr, ptr %17, align 8, !tbaa !21
  %33 = load ptr, ptr %31, align 8, !tbaa !22
  %34 = getelementptr inbounds i32, ptr %33, i64 %indvars.iv39
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.Edge, ptr %32, i64 %36
  %38 = getelementptr inbounds i8, ptr %37, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !23
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %6, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !12
  %43 = icmp slt i32 %42, 0
  br i1 %43, label %44, label %54

44:                                               ; preds = %29
  %45 = getelementptr inbounds i8, ptr %37, i64 8
  %46 = load i32, ptr %45, align 4, !tbaa !25
  %47 = getelementptr inbounds i8, ptr %37, i64 12
  %48 = load i32, ptr %47, align 4, !tbaa !26
  %49 = icmp slt i32 %46, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %44
  %51 = load i32, ptr %28, align 4, !tbaa !12
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %41, align 4, !tbaa !12
  %53 = load i32, ptr %38, align 4, !tbaa !23
  call void @enqueue(ptr noundef nonnull %4, i32 noundef %53) #4
  %.pre = load ptr, ptr %0, align 8, !tbaa !18
  br label %54

54:                                               ; preds = %50, %44, %29
  %55 = phi ptr [ %.pre, %50 ], [ %30, %44 ], [ %30, %29 ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %56 = getelementptr inbounds %struct.List, ptr %55, i64 %22
  %57 = getelementptr inbounds i8, ptr %56, i64 12
  %58 = load i32, ptr %57, align 4, !tbaa !19
  %59 = sext i32 %58 to i64
  %60 = icmp slt i64 %indvars.iv.next40, %59
  br i1 %60, label %29, label %.loopexit, !llvm.loop !27

._crit_edge37:                                    ; preds = %.loopexit, %._crit_edge
  call void @freeQueue(ptr noundef nonnull %4) #4
  %61 = sext i32 %2 to i64
  %62 = getelementptr inbounds i32, ptr %6, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !12
  %64 = icmp ne i32 %63, -1
  %65 = zext i1 %64 to i32
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  ret i32 %65
}

declare void @initQueue(ptr noundef) local_unnamed_addr #2

declare void @enqueue(ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @isQueueEmpty(ptr noundef) local_unnamed_addr #2

declare ptr @dequeue(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

declare void @freeQueue(ptr noundef) local_unnamed_addr #2

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 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { 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, !7, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 28}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !10, i64 0}
!17 = !{!"NodeQueue", !10, i64 0, !7, i64 8}
!18 = !{!6, !7, i64 0}
!19 = !{!20, !10, i64 12}
!20 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!21 = !{!6, !7, i64 8}
!22 = !{!20, !7, i64 0}
!23 = !{!24, !10, i64 4}
!24 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!25 = !{!24, !10, i64 8}
!26 = !{!24, !10, i64 12}
!27 = distinct !{!27, !14}


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