; 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
declare hidden i32 @JPEG_DMA_StartProcess(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_JPEG_Decode_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 %82

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 %82

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 eq i32 %35, 1
  br i1 %36, label %37, label %76

37:                                               ; preds = %32
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %38, i32 0, i32 16
  store volatile i32 4, ptr %39, align 4, !tbaa !14
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %40, i32 0, i32 18
  %42 = load volatile i32, ptr %41, align 4, !tbaa !15
  %43 = and i32 %42, -16
  store volatile i32 %43, ptr %41, align 4, !tbaa !15
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %44, i32 0, i32 18
  %46 = load volatile i32, ptr %45, align 4, !tbaa !15
  %47 = or i32 %46, 14
  store volatile i32 %47, ptr %45, align 4, !tbaa !15
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %49, i32 0, i32 2
  store ptr %48, ptr %50, align 8, !tbaa !16
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %52, i32 0, i32 3
  store ptr %51, ptr %53, align 8, !tbaa !17
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %55, i32 0, i32 6
  store i32 %54, ptr %56, align 8, !tbaa !18
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %58, i32 0, i32 7
  store i32 %57, ptr %59, align 4, !tbaa !19
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %60, i32 0, i32 4
  store volatile i32 0, ptr %61, align 8, !tbaa !20
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %62, i32 0, i32 5
  store volatile i32 0, ptr %63, align 4, !tbaa !21
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  call void @JPEG_Init_Process(ptr noundef %64)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i32 @JPEG_DMA_StartProcess(ptr noundef %65)
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %75

68:                                               ; preds = %37
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %69, i32 0, i32 16
  store volatile i32 6, ptr %70, align 4, !tbaa !14
  br label %71

71:                                               ; preds = %68
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %72, i32 0, i32 15
  store i32 0, ptr %73, align 8, !tbaa !11
  br label %74

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

75:                                               ; preds = %37
  br label %81

76:                                               ; preds = %32
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %78, i32 0, i32 15
  store i32 0, ptr %79, align 8, !tbaa !11
  br label %80

80:                                               ; preds = %77
  store i32 2, ptr %6, align 4
  br label %82

81:                                               ; preds = %75
  store i32 0, ptr %6, align 4
  br label %82

82:                                               ; preds = %81, %80, %74, %27, %20
  %83 = load i32, ptr %6, align 4
  ret i32 %83
}

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
declare hidden i32 @JPEG_DMA_StartProcess(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_JPEG_Decode_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 %31, 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 %31, 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
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %.sink.split

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

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

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

31:                                               ; preds = %.sink.split, %17, %9, %5
  %.0 = phi i32 [ 1, %5 ], [ 2, %9 ], [ 0, %17 ], [ %.0.ph, %.sink.split ]
  ret i32 %.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