; LLVM IR from casensiom/fast-image-processing :: src (edges)

; 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.SImage = type { i32, i32, i32, i32, ptr }

@.str.38 = external hidden unnamed_addr constant [47 x i8], align 1

; 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @draw2(ptr noundef %0, float noundef %1, float noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !11
  store i32 0, ptr %9, align 4, !tbaa !11
  store i32 0, ptr %8, align 4, !tbaa !11
  store i32 0, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.SImage, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !13
  store i32 %15, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SImage, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !15
  store i32 %18, ptr %12, align 4, !tbaa !11
  %19 = load float, ptr %5, align 4, !tbaa !9
  %20 = fpext float %19 to double
  %21 = fcmp oge double %20, 0x3FE921FB54442D18
  br i1 %21, label %22, label %70

22:                                               ; preds = %3
  %23 = load float, ptr %5, align 4, !tbaa !9
  %24 = fpext float %23 to double
  %25 = fcmp ole double %24, 0x4002D97C7F3321D2
  br i1 %25, label %26, label %70

26:                                               ; preds = %22
  store i32 0, ptr %7, align 4, !tbaa !11
  %27 = load float, ptr %6, align 4, !tbaa !9
  %28 = fpext float %27 to double
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = udiv i32 %30, 2
  %32 = sub i32 %29, %31
  %33 = uitofp i32 %32 to double
  %34 = load float, ptr %5, align 4, !tbaa !9
  %35 = fpext float %34 to double
  %36 = call double @cos(double noundef %35) #5
  %37 = fneg double %33
  %38 = call double @llvm.fmuladd.f64(double %37, double %36, double %28)
  %39 = load float, ptr %5, align 4, !tbaa !9
  %40 = fpext float %39 to double
  %41 = call double @sin(double noundef %40) #5
  %42 = fdiv double %38, %41
  %43 = load i32, ptr %12, align 4, !tbaa !11
  %44 = udiv i32 %43, 2
  %45 = uitofp i32 %44 to double
  %46 = fadd double %42, %45
  %47 = fptosi double %46 to i32
  store i32 %47, ptr %8, align 4, !tbaa !11
  %48 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %48, ptr %9, align 4, !tbaa !11
  %49 = load float, ptr %6, align 4, !tbaa !9
  %50 = fpext float %49 to double
  %51 = load i32, ptr %9, align 4, !tbaa !11
  %52 = load i32, ptr %11, align 4, !tbaa !11
  %53 = udiv i32 %52, 2
  %54 = sub i32 %51, %53
  %55 = uitofp i32 %54 to double
  %56 = load float, ptr %5, align 4, !tbaa !9
  %57 = fpext float %56 to double
  %58 = call double @cos(double noundef %57) #5
  %59 = fneg double %55
  %60 = call double @llvm.fmuladd.f64(double %59, double %58, double %50)
  %61 = load float, ptr %5, align 4, !tbaa !9
  %62 = fpext float %61 to double
  %63 = call double @sin(double noundef %62) #5
  %64 = fdiv double %60, %63
  %65 = load i32, ptr %12, align 4, !tbaa !11
  %66 = udiv i32 %65, 2
  %67 = uitofp i32 %66 to double
  %68 = fadd double %64, %67
  %69 = fptosi double %68 to i32
  store i32 %69, ptr %10, align 4, !tbaa !11
  br label %114

70:                                               ; preds = %22, %3
  store i32 0, ptr %8, align 4, !tbaa !11
  %71 = load float, ptr %6, align 4, !tbaa !9
  %72 = fpext float %71 to double
  %73 = load i32, ptr %8, align 4, !tbaa !11
  %74 = load i32, ptr %12, align 4, !tbaa !11
  %75 = udiv i32 %74, 2
  %76 = sub i32 %73, %75
  %77 = uitofp i32 %76 to double
  %78 = load float, ptr %5, align 4, !tbaa !9
  %79 = fpext float %78 to double
  %80 = call double @sin(double noundef %79) #5
  %81 = fneg double %77
  %82 = call double @llvm.fmuladd.f64(double %81, double %80, double %72)
  %83 = load float, ptr %5, align 4, !tbaa !9
  %84 = fpext float %83 to double
  %85 = call double @cos(double noundef %84) #5
  %86 = fdiv double %82, %85
  %87 = load i32, ptr %11, align 4, !tbaa !11
  %88 = udiv i32 %87, 2
  %89 = uitofp i32 %88 to double
  %90 = fadd double %86, %89
  %91 = fptosi double %90 to i32
  store i32 %91, ptr %7, align 4, !tbaa !11
  %92 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %92, ptr %10, align 4, !tbaa !11
  %93 = load float, ptr %6, align 4, !tbaa !9
  %94 = fpext float %93 to double
  %95 = load i32, ptr %10, align 4, !tbaa !11
  %96 = load i32, ptr %12, align 4, !tbaa !11
  %97 = udiv i32 %96, 2
  %98 = sub i32 %95, %97
  %99 = uitofp i32 %98 to double
  %100 = load float, ptr %5, align 4, !tbaa !9
  %101 = fpext float %100 to double
  %102 = call double @sin(double noundef %101) #5
  %103 = fneg double %99
  %104 = call double @llvm.fmuladd.f64(double %103, double %102, double %94)
  %105 = load float, ptr %5, align 4, !tbaa !9
  %106 = fpext float %105 to double
  %107 = call double @cos(double noundef %106) #5
  %108 = fdiv double %104, %107
  %109 = load i32, ptr %11, align 4, !tbaa !11
  %110 = udiv i32 %109, 2
  %111 = uitofp i32 %110 to double
  %112 = fadd double %108, %111
  %113 = fptosi double %112 to i32
  store i32 %113, ptr %9, align 4, !tbaa !11
  br label %114

114:                                              ; preds = %70, %26
  %115 = load float, ptr %5, align 4, !tbaa !9
  %116 = fpext float %115 to double
  %117 = load float, ptr %6, align 4, !tbaa !9
  %118 = fpext float %117 to double
  %119 = load i32, ptr %7, align 4, !tbaa !11
  %120 = load i32, ptr %8, align 4, !tbaa !11
  %121 = load i32, ptr %9, align 4, !tbaa !11
  %122 = load i32, ptr %10, align 4, !tbaa !11
  %123 = call i32 (ptr, ...) @printf(ptr noundef @.str.38, double noundef %116, double noundef %118, i32 noundef %119, i32 noundef %120, i32 noundef %121, i32 noundef %122)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"SImage", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !6, i64 16}
!15 = !{!14, !12, i64 4}


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

@.str.38 = external hidden unnamed_addr constant [47 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @draw2(ptr nocapture noundef readonly %0, float noundef %1, float noundef %2) local_unnamed_addr #1 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = fpext float %1 to double
  %8 = fcmp ult double %7, 0x3FE921FB54442D18
  %9 = fcmp ugt double %7, 0x4002D97C7F3321D2
  %or.cond = or i1 %8, %9
  %10 = fpext float %2 to double
  br i1 %or.cond, label %33, label %11

11:                                               ; preds = %3
  %12 = lshr i32 %4, 1
  %13 = sub nsw i32 0, %12
  %14 = uitofp i32 %13 to double
  %15 = tail call double @cos(double noundef %7) #4
  %16 = fneg double %14
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %15, double %10)
  %18 = tail call double @sin(double noundef %7) #4
  %19 = fdiv double %17, %18
  %20 = lshr i32 %6, 1
  %21 = uitofp nneg i32 %20 to double
  %22 = fadd double %19, %21
  %23 = fptosi double %22 to i32
  %24 = sub i32 %4, %12
  %25 = uitofp i32 %24 to double
  %26 = tail call double @cos(double noundef %7) #4
  %27 = fneg double %25
  %28 = tail call double @llvm.fmuladd.f64(double %27, double %26, double %10)
  %29 = tail call double @sin(double noundef %7) #4
  %30 = fdiv double %28, %29
  %31 = fadd double %30, %21
  %32 = fptosi double %31 to i32
  br label %55

33:                                               ; preds = %3
  %34 = lshr i32 %6, 1
  %35 = sub nsw i32 0, %34
  %36 = uitofp i32 %35 to double
  %37 = tail call double @sin(double noundef %7) #4
  %38 = fneg double %36
  %39 = tail call double @llvm.fmuladd.f64(double %38, double %37, double %10)
  %40 = tail call double @cos(double noundef %7) #4
  %41 = fdiv double %39, %40
  %42 = lshr i32 %4, 1
  %43 = uitofp nneg i32 %42 to double
  %44 = fadd double %41, %43
  %45 = fptosi double %44 to i32
  %46 = sub i32 %6, %34
  %47 = uitofp i32 %46 to double
  %48 = tail call double @sin(double noundef %7) #4
  %49 = fneg double %47
  %50 = tail call double @llvm.fmuladd.f64(double %49, double %48, double %10)
  %51 = tail call double @cos(double noundef %7) #4
  %52 = fdiv double %50, %51
  %53 = fadd double %52, %43
  %54 = fptosi double %53 to i32
  br label %55

55:                                               ; preds = %33, %11
  %.037 = phi i32 [ %54, %33 ], [ %4, %11 ]
  %.036 = phi i32 [ %6, %33 ], [ %32, %11 ]
  %.035 = phi i32 [ 0, %33 ], [ %23, %11 ]
  %.0 = phi i32 [ %45, %33 ], [ 0, %11 ]
  %56 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.38, double noundef %7, double noundef %10, i32 noundef %.0, i32 noundef %.035, i32 noundef %.037, i32 noundef %.036)
  ret void
}

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

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

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

attributes #0 = { nofree 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 #1 = { nofree 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 = { 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 #3 = { mustprogress 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, !7, i64 0}
!6 = !{!"SImage", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!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}


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