; LLVM IR from buresjan/optim_lbm :: nomad/examples/advanced/library/c_api/example1 (example1_c_api)

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @example1_bb(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca double, align 8
  %22 = alloca i32, align 4
  %23 = alloca double, align 8
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  store i8 1, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store double 1.000000e+20, ptr %14, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store double 1.000000e+20, ptr %15, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store double 1.000000e+20, ptr %16, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  store double 0.000000e+00, ptr %17, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  store double 0.000000e+00, ptr %18, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  store double 0.000000e+00, ptr %19, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  store double 1.000000e+00, ptr %20, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  store double 1.000000e+00, ptr %21, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  store i32 0, ptr %22, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %91, %6
  %25 = load i32, ptr %22, align 4, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  br label %94

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = load i32, ptr %22, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %30, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !13
  %35 = call double @cos(double noundef %34) #4
  %36 = call double @pow(double noundef %35, double noundef 4.000000e+00) #4
  %37 = load double, ptr %17, align 8, !tbaa !13
  %38 = fadd double %37, %36
  store double %38, ptr %17, align 8, !tbaa !13
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = load i32, ptr %22, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %39, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !13
  %44 = load double, ptr %18, align 8, !tbaa !13
  %45 = fadd double %44, %43
  store double %45, ptr %18, align 8, !tbaa !13
  %46 = load i32, ptr %22, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = sitofp i32 %47 to double
  %49 = load ptr, ptr %8, align 8, !tbaa !9
  %50 = load i32, ptr %22, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds double, ptr %49, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !13
  %54 = fmul double %48, %53
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = load i32, ptr %22, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !13
  %60 = load double, ptr %19, align 8, !tbaa !13
  %61 = call double @llvm.fmuladd.f64(double %54, double %59, double %60)
  store double %61, ptr %19, align 8, !tbaa !13
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = load i32, ptr %22, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !13
  %67 = call double @cos(double noundef %66) #4
  %68 = call double @pow(double noundef %67, double noundef 2.000000e+00) #4
  %69 = load double, ptr %20, align 8, !tbaa !13
  %70 = fmul double %69, %68
  store double %70, ptr %20, align 8, !tbaa !13
  %71 = load double, ptr %21, align 8, !tbaa !13
  %72 = fcmp une double %71, 0.000000e+00
  br i1 %72, label %73, label %90

73:                                               ; preds = %29
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = load i32, ptr %22, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds double, ptr %74, i64 %76
  %78 = load double, ptr %77, align 8, !tbaa !13
  %79 = fcmp oeq double %78, 0.000000e+00
  br i1 %79, label %80, label %81

80:                                               ; preds = %73
  store double 0.000000e+00, ptr %21, align 8, !tbaa !13
  br label %89

81:                                               ; preds = %73
  %82 = load ptr, ptr %8, align 8, !tbaa !9
  %83 = load i32, ptr %22, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %82, i64 %84
  %86 = load double, ptr %85, align 8, !tbaa !13
  %87 = load double, ptr %21, align 8, !tbaa !13
  %88 = fmul double %87, %86
  store double %88, ptr %21, align 8, !tbaa !13
  br label %89

89:                                               ; preds = %81, %80
  br label %90

90:                                               ; preds = %89, %29
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %22, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %22, align 4, !tbaa !5
  br label %24, !llvm.loop !15

94:                                               ; preds = %28
  %95 = load double, ptr %21, align 8, !tbaa !13
  %96 = fneg double %95
  %97 = fadd double %96, 7.500000e-01
  store double %97, ptr %15, align 8, !tbaa !13
  %98 = load double, ptr %18, align 8, !tbaa !13
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = sitofp i32 %99 to double
  %101 = call double @llvm.fmuladd.f64(double -7.500000e+00, double %100, double %98)
  store double %101, ptr %16, align 8, !tbaa !13
  %102 = load double, ptr %15, align 8, !tbaa !13
  %103 = load double, ptr %16, align 8, !tbaa !13
  %104 = fmul double 1.000000e+01, %103
  %105 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %102, double %104)
  store double %105, ptr %14, align 8, !tbaa !13
  %106 = load double, ptr %19, align 8, !tbaa !13
  %107 = fcmp une double 0.000000e+00, %106
  br i1 %107, label %108, label %118

108:                                              ; preds = %94
  %109 = load double, ptr %17, align 8, !tbaa !13
  %110 = load double, ptr %20, align 8, !tbaa !13
  %111 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %110, double %109)
  %112 = load double, ptr %19, align 8, !tbaa !13
  %113 = call double @sqrt(double noundef %112) #4
  %114 = fdiv double %111, %113
  %115 = call double @llvm.fabs.f64(double %114)
  %116 = load double, ptr %14, align 8, !tbaa !13
  %117 = fsub double %116, %115
  store double %117, ptr %14, align 8, !tbaa !13
  br label %118

