; LLVM IR from arasgungore/filters-and-fractals :: main (drawCantor)

; 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.PPMPixel = type { i8, i8, i8 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local void @drawLine(i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i24) #1

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

16:                                               ; preds = %5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = add i32 %19, %20
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 1 %6, i64 3, i1 false)
  %24 = load i24, ptr %11, align 4
  call void @drawLine(i32 noundef %17, i32 noundef %18, i32 noundef %21, i32 noundef %22, ptr noundef %23, i24 %24)
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = sub nsw i32 %25, 20
  store i32 %26, ptr %8, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = udiv i32 %29, 3
  %31 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 1 %6, i64 3, i1 false)
  %32 = load i24, ptr %12, align 4
  call void @drawCantor(i32 noundef %27, i32 noundef %28, i32 noundef %30, ptr noundef %31, i24 %32)
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = mul i32 2, %34
  %36 = udiv i32 %35, 3
  %37 = add i32 %33, %36
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = udiv i32 %39, 3
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 1 %6, i64 3, i1 false)
  %42 = load i24, ptr %13, align 4
  call void @drawCantor(i32 noundef %37, i32 noundef %38, i32 noundef %40, ptr noundef %41, i24 %42)
  br label %43

43:                                               ; preds = %16, %5
  ret void
}

attributes #0 = { nocallback nofree 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" }

!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 = !{!"int", !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}


; 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
declare dso_local void @drawLine(i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i24) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @drawCantor(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i24 %4) local_unnamed_addr #0 {
  %.not27 = icmp eq i32 %2, 0
  br i1 %.not27, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %5, %tailrecurse
  %.tr2430 = phi i32 [ %8, %tailrecurse ], [ %2, %5 ]
  %.tr2329 = phi i32 [ %7, %tailrecurse ], [ %1, %5 ]
  %.tr28 = phi i32 [ %11, %tailrecurse ], [ %0, %5 ]
  %6 = add i32 %.tr2430, %.tr28
  tail call void @drawLine(i32 noundef %.tr28, i32 noundef %.tr2329, i32 noundef %6, i32 noundef %.tr2329, ptr noundef %3, i24 %4)
  %7 = add nsw i32 %.tr2329, -20
  %8 = udiv i32 %.tr2430, 3
  tail call void @drawCantor(i32 noundef %.tr28, i32 noundef %7, i32 noundef %8, ptr noundef %3, i24 %4)
  %9 = shl i32 %.tr2430, 1
  %10 = udiv i32 %9, 3
  %11 = add i32 %10, %.tr28
  %.not = icmp ult i32 %.tr2430, 3
  br i1 %.not, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  ret void
}

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

!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)"}


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