; LLVM IR from Sentdex/NNfSiX :: C (p005-ReLU-Activation)

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

@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local double @uniform_distribution(double noundef, double noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @spiral_data(i32 noundef %0, i32 noundef %1, ptr noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = mul i64 8, %14
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = mul i64 %15, %17
  %19 = mul i64 %18, 2
  %20 = call noalias ptr @malloc(i64 noundef %19) #6
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.spiral_data_t, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.spiral_data_t, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %29

27:                                               ; preds = %3
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %124

29:                                               ; preds = %3
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = mul i64 8, %31
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = mul i64 %32, %34
  %36 = call noalias ptr @malloc(i64 noundef %35) #6
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.spiral_data_t, ptr %37, i32 0, i32 1
  store ptr %36, ptr %38, align 8, !tbaa !13
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.spiral_data_t, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %45

43:                                               ; preds = %29
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %124

45:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %120, %45
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %123

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  store double 0.000000e+00, ptr %10, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = mul nsw i32 %51, 4
  %53 = sitofp i32 %52 to double
  store double %53, ptr %11, align 8, !tbaa !14
  br label %54

54:                                               ; preds = %66, %50
  %55 = load double, ptr %10, align 8, !tbaa !14
  %56 = fcmp ole double %55, 1.000000e+00
  br i1 %56, label %57, label %64

57:                                               ; preds = %54
  %58 = load double, ptr %11, align 8, !tbaa !14
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = mul nsw i32 %60, 4
  %62 = sitofp i32 %61 to double
  %63 = fcmp ole double %58, %62
  br label %64

64:                                               ; preds = %57, %54
  %65 = phi i1 [ false, %54 ], [ %63, %57 ]
  br i1 %65, label %66, label %119

66:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %67 = load double, ptr %11, align 8, !tbaa !14
  %68 = call double @uniform_distribution(double noundef -1.000000e+00, double noundef 1.000000e+00)
  %69 = call double @llvm.fmuladd.f64(double %68, double 2.000000e-01, double %67)
  store double %69, ptr %12, align 8, !tbaa !14
  %70 = load double, ptr %10, align 8, !tbaa !14
  %71 = load double, ptr %12, align 8, !tbaa !14
  %72 = fmul double %71, 2.500000e+00
  %73 = call double @sin(double noundef %72) #7
  %74 = fmul double %70, %73
  %75 = load ptr, ptr %6, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.spiral_data_t, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !11
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  store double %74, ptr %80, align 8, !tbaa !14
  %81 = load double, ptr %10, align 8, !tbaa !14
  %82 = load double, ptr %12, align 8, !tbaa !14
  %83 = fmul double %82, 2.500000e+00
  %84 = call double @cos(double noundef %83) #7
  %85 = fmul double %81, %84
  %86 = load ptr, ptr %6, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.spiral_data_t, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !11
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds double, ptr %88, i64 %91
  store double %85, ptr %92, align 8, !tbaa !14
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = sitofp i32 %93 to double
  %95 = load ptr, ptr %6, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.spiral_data_t, ptr %95, i32 0, i32 1
  %97 = load ptr, ptr %96, align 8, !tbaa !13
  %98 = load i32, ptr %8, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds double, ptr %97, i64 %99
  store double %94, ptr %100, align 8, !tbaa !14
  %101 = load i32, ptr %4, align 4, !tbaa !5
  %102 = sub nsw i32 %101, 1
  %103 = sitofp i32 %102 to float
  %104 = fdiv float 1.000000e+00, %103
  %105 = fpext float %104 to double
  %106 = load double, ptr %10, align 8, !tbaa !14
  %107 = fadd double %106, %105
  store double %107, ptr %10, align 8, !tbaa !14
  %108 = load i32, ptr %4, align 4, !tbaa !5
  %109 = sub nsw i32 %108, 1
  %110 = sitofp i32 %109 to float
  %111 = fdiv float 4.000000e+00, %110
  %112 = fpext float %111 to double
  %113 = load double, ptr %11, align 8, !tbaa !14
  %114 = fadd double %113, %112
  store double %114, ptr %11, align 8, !tbaa !14
  %115 = load i32, ptr %8, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %8, align 4, !tbaa !5
  %117 = load i32, ptr %7, align 4, !tbaa !5
  %118 = add nsw i32 %117, 2
  store i32 %118, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %54, !llvm.loop !16

119:                                              ; preds = %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %120

120:                                              ; preds = %119
  %121 = load i32, ptr %9, align 4, !tbaa !5
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %9, align 4, !tbaa !5
  br label %46, !llvm.loop !18

123:                                              ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %124

124:                                              ; preds = %123, %43, %27
  ret void
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind allocsize(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 = { "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 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 #5 = { 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 #6 = { nounwind allocsize(0) }
attributes #7 = { 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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local double @uniform_distribution(double noundef, double noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @spiral_data(i32 noundef %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #3 {
  %4 = sext i32 %0 to i64
  %5 = shl nsw i64 %4, 3
  %6 = sext i32 %1 to i64
  %7 = mul i64 %5, %6
  %8 = shl i64 %7, 1
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #5
  store ptr %9, ptr %2, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %.loopexit.sink.split, label %11

11:                                               ; preds = %3
  %12 = tail call noalias ptr @malloc(i64 noundef %7) #5
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !10
  %14 = icmp eq ptr %12, null
  br i1 %14, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %11
  %15 = icmp sgt i32 %1, 0
  br i1 %15, label %.lr.ph45, label %.loopexit

.lr.ph45:                                         ; preds = %.preheader
  %16 = add nsw i32 %0, -1
  %17 = sitofp i32 %16 to float
  %18 = insertelement <2 x float> poison, float %17, i64 0
  %19 = shufflevector <2 x float> %18, <2 x float> poison, <2 x i32> zeroinitializer
  %20 = fdiv <2 x float> <float 4.000000e+00, float 1.000000e+00>, %19
  %21 = fpext <2 x float> %20 to <2 x double>
  br label %22

22:                                               ; preds = %.lr.ph45, %.critedge
  %.044 = phi i32 [ 0, %.lr.ph45 ], [ %.1.lcssa, %.critedge ]
  %.03443 = phi i32 [ 0, %.lr.ph45 ], [ %57, %.critedge ]
  %.03542 = phi i32 [ 0, %.lr.ph45 ], [ %.136.lcssa, %.critedge ]
  %23 = shl i32 %.03443, 2
  %24 = uitofp nneg i32 %23 to double
  %25 = add i32 %23, 4
  %26 = sitofp i32 %25 to double
  %27 = fcmp ugt double %24, %26
  br i1 %27, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %22
  %28 = uitofp nneg i32 %.03443 to double
  %29 = sext i32 %.044 to i64
  %30 = sext i32 %.03542 to i64
  %31 = insertelement <2 x double> <double poison, double 0.000000e+00>, double %24, i64 0
  br label %32

32:                                               ; preds = %.lr.ph, %32
  %indvars.iv47 = phi i64 [ %30, %.lr.ph ], [ %indvars.iv.next48, %32 ]
  %indvars.iv = phi i64 [ %29, %.lr.ph ], [ %indvars.iv.next, %32 ]
  %33 = phi <2 x double> [ %31, %.lr.ph ], [ %50, %32 ]
  %34 = tail call double @uniform_distribution(double noundef -1.000000e+00, double noundef 1.000000e+00)
  %35 = extractelement <2 x double> %33, i64 0
  %36 = tail call double @llvm.fmuladd.f64(double %34, double 2.000000e-01, double %35)
  %37 = fmul double %36, 2.500000e+00
  %38 = tail call double @sin(double noundef %37) #6
  %39 = extractelement <2 x double> %33, i64 1
  %40 = fmul double %39, %38
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds double, ptr %41, i64 %indvars.iv
  store double %40, ptr %42, align 8, !tbaa !11
  %43 = tail call double @cos(double noundef %37) #6
  %44 = fmul double %39, %43
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr double, ptr %45, i64 %indvars.iv
  %47 = getelementptr i8, ptr %46, i64 8
  store double %44, ptr %47, align 8, !tbaa !11
  %48 = load ptr, ptr %13, align 8, !tbaa !10
  %49 = getelementptr inbounds double, ptr %48, i64 %indvars.iv47
  store double %28, ptr %49, align 8, !tbaa !11
  %50 = fadd <2 x double> %33, %21
  %indvars.iv.next48 = add nsw i64 %indvars.iv47, 1
  %indvars.iv.next = add nsw i64 %indvars.iv, 2
  %51 = extractelement <2 x double> %50, i64 1
  %52 = fcmp ugt double %51, 1.000000e+00
  %53 = extractelement <2 x double> %50, i64 0
  %54 = fcmp ugt double %53, %26
  %or.cond = select i1 %52, i1 true, i1 %54
  br i1 %or.cond, label %.critedge.loopexit, label %32, !llvm.loop !13

.critedge.loopexit:                               ; preds = %32
  %55 = trunc nsw i64 %indvars.iv.next48 to i32
  %56 = trunc nsw i64 %indvars.iv.next to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %22
  %.136.lcssa = phi i32 [ %.03542, %22 ], [ %55, %.critedge.loopexit ]
  %.1.lcssa = phi i32 [ %.044, %22 ], [ %56, %.critedge.loopexit ]
  %57 = add nuw nsw i32 %.03443, 1
  %exitcond.not = icmp eq i32 %57, %1
  br i1 %exitcond.not, label %.loopexit, label %22, !llvm.loop !15

.loopexit.sink.split:                             ; preds = %11, %3
  %.str.4.sink = phi ptr [ @.str.3, %3 ], [ @.str.4, %11 ]
  %58 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.4.sink)
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %.loopexit.sink.split, %.preheader
  ret void
}

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #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 = { 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 #5 = { nounwind allocsize(0) }
attributes #6 = { 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 = !{!"", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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