118:                                              ; preds = %108, %94
  %119 = load double, ptr %14, align 8, !tbaa !13
  %120 = fmul double %119, 1.000000e-05
  store double %120, ptr %14, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %121 = load double, ptr %14, align 8, !tbaa !13
  %122 = fneg double %121
  %123 = fsub double %122, 2.000000e+03
  store double %123, ptr %23, align 8, !tbaa !13
  %124 = load double, ptr %15, align 8, !tbaa !13
  %125 = load ptr, ptr %10, align 8, !tbaa !9
  %126 = getelementptr inbounds double, ptr %125, i64 0
  store double %124, ptr %126, align 8, !tbaa !13
  %127 = load double, ptr %16, align 8, !tbaa !13
  %128 = load ptr, ptr %10, align 8, !tbaa !9
  %129 = getelementptr inbounds double, ptr %128, i64 1
  store double %127, ptr %129, align 8, !tbaa !13
  %130 = load double, ptr %14, align 8, !tbaa !13
  %131 = load ptr, ptr %10, align 8, !tbaa !9
  %132 = getelementptr inbounds double, ptr %131, i64 2
  store double %130, ptr %132, align 8, !tbaa !13
  %133 = load double, ptr %23, align 8, !tbaa !13
  %134 = load ptr, ptr %10, align 8, !tbaa !9
  %135 = getelementptr inbounds double, ptr %134, i64 3
  store double %133, ptr %135, align 8, !tbaa !13
  %136 = load ptr, ptr %11, align 8, !tbaa !9
  store i8 1, ptr %136, align 1, !tbaa !11
  %137 = load i8, ptr %13, align 1, !tbaa !11, !range !17, !noundef !18
  %138 = trunc i8 %137 to i1
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  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 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  ret i1 %138
}

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

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

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

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

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

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

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

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 = { nocallback nofree nosync 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 = { 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 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{i8 0, i8 2}
!18 = !{}


; 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: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @example1_bb(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef readnone %5) local_unnamed_addr #0 {
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %33, %6
  %.050.lcssa = phi double [ 0.000000e+00, %6 ], [ %18, %33 ]
  %.049.lcssa = phi double [ 0.000000e+00, %6 ], [ %20, %33 ]
  %.048.lcssa = phi double [ 0.000000e+00, %6 ], [ %24, %33 ]
  %.047.lcssa = phi double [ 1.000000e+00, %6 ], [ %26, %33 ]
  %.046.lcssa = phi double [ 1.000000e+00, %6 ], [ %.1, %33 ]
  %8 = fsub double 7.500000e-01, %.046.lcssa
  %9 = sitofp i32 %0 to double
  %10 = tail call double @llvm.fmuladd.f64(double %9, double -7.500000e+00, double %.049.lcssa)
  %11 = fmul double %10, 1.000000e+01
  %12 = tail call double @llvm.fmuladd.f64(double %8, double 1.000000e+01, double %11)
  %13 = fcmp une double %.048.lcssa, 0.000000e+00
  br i1 %13, label %34, label %40

.lr.ph:                                           ; preds = %.lr.ph.preheader, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %33 ]
  %.04657 = phi double [ 1.000000e+00, %.lr.ph.preheader ], [ %.1, %33 ]
  %.04756 = phi double [ 1.000000e+00, %.lr.ph.preheader ], [ %26, %33 ]
  %.04855 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %24, %33 ]
  %.04954 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %20, %33 ]
  %.05053 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %18, %33 ]
  %14 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = tail call double @cos(double noundef %15) #3
  %17 = tail call double @pow(double noundef %16, double noundef 4.000000e+00) #3
  %18 = fadd double %.05053, %17
  %19 = load double, ptr %14, align 8, !tbaa !5
  %20 = fadd double %.04954, %19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = trunc nuw nsw i64 %indvars.iv.next to i32
  %22 = uitofp nneg i32 %21 to double
  %23 = fmul double %19, %22
  %24 = tail call double @llvm.fmuladd.f64(double %23, double %19, double %.04855)
  %25 = tail call double @cos(double noundef %19) #3
  %square = fmul double %25, %25
  %26 = fmul double %.04756, %square
  %27 = fcmp une double %.04657, 0.000000e+00
  br i1 %27, label %28, label %33

28:                                               ; preds = %.lr.ph
  %29 = load double, ptr %14, align 8, !tbaa !5
  %30 = fcmp oeq double %29, 0.000000e+00
  br i1 %30, label %33, label %31

31:                                               ; preds = %28
  %32 = fmul double %.04657, %29
  br label %33

33:                                               ; preds = %28, %.lr.ph, %31
  %.1 = phi double [ %32, %31 ], [ %.04657, %.lr.ph ], [ 0.000000e+00, %28 ]
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

34:                                               ; preds = %._crit_edge
  %35 = tail call double @llvm.fmuladd.f64(double %.047.lcssa, double -2.000000e+00, double %.050.lcssa)
  %36 = tail call double @sqrt(double noundef %.048.lcssa) #3
  %37 = fdiv double %35, %36
  %38 = tail call double @llvm.fabs.f64(double %37)
  %39 = fsub double %12, %38
  br label %40

40:                                               ; preds = %34, %._crit_edge
  %.0 = phi double [ %39, %34 ], [ %12, %._crit_edge ]
  %41 = fmul double %.0, 1.000000e-05
  %42 = fsub double -2.000000e+03, %41
  store double %8, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %3, i64 8
  store double %10, ptr %43, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %3, i64 16
  store double %41, ptr %44, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %3, i64 24
  store double %42, ptr %45, align 8, !tbaa !5
  store i8 1, ptr %4, align 1, !tbaa !11
  ret i1 true
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

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

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

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

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

attributes #0 = { nofree nounwind memory(write, argmem: readwrite) 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 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 #2 = { mustprogress 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}


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