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

; 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 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: 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) #1

; Function Attrs: nounwind
declare double @cos(double noundef) #2

; Function Attrs: nounwind
declare double @sin(double noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @drawTree(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, i24 %6) #3 {
  %8 = alloca %struct.PPMPixel, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i24, align 4
  %18 = alloca i24, align 4
  %19 = alloca i24, align 4
  store i24 %6, ptr %8, align 1
  store i32 %0, ptr %9, align 4, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !5
  store i32 %4, ptr %13, align 4, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !9
  %20 = load i32, ptr %13, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %7
  br label %74

23:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = sitofp i32 %25 to double
  %27 = fmul double %26, 0x400921FB54442D18
  %28 = fdiv double %27, 1.800000e+02
  %29 = call double @cos(double noundef %28) #4
  %30 = load i32, ptr %13, align 4, !tbaa !5
  %31 = uitofp i32 %30 to double
  %32 = fmul double %29, %31
  %33 = fmul double %32, 1.000000e+01
  %34 = fptosi double %33 to i32
  %35 = sub nsw i32 %24, %34
  store i32 %35, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !5
  %38 = sitofp i32 %37 to double
  %39 = fmul double %38, 0x400921FB54442D18
  %40 = fdiv double %39, 1.800000e+02
  %41 = call double @sin(double noundef %40) #4
  %42 = load i32, ptr %13, align 4, !tbaa !5
  %43 = uitofp i32 %42 to double
  %44 = fmul double %41, %43
  %45 = fmul double %44, 1.000000e+01
  %46 = fptosi double %45 to i32
  %47 = sub nsw i32 %36, %46
  store i32 %47, ptr %16, align 4, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = load i32, ptr %15, align 4, !tbaa !5
  %51 = load i32, ptr %16, align 4, !tbaa !5
  %52 = load ptr, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 1 %8, i64 3, i1 false)
  %53 = load i24, ptr %17, align 4
  call void @drawLine(i32 noundef %48, i32 noundef %49, i32 noundef %50, i32 noundef %51, ptr noundef %52, i24 %53)
  %54 = load i32, ptr %15, align 4, !tbaa !5
  %55 = load i32, ptr %16, align 4, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = load i32, ptr %12, align 4, !tbaa !5
  %58 = sub nsw i32 %56, %57
  %59 = load i32, ptr %12, align 4, !tbaa !5
  %60 = load i32, ptr %13, align 4, !tbaa !5
  %61 = sub i32 %60, 1
  %62 = load ptr, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 1 %8, i64 3, i1 false)
  %63 = load i24, ptr %18, align 4
  call void @drawTree(i32 noundef %54, i32 noundef %55, i32 noundef %58, i32 noundef %59, i32 noundef %61, ptr noundef %62, i24 %63)
  %64 = load i32, ptr %15, align 4, !tbaa !5
  %65 = load i32, ptr %16, align 4, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = add nsw i32 %66, %67
  %69 = load i32, ptr %12, align 4, !tbaa !5
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = sub i32 %70, 1
  %72 = load ptr, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 1 %8, i64 3, i1 false)
  %73 = load i24, ptr %19, align 4
  call void @drawTree(i32 noundef %64, i32 noundef %65, i32 noundef %68, i32 noundef %69, i32 noundef %71, ptr noundef %72, i24 %73)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %74

74:                                               ; preds = %23, %22
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"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: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #0

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

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

tailrecurse:                                      ; preds = %7, %tailrecurse
  %.tr3541 = phi i32 [ %24, %tailrecurse ], [ %4, %7 ]
  %.tr3340 = phi i32 [ %25, %tailrecurse ], [ %2, %7 ]
  %.tr3239 = phi i32 [ %22, %tailrecurse ], [ %1, %7 ]
  %.tr38 = phi i32 [ %17, %tailrecurse ], [ %0, %7 ]
  %9 = sitofp i32 %.tr3340 to double
  %10 = fmul double %9, 0x400921FB54442D18
  %11 = fdiv double %10, 1.800000e+02
  %12 = tail call double @cos(double noundef %11) #2
  %13 = uitofp i32 %.tr3541 to double
  %14 = fmul double %12, %13
  %15 = fmul double %14, 1.000000e+01
  %16 = fptosi double %15 to i32
  %17 = sub nsw i32 %.tr38, %16
  %18 = tail call double @sin(double noundef %11) #2
  %19 = fmul double %18, %13
  %20 = fmul double %19, 1.000000e+01
  %21 = fptosi double %20 to i32
  %22 = sub nsw i32 %.tr3239, %21
  tail call void @drawLine(i32 noundef %.tr38, i32 noundef %.tr3239, i32 noundef %17, i32 noundef %22, ptr noundef %5, i24 %6)
  %23 = sub nsw i32 %.tr3340, %3
  %24 = add i32 %.tr3541, -1
  tail call void @drawTree(i32 noundef %17, i32 noundef %22, i32 noundef %23, i32 noundef %3, i32 noundef %24, ptr noundef %5, i24 %6)
  %25 = add nsw i32 %.tr3340, %3
  %26 = icmp eq i32 %24, 0
  br i1 %26, label %tailrecurse._crit_edge, label %tailrecurse

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

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 = { 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)"}


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