; LLVM IR from hutusi/rethink-c :: 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._AdjacencyMatrix = type { i32, i32, ptr }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @adjacency_matrix_bfs(ptr noundef %0, i32 noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  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 4, ptr %7) #7
  store i32 -1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._AdjacencyMatrix, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = mul i64 4, %16
  %18 = call noalias ptr @malloc(i64 noundef %17) #8
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._AdjacencyMatrix, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = mul i64 4, %23
  call void @llvm.memset.p0.i64(ptr align 4 %19, i8 0, i64 %24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %25 = call ptr (...) @queue_new()
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = call ptr @intdup(i32 noundef %27)
  %29 = call i32 @queue_push_tail(ptr noundef %26, ptr noundef %28)
  br label %30

30:                                               ; preds = %83, %3
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call i32 @queue_is_empty(ptr noundef %31)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %84

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = call ptr @queue_pop_head(ptr noundef %35)
  store ptr %36, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %37, i64 %40
  store i32 1, ptr %41, align 4, !tbaa !9
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %34
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %47) #7
  store i32 0, ptr %7, align 4, !tbaa !9
  store i32 3, ptr %11, align 4
  br label %81

48:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %76, %48
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._AdjacencyMatrix, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = icmp slt i32 %50, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %49
  store i32 4, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %79

56:                                               ; preds = %49
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = call i32 @adjacency_matrix_connected(ptr noundef %57, i32 noundef %59, i32 noundef %60)
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %75

63:                                               ; preds = %56
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %75, label %70

70:                                               ; preds = %63
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = call ptr @intdup(i32 noundef %72)
  %74 = call i32 @queue_push_tail(ptr noundef %71, ptr noundef %73)
  br label %75

75:                                               ; preds = %70, %63, %56
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %12, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %12, align 4, !tbaa !9
  br label %49, !llvm.loop !13

79:                                               ; preds = %55
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %80) #7
  store i32 0, ptr %11, align 4
  br label %81

81:                                               ; preds = %79, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  %82 = load i32, ptr %11, align 4
  switch i32 %82, label %88 [
    i32 0, label %83
    i32 3, label %84
  ]

83:                                               ; preds = %81
  br label %30, !llvm.loop !15

84:                                               ; preds = %81, %30
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  call void @queue_free(ptr noundef %85)
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %86) #7
  %87 = load i32, ptr %7, align 4, !tbaa !9
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  ret i32 %87

88:                                               ; preds = %81
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare ptr @queue_new(...) #5

declare i32 @queue_push_tail(ptr noundef, ptr noundef) #5

declare ptr @intdup(i32 noundef) #5

declare i32 @queue_is_empty(ptr noundef) #5

declare ptr @queue_pop_head(ptr noundef) #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @adjacency_matrix_connected(ptr noundef, i32 noundef, i32 noundef) #6

declare void @queue_free(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 "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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { "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 #6 = { inlinehint 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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, !10, i64 4}
!12 = !{!"_AdjacencyMatrix", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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"

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @adjacency_matrix_bfs(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 2
  %calloc = tail call ptr @calloc(i64 1, i64 %7)
  %8 = tail call ptr (...) @queue_new() #5
  %9 = tail call ptr @intdup(i32 noundef %1) #5
  %10 = tail call i32 @queue_push_tail(ptr noundef %8, ptr noundef %9) #5
  %11 = tail call i32 @queue_is_empty(ptr noundef %8) #5
  %.not34 = icmp eq i32 %11, 0
  br i1 %.not34, label %.loopexit, label %.lr.ph36

.lr.ph36:                                         ; preds = %3, %._crit_edge
  %12 = tail call ptr @queue_pop_head(ptr noundef %8) #5
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr %calloc, i64 %14
  store i32 1, ptr %15, align 4, !tbaa !11
  %16 = icmp eq i32 %13, %2
  br i1 %16, label %.thread, label %.preheader

.preheader:                                       ; preds = %.lr.ph36
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.thread:                                          ; preds = %.lr.ph36
  tail call void @free(ptr noundef nonnull %12) #5
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %28
  %indvars.iv = phi i64 [ %indvars.iv.next, %28 ], [ 0, %.preheader ]
  %19 = load i32, ptr %12, align 4, !tbaa !11
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  %21 = tail call i32 @adjacency_matrix_connected(ptr noundef nonnull %0, i32 noundef %19, i32 noundef %20)
  %.not28 = icmp eq i32 %21, 0
  br i1 %.not28, label %28, label %22

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds i32, ptr %calloc, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %.not29 = icmp eq i32 %24, 0
  br i1 %.not29, label %25, label %28

25:                                               ; preds = %22
  %26 = tail call ptr @intdup(i32 noundef %20) #5
  %27 = tail call i32 @queue_push_tail(ptr noundef %8, ptr noundef %26) #5
  br label %28

28:                                               ; preds = %.lr.ph, %22, %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next, %30
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %28, %.preheader
  tail call void @free(ptr noundef nonnull %12) #5
  %32 = tail call i32 @queue_is_empty(ptr noundef %8) #5
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %.loopexit, label %.lr.ph36

.loopexit:                                        ; preds = %._crit_edge, %3, %.thread
  %.2 = phi i32 [ 0, %.thread ], [ -1, %3 ], [ -1, %._crit_edge ]
  tail call void @queue_free(ptr noundef %8) #5
  tail call void @free(ptr noundef %calloc) #5
  ret i32 %.2
}

declare ptr @queue_new(...) local_unnamed_addr #2

declare i32 @queue_push_tail(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @intdup(i32 noundef) local_unnamed_addr #2

declare i32 @queue_is_empty(ptr noundef) local_unnamed_addr #2

declare ptr @queue_pop_head(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @adjacency_matrix_connected(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @queue_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #4

attributes #0 = { 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 #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 = { inlinehint 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 #4 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #5 = { 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 4}
!6 = !{!"_AdjacencyMatrix", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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