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

; 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.PPMImage = type { i32, i32, ptr }
%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: nounwind uwtable
declare dso_local double @truncateRGB(double noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind uwtable
define dso_local void @sepiaFilter(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %147, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.PPMImage, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.PPMImage, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = mul i32 %11, %14
  %16 = icmp ult i32 %8, %15
  br i1 %16, label %17, label %150

17:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.PPMImage, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds %struct.PPMPixel, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.PPMPixel, ptr %23, i32 0, i32 0
  %25 = load i8, ptr %24, align 1, !tbaa !15
  %26 = zext i8 %25 to i32
  %27 = sitofp i32 %26 to double
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PPMImage, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds %struct.PPMPixel, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.PPMPixel, ptr %33, i32 0, i32 1
  %35 = load i8, ptr %34, align 1, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = sitofp i32 %36 to double
  %38 = fmul double 7.690000e-01, %37
  %39 = call double @llvm.fmuladd.f64(double 3.930000e-01, double %27, double %38)
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.PPMImage, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %struct.PPMPixel, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.PPMPixel, ptr %45, i32 0, i32 2
  %47 = load i8, ptr %46, align 1, !tbaa !18
  %48 = zext i8 %47 to i32
  %49 = sitofp i32 %48 to double
  %50 = call double @llvm.fmuladd.f64(double 1.890000e-01, double %49, double %39)
  store double %50, ptr %4, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.PPMImage, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load i32, ptr %3, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds %struct.PPMPixel, ptr %53, i64 %55
  %57 = getelementptr inbounds %struct.PPMPixel, ptr %56, i32 0, i32 0
  %58 = load i8, ptr %57, align 1, !tbaa !15
  %59 = zext i8 %58 to i32
  %60 = sitofp i32 %59 to double
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.PPMImage, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = load i32, ptr %3, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds %struct.PPMPixel, ptr %63, i64 %65
  %67 = getelementptr inbounds %struct.PPMPixel, ptr %66, i32 0, i32 1
  %68 = load i8, ptr %67, align 1, !tbaa !17
  %69 = zext i8 %68 to i32
  %70 = sitofp i32 %69 to double
  %71 = fmul double 6.860000e-01, %70
  %72 = call double @llvm.fmuladd.f64(double 3.490000e-01, double %60, double %71)
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.PPMImage, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !14
  %76 = load i32, ptr %3, align 4, !tbaa !9
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds %struct.PPMPixel, ptr %75, i64 %77
  %79 = getelementptr inbounds %struct.PPMPixel, ptr %78, i32 0, i32 2
  %80 = load i8, ptr %79, align 1, !tbaa !18
  %81 = zext i8 %80 to i32
  %82 = sitofp i32 %81 to double
  %83 = call double @llvm.fmuladd.f64(double 1.680000e-01, double %82, double %72)
  store double %83, ptr %5, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.PPMImage, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !14
  %87 = load i32, ptr %3, align 4, !tbaa !9
  %88 = zext i32 %87 to i64
  %89 = getelementptr inbounds %struct.PPMPixel, ptr %86, i64 %88
  %90 = getelementptr inbounds %struct.PPMPixel, ptr %89, i32 0, i32 0
  %91 = load i8, ptr %90, align 1, !tbaa !15
  %92 = zext i8 %91 to i32
  %93 = sitofp i32 %92 to double
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.PPMImage, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !14
  %97 = load i32, ptr %3, align 4, !tbaa !9
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds %struct.PPMPixel, ptr %96, i64 %98
  %100 = getelementptr inbounds %struct.PPMPixel, ptr %99, i32 0, i32 1
  %101 = load i8, ptr %100, align 1, !tbaa !17
  %102 = zext i8 %101 to i32
  %103 = sitofp i32 %102 to double
  %104 = fmul double 5.340000e-01, %103
  %105 = call double @llvm.fmuladd.f64(double 2.720000e-01, double %93, double %104)
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.PPMImage, ptr %106, i32 0, i32 2
  %108 = load ptr, ptr %107, align 8, !tbaa !14
  %109 = load i32, ptr %3, align 4, !tbaa !9
  %110 = zext i32 %109 to i64
  %111 = getelementptr inbounds %struct.PPMPixel, ptr %108, i64 %110
  %112 = getelementptr inbounds %struct.PPMPixel, ptr %111, i32 0, i32 2
  %113 = load i8, ptr %112, align 1, !tbaa !18
  %114 = zext i8 %113 to i32
  %115 = sitofp i32 %114 to double
  %116 = call double @llvm.fmuladd.f64(double 1.310000e-01, double %115, double %105)
  store double %116, ptr %6, align 8, !tbaa !19
  %117 = load double, ptr %4, align 8, !tbaa !19
  %118 = call double @truncateRGB(double noundef %117)
  %119 = fptoui double %118 to i8
  %120 = load ptr, ptr %2, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.PPMImage, ptr %120, i32 0, i32 2
  %122 = load ptr, ptr %121, align 8, !tbaa !14
  %123 = load i32, ptr %3, align 4, !tbaa !9
  %124 = zext i32 %123 to i64
  %125 = getelementptr inbounds %struct.PPMPixel, ptr %122, i64 %124
  %126 = getelementptr inbounds %struct.PPMPixel, ptr %125, i32 0, i32 0
  store i8 %119, ptr %126, align 1, !tbaa !15
  %127 = load double, ptr %5, align 8, !tbaa !19
  %128 = call double @truncateRGB(double noundef %127)
  %129 = fptoui double %128 to i8
  %130 = load ptr, ptr %2, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.PPMImage, ptr %130, i32 0, i32 2
  %132 = load ptr, ptr %131, align 8, !tbaa !14
  %133 = load i32, ptr %3, align 4, !tbaa !9
  %134 = zext i32 %133 to i64
  %135 = getelementptr inbounds %struct.PPMPixel, ptr %132, i64 %134
  %136 = getelementptr inbounds %struct.PPMPixel, ptr %135, i32 0, i32 1
  store i8 %129, ptr %136, align 1, !tbaa !17
  %137 = load double, ptr %6, align 8, !tbaa !19
  %138 = call double @truncateRGB(double noundef %137)
  %139 = fptoui double %138 to i8
  %140 = load ptr, ptr %2, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.PPMImage, ptr %140, i32 0, i32 2
  %142 = load ptr, ptr %141, align 8, !tbaa !14
  %143 = load i32, ptr %3, align 4, !tbaa !9
  %144 = zext i32 %143 to i64
  %145 = getelementptr inbounds %struct.PPMPixel, ptr %142, i64 %144
  %146 = getelementptr inbounds %struct.PPMPixel, ptr %145, i32 0, i32 2
  store i8 %139, ptr %146, align 1, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %147

147:                                              ; preds = %17
  %148 = load i32, ptr %3, align 4, !tbaa !9
  %149 = add i32 %148, 1
  store i32 %149, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !21

150:                                              ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync 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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"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 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!17 = !{!16, !7, i64 1}
!18 = !{!16, !7, i64 2}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.PPMPixel = type { i8, i8, i8 }

; Function Attrs: nounwind uwtable
declare dso_local double @truncateRGB(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local void @sepiaFilter(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !11
  %5 = mul i32 %4, %3
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %6, align 8, !tbaa !12
  br label %7

7:                                                ; preds = %.lr.ph, %7
  %8 = phi ptr [ %.pre, %.lr.ph ], [ %37, %7 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %7 ]
  %9 = getelementptr inbounds %struct.PPMPixel, ptr %8, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !13
  %11 = uitofp i8 %10 to double
  %12 = getelementptr inbounds i8, ptr %9, i64 1
  %13 = load i8, ptr %12, align 1, !tbaa !15
  %14 = uitofp i8 %13 to double
  %15 = fmul double %14, 7.690000e-01
  %16 = tail call double @llvm.fmuladd.f64(double %11, double 3.930000e-01, double %15)
  %17 = getelementptr inbounds i8, ptr %9, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !16
  %19 = uitofp i8 %18 to double
  %20 = tail call double @llvm.fmuladd.f64(double %19, double 1.890000e-01, double %16)
  %21 = fmul double %14, 6.860000e-01
  %22 = tail call double @llvm.fmuladd.f64(double %11, double 3.490000e-01, double %21)
  %23 = tail call double @llvm.fmuladd.f64(double %19, double 1.680000e-01, double %22)
  %24 = fmul double %14, 5.340000e-01
  %25 = tail call double @llvm.fmuladd.f64(double %11, double 2.720000e-01, double %24)
  %26 = tail call double @llvm.fmuladd.f64(double %19, double 1.310000e-01, double %25)
  %27 = tail call double @truncateRGB(double noundef %20)
  %28 = fptoui double %27 to i8
  %29 = load ptr, ptr %6, align 8, !tbaa !12
  %30 = getelementptr inbounds %struct.PPMPixel, ptr %29, i64 %indvars.iv
  store i8 %28, ptr %30, align 1, !tbaa !13
  %31 = tail call double @truncateRGB(double noundef %23)
  %32 = fptoui double %31 to i8
  %33 = load ptr, ptr %6, align 8, !tbaa !12
  %34 = getelementptr inbounds %struct.PPMPixel, ptr %33, i64 %indvars.iv, i32 1
  store i8 %32, ptr %34, align 1, !tbaa !15
  %35 = tail call double @truncateRGB(double noundef %26)
  %36 = fptoui double %35 to i8
  %37 = load ptr, ptr %6, align 8, !tbaa !12
  %38 = getelementptr inbounds %struct.PPMPixel, ptr %37, i64 %indvars.iv, i32 2
  store i8 %36, ptr %38, align 1, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i32, ptr %0, align 8, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !11
  %41 = mul i32 %40, %39
  %42 = zext i32 %41 to i64
  %43 = icmp ult i64 %indvars.iv.next, %42
  br i1 %43, label %7, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %7, %1
  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" }
attributes #1 = { mustprogress 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 = !{!6, !7, i64 0}
!6 = !{!"", !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 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !8, i64 0}
!14 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2}
!15 = !{!14, !8, i64 1}
!16 = !{!14, !8, i64 2}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass