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

; 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 uwtable
declare dso_local void @putPixel(i32 noundef, i32 noundef, ptr noundef, i24) #2

; Function Attrs: nounwind uwtable
define dso_local void @drawLine(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i24 %5) #2 {
  %7 = alloca %struct.PPMPixel, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca i24, align 4
  store i24 %5, ptr %7, align 1
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  store i32 %24, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = sub nsw i32 %25, %26
  store i32 %27, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %28 = load i32, ptr %13, align 4, !tbaa !5
  %29 = call i32 @llvm.abs.i32(i32 %28, i1 true)
  %30 = load i32, ptr %14, align 4, !tbaa !5
  %31 = call i32 @llvm.abs.i32(i32 %30, i1 true)
  %32 = icmp sgt i32 %29, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %6
  %34 = load i32, ptr %13, align 4, !tbaa !5
  %35 = call i32 @llvm.abs.i32(i32 %34, i1 true)
  br label %39

36:                                               ; preds = %6
  %37 = load i32, ptr %14, align 4, !tbaa !5
  %38 = call i32 @llvm.abs.i32(i32 %37, i1 true)
  br label %39

39:                                               ; preds = %36, %33
  %40 = phi i32 [ %35, %33 ], [ %38, %36 ]
  store i32 %40, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %41 = load i32, ptr %13, align 4, !tbaa !5
  %42 = sitofp i32 %41 to double
  %43 = load i32, ptr %15, align 4, !tbaa !5
  %44 = uitofp i32 %43 to double
  %45 = fdiv double %42, %44
  store double %45, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %46 = load i32, ptr %14, align 4, !tbaa !5
  %47 = sitofp i32 %46 to double
  %48 = load i32, ptr %15, align 4, !tbaa !5
  %49 = uitofp i32 %48 to double
  %50 = fdiv double %47, %49
  store double %50, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sitofp i32 %51 to double
  store double %52, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = sitofp i32 %53 to double
  store double %54, ptr %20, align 8, !tbaa !11
  store i32 0, ptr %16, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %66, %39
  %56 = load i32, ptr %16, align 4, !tbaa !5
  %57 = load i32, ptr %15, align 4, !tbaa !5
  %58 = icmp ule i32 %56, %57
  br i1 %58, label %59, label %75

59:                                               ; preds = %55
  %60 = load double, ptr %19, align 8, !tbaa !11
  %61 = fptosi double %60 to i32
  %62 = load double, ptr %20, align 8, !tbaa !11
  %63 = fptosi double %62 to i32
  %64 = load ptr, ptr %12, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %21, ptr align 1 %7, i64 3, i1 false)
  %65 = load i24, ptr %21, align 4
  call void @putPixel(i32 noundef %61, i32 noundef %63, ptr noundef %64, i24 %65)
  br label %66

66:                                               ; preds = %59
  %67 = load i32, ptr %16, align 4, !tbaa !5
  %68 = add i32 %67, 1
  store i32 %68, ptr %16, align 4, !tbaa !5
  %69 = load double, ptr %17, align 8, !tbaa !11
  %70 = load double, ptr %19, align 8, !tbaa !11
  %71 = fadd double %70, %69
  store double %71, ptr %19, align 8, !tbaa !11
  %72 = load double, ptr %18, align 8, !tbaa !11
  %73 = load double, ptr %20, align 8, !tbaa !11
  %74 = fadd double %73, %72
  store double %74, ptr %20, align 8, !tbaa !11
  br label %55, !llvm.loop !13

75:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
define dso_local void @drawLine(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i24 %5) local_unnamed_addr #0 {
  %7 = insertelement <2 x i32> poison, i32 %3, i64 0
  %8 = insertelement <2 x i32> %7, i32 %2, i64 1
  %9 = insertelement <2 x i32> poison, i32 %1, i64 0
  %10 = insertelement <2 x i32> %9, i32 %0, i64 1
  %11 = sub <2 x i32> %8, %10
  %12 = extractelement <2 x i32> %11, i64 1
  %13 = tail call i32 @llvm.abs.i32(i32 %12, i1 true)
  %14 = extractelement <2 x i32> %11, i64 0
  %15 = tail call i32 @llvm.abs.i32(i32 %14, i1 true)
  %. = tail call i32 @llvm.umax.i32(i32 %13, i32 %15)
  %16 = uitofp nneg i32 %. to double
  %17 = sitofp <2 x i32> %11 to <2 x double>
  %18 = insertelement <2 x double> poison, double %16, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = fdiv <2 x double> %17, %19
  %21 = sitofp <2 x i32> %10 to <2 x double>
  %smax = tail call i32 @llvm.abs.i32(i32 %14, i1 false)
  %smax31 = tail call i32 @llvm.abs.i32(i32 %12, i1 false)
  %umax = tail call i32 @llvm.umax.i32(i32 %smax, i32 %smax31)
  br label %22

22:                                               ; preds = %6, %22
  %.030 = phi i32 [ 0, %6 ], [ %28, %22 ]
  %23 = phi <2 x double> [ %21, %6 ], [ %29, %22 ]
  %24 = extractelement <2 x double> %23, i64 1
  %25 = fptosi double %24 to i32
  %26 = extractelement <2 x double> %23, i64 0
  %27 = fptosi double %26 to i32
  tail call void @putPixel(i32 noundef %25, i32 noundef %27, ptr noundef %4, i24 %5)
  %28 = add i32 %.030, 1
  %29 = fadd <2 x double> %20, %23
  %exitcond.not = icmp eq i32 %.030, %umax
  br i1 %exitcond.not, label %30, label %22, !llvm.loop !5

30:                                               ; preds = %22
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass