; LLVM IR from adamdempsey90/MultiGrid :: src (vcycle)

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

; Function Attrs: nounwind uwtable
define dso_local void @vcycle(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %24

17:                                               ; preds = %5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  call void @solve(ptr noundef %22, ptr noundef %23)
  br label %113

24:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = shl i32 2, %25
  %27 = add nsw i32 1, %26
  store i32 %27, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = sub nsw i32 %28, 1
  %30 = shl i32 2, %29
  %31 = add nsw i32 1, %30
  store i32 %31, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = mul i64 8, %33
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = mul i64 %34, %36
  %38 = call noalias ptr @malloc(i64 noundef %37) #6
  store ptr %38, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = mul i64 8, %40
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = mul i64 %41, %43
  %45 = call noalias ptr @malloc(i64 noundef %44) #6
  store ptr %45, ptr %14, align 8, !tbaa !5
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = mul nsw i32 %47, %48
  call void @matfill(ptr noundef %46, ptr noundef null, i32 noundef %49)
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = mul nsw i32 %51, %52
  call void @matfill(ptr noundef %50, ptr noundef null, i32 noundef %53)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = load i32, ptr %9, align 4, !tbaa !9
  call void @gauss_seidel(ptr noundef %58, ptr noundef %59, i32 noundef %60, i32 noundef %61)
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !9
  call void @residual(ptr noundef %62, ptr noundef %67, ptr noundef %68, i32 noundef %69)
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = sub nsw i32 %72, 1
  call void @restrict2D(ptr noundef %70, ptr noundef %71, i32 noundef %73)
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = sub nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds ptr, ptr %74, i64 %77
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = mul nsw i32 %80, %81
  call void @matfill(ptr noundef %79, ptr noundef null, i32 noundef %82)
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = sub nsw i32 %85, 1
  %87 = load i32, ptr %9, align 4, !tbaa !9
  %88 = load i32, ptr %10, align 4, !tbaa !9
  call void @vcycle(ptr noundef %83, ptr noundef %84, i32 noundef %86, i32 noundef %87, i32 noundef %88)
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = load i32, ptr %8, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds ptr, ptr %89, i64 %91
  %93 = load ptr, ptr %92, align 8, !tbaa !5
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = load i32, ptr %8, align 4, !tbaa !9
  %96 = sub nsw i32 %95, 1
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds ptr, ptr %94, i64 %97
  %99 = load ptr, ptr %98, align 8, !tbaa !5
  %100 = load ptr, ptr %13, align 8, !tbaa !5
  %101 = load i32, ptr %8, align 4, !tbaa !9
  %102 = sub nsw i32 %101, 1
  call void @addint(ptr noundef %93, ptr noundef %99, ptr noundef %100, i32 noundef %102)
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load i32, ptr %8, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds ptr, ptr %103, i64 %105
  %107 = load ptr, ptr %106, align 8, !tbaa !5
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = load i32, ptr %8, align 4, !tbaa !9
  %110 = load i32, ptr %10, align 4, !tbaa !9
  call void @gauss_seidel(ptr noundef %107, ptr noundef %108, i32 noundef %109, i32 noundef %110)
  %111 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %111) #5
  %112 = load ptr, ptr %14, align 8, !tbaa !5
  call void @free(ptr noundef %112) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %113

113:                                              ; preds = %24, %17
  ret void
}

declare void @solve(ptr noundef, ptr noundef) #1

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

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

declare void @matfill(ptr noundef, ptr noundef, i32 noundef) #1

declare void @gauss_seidel(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

declare void @residual(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare void @restrict2D(ptr noundef, ptr noundef, i32 noundef) #1

declare void @addint(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

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

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

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


; 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: nounwind uwtable
define dso_local void @vcycle(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %2, 0
  br i1 %6, label %common.ret, label %8

common.ret:                                       ; preds = %5
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @solve(ptr noundef %7, ptr noundef %1) #4
  br label %common.ret50

common.ret50:                                     ; preds = %8, %common.ret
  ret void

8:                                                ; preds = %5
  %9 = shl i32 2, %2
  %10 = or disjoint i32 %9, 1
  %11 = add nsw i32 %2, -1
  %12 = shl i32 2, %11
  %13 = or disjoint i32 %12, 1
  %14 = sext i32 %10 to i64
  %15 = shl nsw i64 %14, 3
  %16 = mul i64 %15, %14
  %17 = tail call noalias ptr @malloc(i64 noundef %16) #5
  %18 = sext i32 %13 to i64
  %19 = shl nsw i64 %18, 3
  %20 = mul i64 %19, %18
  %21 = tail call noalias ptr @malloc(i64 noundef %20) #5
  %22 = mul nsw i32 %10, %10
  tail call void @matfill(ptr noundef %17, ptr noundef null, i32 noundef %22) #4
  %23 = mul nsw i32 %13, %13
  tail call void @matfill(ptr noundef %21, ptr noundef null, i32 noundef %23) #4
  %24 = sext i32 %2 to i64
  %25 = getelementptr inbounds ptr, ptr %0, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  tail call void @gauss_seidel(ptr noundef %26, ptr noundef %1, i32 noundef %2, i32 noundef %3) #4
  %27 = load ptr, ptr %25, align 8, !tbaa !5
  tail call void @residual(ptr noundef %17, ptr noundef %27, ptr noundef %1, i32 noundef %2) #4
  tail call void @restrict2D(ptr noundef %21, ptr noundef %17, i32 noundef %11) #4
  %28 = sext i32 %11 to i64
  %29 = getelementptr inbounds ptr, ptr %0, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  tail call void @matfill(ptr noundef %30, ptr noundef null, i32 noundef %23) #4
  tail call void @vcycle(ptr noundef %0, ptr noundef %21, i32 noundef %11, i32 noundef %3, i32 noundef %4)
  %31 = load ptr, ptr %25, align 8, !tbaa !5
  %32 = load ptr, ptr %29, align 8, !tbaa !5
  tail call void @addint(ptr noundef %31, ptr noundef %32, ptr noundef %17, i32 noundef %11) #4
  %33 = load ptr, ptr %25, align 8, !tbaa !5
  tail call void @gauss_seidel(ptr noundef %33, ptr noundef %1, i32 noundef %2, i32 noundef %4) #4
  tail call void @free(ptr noundef %17) #4
  tail call void @free(ptr noundef %21) #4
  br label %common.ret50
}

declare void @solve(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare void @matfill(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @gauss_seidel(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @residual(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @restrict2D(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @addint(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

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 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #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 }
attributes #5 = { 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass