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

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

declare i32 @HAL_GetTick() #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @JPEG_Process(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_JPEG_Decode(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i32 %4, ptr %12, align 4, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %24, label %18

18:                                               ; preds = %6
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %21, %18, %6
  store i32 1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %129

25:                                               ; preds = %21
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %27, i32 0, i32 15
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  store i32 2, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %129

32:                                               ; preds = %26
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %33, i32 0, i32 15
  store i32 1, ptr %34, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %32
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  %38 = call i32 @HAL_GetTick()
  store i32 %38, ptr %14, align 4, !tbaa !9
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %39, i32 0, i32 16
  %41 = load volatile i32, ptr %40, align 4, !tbaa !14
  %42 = icmp eq i32 %41, 1
  br i1 %42, label %43, label %122

43:                                               ; preds = %37
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %44, i32 0, i32 16
  store volatile i32 4, ptr %45, align 4, !tbaa !14
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %46, i32 0, i32 18
  %48 = load volatile i32, ptr %47, align 4, !tbaa !15
  %49 = and i32 %48, -16
  store volatile i32 %49, ptr %47, align 4, !tbaa !15
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %50, i32 0, i32 18
  %52 = load volatile i32, ptr %51, align 4, !tbaa !15
  %53 = or i32 %52, 6
  store volatile i32 %53, ptr %51, align 4, !tbaa !15
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %55, i32 0, i32 2
  store ptr %54, ptr %56, align 8, !tbaa !16
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %58, i32 0, i32 3
  store ptr %57, ptr %59, align 8, !tbaa !17
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = zext i32 %60 to i64
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = urem i64 %63, 4
  %65 = sub i64 %61, %64
  %66 = trunc i64 %65 to i32
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %67, i32 0, i32 6
  store i32 %66, ptr %68, align 8, !tbaa !18
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = zext i32 %69 to i64
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = zext i32 %71 to i64
  %73 = urem i64 %72, 4
  %74 = sub i64 %70, %73
  %75 = trunc i64 %74 to i32
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %76, i32 0, i32 7
  store i32 %75, ptr %77, align 4, !tbaa !19
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %78, i32 0, i32 4
  store volatile i32 0, ptr %79, align 8, !tbaa !20
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %80, i32 0, i32 5
  store volatile i32 0, ptr %81, align 4, !tbaa !21
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  call void @JPEG_Init_Process(ptr noundef %82)
  br label %83

83:                                               ; preds = %113, %43
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = call i32 @JPEG_Process(ptr noundef %84)
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %114

87:                                               ; preds = %83
  %88 = load i32, ptr %13, align 4, !tbaa !9
  %89 = icmp ne i32 %88, -1
  br i1 %89, label %90, label %113

90:                                               ; preds = %87
  %91 = call i32 @HAL_GetTick()
  %92 = load i32, ptr %14, align 4, !tbaa !9
  %93 = sub i32 %91, %92
  %94 = load i32, ptr %13, align 4, !tbaa !9
  %95 = icmp ugt i32 %93, %94
  br i1 %95, label %100, label %96

96:                                               ; preds = %90
  %97 = load i32, ptr %13, align 4, !tbaa !9
  %98 = zext i32 %97 to i64
  %99 = icmp eq i64 %98, 0
  br i1 %99, label %100, label %112

100:                                              ; preds = %96, %90
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %101, i32 0, i32 17
  %103 = load volatile i32, ptr %102, align 8, !tbaa !22
  %104 = or i32 %103, 8
  store volatile i32 %104, ptr %102, align 8, !tbaa !22
  br label %105

105:                                              ; preds = %100
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %106, i32 0, i32 15
  store i32 0, ptr %107, align 8, !tbaa !11
  br label %108

108:                                              ; preds = %105
  br label %109

109:                                              ; preds = %108
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %110, i32 0, i32 16
  store volatile i32 1, ptr %111, align 4, !tbaa !14
  store i32 3, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %129

112:                                              ; preds = %96
  br label %113

113:                                              ; preds = %112, %87
  br label %83, !llvm.loop !23

114:                                              ; preds = %83
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %8, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %116, i32 0, i32 15
  store i32 0, ptr %117, align 8, !tbaa !11
  br label %118

118:                                              ; preds = %115
  br label %119

119:                                              ; preds = %118
  %120 = load ptr, ptr %8, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %120, i32 0, i32 16
  store volatile i32 1, ptr %121, align 4, !tbaa !14
  br label %128

122:                                              ; preds = %37
  br label %123

123:                                              ; preds = %122
  %124 = load ptr, ptr %8, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %124, i32 0, i32 15
  store i32 0, ptr %125, align 8, !tbaa !11
  br label %126

126:                                              ; preds = %123
  br label %127

127:                                              ; preds = %126
  store i32 2, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %129

128:                                              ; preds = %119
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %129

129:                                              ; preds = %128, %127, %109, %31, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %130 = load i32, ptr %7, align 4
  ret i32 %130
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 = !{!"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}
!22 = !{!12, !10, i64 128}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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

declare i32 @HAL_GetTick() local_unnamed_addr #0

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

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

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

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

14:                                               ; preds = %10
  store i32 1, ptr %11, align 8, !tbaa !5
  %15 = tail call i32 @HAL_GetTick() #2
  %16 = getelementptr inbounds i8, ptr %0, i64 124
  %17 = load volatile i32, ptr %16, align 4, !tbaa !12
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %47

19:                                               ; preds = %14
  store volatile i32 4, ptr %16, align 4, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %0, i64 132
  %21 = load volatile i32, ptr %20, align 4, !tbaa !13
  %22 = and i32 %21, -16
  store volatile i32 %22, ptr %20, align 4, !tbaa !13
  %23 = load volatile i32, ptr %20, align 4, !tbaa !13
  %24 = or i32 %23, 6
  store volatile i32 %24, ptr %20, 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 = and i32 %2, -4
  %28 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %27, ptr %28, align 8, !tbaa !16
  %29 = and i32 %4, -4
  %30 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %29, ptr %30, align 4, !tbaa !17
  %31 = getelementptr inbounds i8, ptr %0, i64 48
  store volatile i32 0, ptr %31, align 8, !tbaa !18
  %32 = getelementptr inbounds i8, ptr %0, i64 52
  store volatile i32 0, ptr %32, align 4, !tbaa !19
  tail call void @JPEG_Init_Process(ptr noundef nonnull %0)
  %33 = tail call i32 @JPEG_Process(ptr noundef nonnull %0)
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %19
  switch i32 %5, label %.lr.ph.split.split [
    i32 -1, label %.lr.ph.split.us
    i32 0, label %.lr.ph.split.split.us
  ]

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %35 = tail call i32 @JPEG_Process(ptr noundef %0)
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !20

.lr.ph.split.split.us:                            ; preds = %.lr.ph
  %37 = tail call i32 @HAL_GetTick() #2
  br label %.split

.lr.ph.split.split:                               ; preds = %.lr.ph, %44
  %38 = tail call i32 @HAL_GetTick() #2
  %39 = sub i32 %38, %15
  %40 = icmp ugt i32 %39, %5
  br i1 %40, label %.split, label %44

.split:                                           ; preds = %.lr.ph.split.split, %.lr.ph.split.split.us
  %41 = getelementptr inbounds i8, ptr %0, i64 128
  %42 = load volatile i32, ptr %41, align 8, !tbaa !22
  %43 = or i32 %42, 8
  store volatile i32 %43, ptr %41, align 8, !tbaa !22
  store i32 0, ptr %11, align 8, !tbaa !5
  store volatile i32 1, ptr %16, align 4, !tbaa !12
  br label %48

44:                                               ; preds = %.lr.ph.split.split
  %45 = tail call i32 @JPEG_Process(ptr noundef %0)
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %.lr.ph.split.split, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph.split.us, %44, %19
  store i32 0, ptr %11, align 8, !tbaa !5
  store volatile i32 1, ptr %16, align 4, !tbaa !12
  br label %48

47:                                               ; preds = %14
  store i32 0, ptr %11, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %10, %6, %._crit_edge, %47, %.split
  %.0 = phi i32 [ 3, %.split ], [ 0, %._crit_edge ], [ 2, %47 ], [ 1, %6 ], [ 2, %10 ]
  ret i32 %.0
}

attributes #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 = { 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 = { 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, !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}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !11, i64 128}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass