; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (DMA)

; 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.JPEG_HandleTypeDef = type { ptr, %struct.JPEG_ConfTypeDef, ptr, ptr, i32, i32, i32, i32, ptr, ptr, i8, ptr, ptr, ptr, ptr, i32, i32, i32, i32 }
%struct.JPEG_ConfTypeDef = type { i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare hidden void @JPEG_Init_Process(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_JPEG_Encode_DMA(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %20, label %14

14:                                               ; preds = %5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %14, %5
  store i32 1, ptr %6, align 4
  br label %94

21:                                               ; preds = %17
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %23, i32 0, i32 15
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i32 2, ptr %6, align 4
  br label %94

28:                                               ; preds = %22
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %29, i32 0, i32 15
  store i32 1, ptr %30, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %33, i32 0, i32 16
  %35 = load volatile i32, ptr %34, align 4, !tbaa !14
  %36 = icmp ne i32 %35, 1
  br i1 %36, label %37, label %42

37:                                               ; preds = %32
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %39, i32 0, i32 15
  store i32 0, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %38
  store i32 2, ptr %6, align 4
  br label %94

42:                                               ; preds = %32
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %43, i32 0, i32 18
  %45 = load volatile i32, ptr %44, align 4, !tbaa !15
  %46 = and i32 %45, 256
  %47 = icmp eq i32 %46, 256
  br i1 %47, label %48, label %87

48:                                               ; preds = %42
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %49, i32 0, i32 16
  store volatile i32 3, ptr %50, align 4, !tbaa !14
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %51, i32 0, i32 18
  %53 = load volatile i32, ptr %52, align 4, !tbaa !15
  %54 = and i32 %53, -16
  store volatile i32 %54, ptr %52, align 4, !tbaa !15
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %55, i32 0, i32 18
  %57 = load volatile i32, ptr %56, align 4, !tbaa !15
  %58 = or i32 %57, 13
  store volatile i32 %58, ptr %56, align 4, !tbaa !15
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %60, i32 0, i32 2
  store ptr %59, ptr %61, align 8, !tbaa !16
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %63, i32 0, i32 3
  store ptr %62, ptr %64, align 8, !tbaa !17
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %66, i32 0, i32 6
  store i32 %65, ptr %67, align 8, !tbaa !18
  %68 = load i32, ptr %11, align 4, !tbaa !9
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %69, i32 0, i32 7
  store i32 %68, ptr %70, align 4, !tbaa !19
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %71, i32 0, i32 4
  store volatile i32 0, ptr %72, align 8, !tbaa !20
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %73, i32 0, i32 5
  store volatile i32 0, ptr %74, align 4, !tbaa !21
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  call void @JPEG_Init_Process(ptr noundef %75)
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = call i32 @JPEG_DMA_StartProcess(ptr noundef %76)
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %86

79:                                               ; preds = %48
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %80, i32 0, i32 16
  store volatile i32 6, ptr %81, align 4, !tbaa !14
  br label %82

82:                                               ; preds = %79
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %83, i32 0, i32 15
  store i32 0, ptr %84, align 8, !tbaa !11
  br label %85

85:                                               ; preds = %82
  store i32 1, ptr %6, align 4
  br label %94

86:                                               ; preds = %48
  br label %92

87:                                               ; preds = %42
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %89, i32 0, i32 15
  store i32 0, ptr %90, align 8, !tbaa !11
  br label %91

91:                                               ; preds = %88
  store i32 1, ptr %6, align 4
  br label %94

92:                                               ; preds = %86
  br label %93

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

94:                                               ; preds = %93, %91, %85, %41, %27, %20
  %95 = load i32, ptr %6, align 4
  ret i32 %95
}

; Function Attrs: nounwind uwtable
declare hidden i32 @JPEG_DMA_StartProcess(ptr noundef) #0

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

!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 120}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !6, i64 64, !6, i64 72, !7, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!14 = !{!12, !10, i64 124}
!15 = !{!12, !10, i64 132}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 40}
!18 = !{!12, !10, i64 56}
!19 = !{!12, !10, i64 60}
!20 = !{!12, !10, i64 48}
!21 = !{!12, !10, i64 52}


; 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: nounwind uwtable
declare hidden void @JPEG_Init_Process(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_JPEG_Encode_DMA(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %7
  %8 = icmp eq ptr %3, null
  %or.cond3 = or i1 %or.cond, %8
  br i1 %or.cond3, label %33, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 120
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %33, label %13

13:                                               ; preds = %9
  store i32 1, ptr %10, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 124
  %15 = load volatile i32, ptr %14, align 4, !tbaa !12
  %.not = icmp eq i32 %15, 1
  br i1 %.not, label %16, label %.sink.split

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 132
  %18 = load volatile i32, ptr %17, align 4, !tbaa !13
  %19 = and i32 %18, 256
  %.not32 = icmp eq i32 %19, 0
  br i1 %.not32, label %.sink.split, label %20

20:                                               ; preds = %16
  store volatile i32 3, ptr %14, align 4, !tbaa !12
  %21 = load volatile i32, ptr %17, align 4, !tbaa !13
  %22 = and i32 %21, -16
  store volatile i32 %22, ptr %17, align 4, !tbaa !13
  %23 = load volatile i32, ptr %17, align 4, !tbaa !13
  %24 = or i32 %23, 13
  store volatile i32 %24, ptr %17, align 4, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %1, ptr %25, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %3, ptr %26, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %2, ptr %27, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %4, ptr %28, align 4, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %0, i64 48
  store volatile i32 0, ptr %29, align 8, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %0, i64 52
  store volatile i32 0, ptr %30, align 4, !tbaa !19
  tail call void @JPEG_Init_Process(ptr noundef nonnull %0)
  %31 = tail call i32 @JPEG_DMA_StartProcess(ptr noundef nonnull %0)
  %.not33 = icmp eq i32 %31, 0
  br i1 %.not33, label %33, label %32

32:                                               ; preds = %20
  store volatile i32 6, ptr %14, align 4, !tbaa !12
  br label %.sink.split

.sink.split:                                      ; preds = %16, %13, %32
  %.0.ph = phi i32 [ 1, %32 ], [ 2, %13 ], [ 1, %16 ]
  store i32 0, ptr %10, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %.sink.split, %20, %9, %5
  %.0 = phi i32 [ 1, %5 ], [ 2, %9 ], [ 0, %20 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @JPEG_DMA_StartProcess(ptr noundef) local_unnamed_addr #0

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

!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, !11, i64 120}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 32, !7, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !7, i64 64, !7, i64 72, !8, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 124}
!13 = !{!6, !11, i64 132}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !7, i64 40}
!16 = !{!6, !11, i64 56}
!17 = !{!6, !11, i64 60}
!18 = !{!6, !11, i64 48}
!19 = !{!6, !11, i64 52}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass