; LLVM IR from DroneBridge/DroneBridge :: video (fec)

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

@fec_initialized = external hidden global i32, align 4
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.fec_encode = external hidden unnamed_addr constant [85 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1
@inverse = external hidden global [256 x i8], align 16

; 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
define dso_local void @fec_encode(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %15 = load i32, ptr @fec_initialized, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  br label %19

18:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 518, ptr noundef @__PRETTY_FUNCTION__.fec_encode) #5
  unreachable

19:                                               ; preds = %17
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = icmp ule i32 %20, 128
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  br label %24

23:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 519, ptr noundef @__PRETTY_FUNCTION__.fec_encode) #5
  unreachable

24:                                               ; preds = %22
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = icmp ule i32 %25, 128
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  br label %29

28:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.2, i32 noundef 520, ptr noundef @__PRETTY_FUNCTION__.fec_encode) #5
  unreachable

29:                                               ; preds = %27
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  store i32 1, ptr %14, align 4
  br label %94

33:                                               ; preds = %29
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %53, %33
  %35 = load i32, ptr %12, align 4, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = icmp ult i32 %35, %36
  br i1 %37, label %38, label %56

38:                                               ; preds = %34
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = load i32, ptr %12, align 4, !tbaa !5
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %39, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = getelementptr inbounds ptr, ptr %44, i64 0
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = load i32, ptr %12, align 4, !tbaa !5
  %48 = xor i32 128, %47
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds [256 x i8], ptr @inverse, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !11
  %52 = load i32, ptr %6, align 4, !tbaa !5
  call void @gf256_mul_mem(ptr noundef %43, ptr noundef %46, i8 noundef zeroext %51, i32 noundef %52)
  br label %53

53:                                               ; preds = %38
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = add i32 %54, 1
  store i32 %55, ptr %12, align 4, !tbaa !5
  br label %34, !llvm.loop !12

56:                                               ; preds = %34
  store i32 129, ptr %13, align 4, !tbaa !5
  store i32 1, ptr %11, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %88, %56
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = icmp ult i32 %58, %59
  br i1 %60, label %61, label %93

61:                                               ; preds = %57
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %84, %61
  %63 = load i32, ptr %12, align 4, !tbaa !5
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = icmp ult i32 %63, %64
  br i1 %65, label %66, label %87

66:                                               ; preds = %62
  %67 = load ptr, ptr %9, align 8, !tbaa !9
  %68 = load i32, ptr %12, align 4, !tbaa !5
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds ptr, ptr %67, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = load i32, ptr %13, align 4, !tbaa !5
  %74 = xor i32 %72, %73
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds [256 x i8], ptr @inverse, i64 0, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !11
  %78 = load ptr, ptr %7, align 8, !tbaa !9
  %79 = load i32, ptr %11, align 4, !tbaa !5
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds ptr, ptr %78, i64 %80
  %82 = load ptr, ptr %81, align 8, !tbaa !9
  %83 = load i32, ptr %6, align 4, !tbaa !5
  call void @gf256_muladd_mem(ptr noundef %71, i8 noundef zeroext %77, ptr noundef %82, i32 noundef %83)
  br label %84

84:                                               ; preds = %66
  %85 = load i32, ptr %12, align 4, !tbaa !5
  %86 = add i32 %85, 1
  store i32 %86, ptr %12, align 4, !tbaa !5
  br label %62, !llvm.loop !14

87:                                               ; preds = %62
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %13, align 4, !tbaa !5
  %90 = add i32 %89, 1
  store i32 %90, ptr %13, align 4, !tbaa !5
  %91 = load i32, ptr %11, align 4, !tbaa !5
  %92 = add i32 %91, 1
  store i32 %92, ptr %11, align 4, !tbaa !5
  br label %57, !llvm.loop !15

93:                                               ; preds = %57
  store i32 0, ptr %14, align 4
  br label %94

94:                                               ; preds = %93, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %95 = load i32, ptr %14, align 4
  switch i32 %95, label %97 [
    i32 0, label %96
    i32 1, label %96
  ]

96:                                               ; preds = %94, %94
  ret void

97:                                               ; preds = %94
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare void @gf256_mul_mem(ptr noundef, ptr noundef, i8 noundef zeroext, i32 noundef) #3

declare void @gf256_muladd_mem(ptr noundef, i8 noundef zeroext, ptr noundef, i32 noundef) #3

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 = { noreturn 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 = { "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 }
attributes #5 = { noreturn 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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

@fec_initialized = external hidden local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.fec_encode = external hidden unnamed_addr constant [85 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1
@inverse = external hidden local_unnamed_addr global [256 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @fec_encode(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr @fec_initialized, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %8

7:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 518, ptr noundef nonnull @__PRETTY_FUNCTION__.fec_encode) #4
  unreachable

8:                                                ; preds = %5
  %9 = icmp ult i32 %2, 129
  br i1 %9, label %11, label %10

10:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 519, ptr noundef nonnull @__PRETTY_FUNCTION__.fec_encode) #4
  unreachable

11:                                               ; preds = %8
  %12 = icmp ult i32 %4, 129
  br i1 %12, label %14, label %13

13:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.2, i32 noundef 520, ptr noundef nonnull @__PRETTY_FUNCTION__.fec_encode) #4
  unreachable

14:                                               ; preds = %11
  %.not28 = icmp eq i32 %2, 0
  br i1 %.not28, label %.loopexit, label %.preheader30

.preheader30:                                     ; preds = %14
  %.not36 = icmp eq i32 %4, 0
  br i1 %.not36, label %.loopexit, label %.lr.ph.preheader

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

.preheader29:                                     ; preds = %.lr.ph
  %.not37 = icmp eq i32 %2, 1
  %brmerge = or i1 %.not37, %.not36
  br i1 %brmerge, label %.loopexit, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader29
  %umax = tail call i32 @llvm.umax.i32(i32 %2, i32 2)
  %wide.trip.count49 = zext nneg i32 %umax to i64
  %wide.trip.count44 = zext nneg i32 %4 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv46 = phi i64 [ 1, %.preheader.us.preheader ], [ %indvars.iv.next47, %._crit_edge.us ]
  %.035.us = phi i32 [ 129, %.preheader.us.preheader ], [ %25, %._crit_edge.us ]
  %15 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv46
  br label %16

16:                                               ; preds = %.preheader.us, %16
  %indvars.iv41 = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next42, %16 ]
  %17 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv41
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = trunc nuw nsw i64 %indvars.iv41 to i32
  %20 = xor i32 %.035.us, %19
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [256 x i8], ptr @inverse, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = load ptr, ptr %15, align 8, !tbaa !9
  tail call void @gf256_muladd_mem(ptr noundef %18, i8 noundef zeroext %23, ptr noundef %24, i32 noundef %0) #5
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %wide.trip.count44
  br i1 %exitcond45.not, label %._crit_edge.us, label %16, !llvm.loop !12

._crit_edge.us:                                   ; preds = %16
  %25 = add i32 %.035.us, 1
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next47, %wide.trip.count49
  br i1 %exitcond50.not, label %.loopexit, label %.preheader.us, !llvm.loop !14

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %26 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = load ptr, ptr %1, align 8, !tbaa !9
  %29 = and i64 %indvars.iv, 4294967295
  %30 = xor i64 %29, 128
  %31 = getelementptr inbounds [256 x i8], ptr @inverse, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  tail call void @gf256_mul_mem(ptr noundef %27, ptr noundef %28, i8 noundef zeroext %32, i32 noundef %0) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader29, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %._crit_edge.us, %.preheader29, %.preheader30, %14
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @gf256_mul_mem(ptr noundef, ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #2

declare void @gf256_muladd_mem(ptr noundef, i8 noundef zeroext, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 = { noreturn 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 #2 = { "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 = { noreturn nounwind }
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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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