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

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_JPEG_Encode(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #1 {
  %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 %147

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

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 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %38, i32 0, i32 16
  %40 = load volatile i32, ptr %39, align 4, !tbaa !14
  %41 = icmp ne i32 %40, 1
  br i1 %41, label %42, label %48

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %44, i32 0, i32 15
  store i32 0, ptr %45, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  store i32 2, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %147

48:                                               ; preds = %37
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %49, i32 0, i32 16
  %51 = load volatile i32, ptr %50, align 4, !tbaa !14
  %52 = icmp eq i32 %51, 1
  br i1 %52, label %53, label %146

53:                                               ; preds = %48
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %54, i32 0, i32 18
  %56 = load volatile i32, ptr %55, align 4, !tbaa !15
  %57 = and i32 %56, 256
  %58 = icmp eq i32 %57, 256
  br i1 %58, label %59, label %139

59:                                               ; preds = %53
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %60, i32 0, i32 16
  store volatile i32 3, ptr %61, align 4, !tbaa !14
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %62, i32 0, i32 18
  %64 = load volatile i32, ptr %63, align 4, !tbaa !15
  %65 = and i32 %64, -16
  store volatile i32 %65, ptr %63, align 4, !tbaa !15
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %66, i32 0, i32 18
  %68 = load volatile i32, ptr %67, align 4, !tbaa !15
  %69 = or i32 %68, 5
  store volatile i32 %69, ptr %67, align 4, !tbaa !15
  %70 = call i32 @HAL_GetTick()
  store i32 %70, ptr %14, align 4, !tbaa !9
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %72, i32 0, i32 2
  store ptr %71, ptr %73, align 8, !tbaa !16
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %75, i32 0, i32 3
  store ptr %74, ptr %76, align 8, !tbaa !17
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = zext i32 %79 to i64
  %81 = urem i64 %80, 4
  %82 = sub i64 %78, %81
  %83 = trunc i64 %82 to i32
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %84, i32 0, i32 6
  store i32 %83, ptr %85, align 8, !tbaa !18
  %86 = load i32, ptr %12, align 4, !tbaa !9
  %87 = zext i32 %86 to i64
  %88 = load i32, ptr %12, align 4, !tbaa !9
  %89 = zext i32 %88 to i64
  %90 = urem i64 %89, 4
  %91 = sub i64 %87, %90
  %92 = trunc i64 %91 to i32
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %93, i32 0, i32 7
  store i32 %92, ptr %94, align 4, !tbaa !19
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %95, i32 0, i32 4
  store volatile i32 0, ptr %96, align 8, !tbaa !20
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %97, i32 0, i32 5
  store volatile i32 0, ptr %98, align 4, !tbaa !21
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  call void @JPEG_Init_Process(ptr noundef %99)
  br label %100

100:                                              ; preds = %130, %59
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = call i32 @JPEG_Process(ptr noundef %101)
  %103 = icmp eq i32 %102, 0
  br i1 %103, label %104, label %131

104:                                              ; preds = %100
  %105 = load i32, ptr %13, align 4, !tbaa !9
  %106 = icmp ne i32 %105, -1
  br i1 %106, label %107, label %130

107:                                              ; preds = %104
  %108 = call i32 @HAL_GetTick()
  %109 = load i32, ptr %14, align 4, !tbaa !9
  %110 = sub i32 %108, %109
  %111 = load i32, ptr %13, align 4, !tbaa !9
  %112 = icmp ugt i32 %110, %111
  br i1 %112, label %117, label %113

113:                                              ; preds = %107
  %114 = load i32, ptr %13, align 4, !tbaa !9
  %115 = zext i32 %114 to i64
  %116 = icmp eq i64 %115, 0
  br i1 %116, label %117, label %129

117:                                              ; preds = %113, %107
  %118 = load ptr, ptr %8, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %118, i32 0, i32 17
  %120 = load volatile i32, ptr %119, align 8, !tbaa !22
  %121 = or i32 %120, 8
  store volatile i32 %121, ptr %119, align 8, !tbaa !22
  br label %122

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

125:                                              ; preds = %122
  br label %126

126:                                              ; preds = %125
  %127 = load ptr, ptr %8, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %127, i32 0, i32 16
  store volatile i32 1, ptr %128, align 4, !tbaa !14
  store i32 3, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %147

129:                                              ; preds = %113
  br label %130

130:                                              ; preds = %129, %104
  br label %100, !llvm.loop !23

131:                                              ; preds = %100
  br label %132

132:                                              ; preds = %131
  %133 = load ptr, ptr %8, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %133, i32 0, i32 15
  store i32 0, ptr %134, align 8, !tbaa !11
  br label %135

135:                                              ; preds = %132
  br label %136

136:                                              ; preds = %135
  %137 = load ptr, ptr %8, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %137, i32 0, i32 16
  store volatile i32 1, ptr %138, align 4, !tbaa !14
  br label %145

139:                                              ; preds = %53
  br label %140

140:                                              ; preds = %139
  %141 = load ptr, ptr %8, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.JPEG_HandleTypeDef, ptr %141, i32 0, i32 15
  store i32 0, ptr %142, align 8, !tbaa !11
  br label %143

143:                                              ; preds = %140
  br label %144

144:                                              ; preds = %143
  store i32 1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %147

145:                                              ; preds = %136
  br label %146

146:                                              ; preds = %145, %48
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %147

147:                                              ; preds = %146, %144, %126, %47, %31, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %148 = load i32, ptr %7, align 4
  ret i32 %148
}

declare i32 @HAL_GetTick() #2

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

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

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 = { "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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_JPEG_Encode(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %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 %54, 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 %54, label %14

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

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

18:                                               ; preds = %14
  %19 = load volatile i32, ptr %15, align 4, !tbaa !12
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %54

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 132
  %23 = load volatile i32, ptr %22, align 4, !tbaa !13
  %24 = and i32 %23, 256
  %.not46 = icmp eq i32 %24, 0
  br i1 %.not46, label %53, label %25

25:                                               ; preds = %21
  store volatile i32 3, ptr %15, align 4, !tbaa !12
  %26 = load volatile i32, ptr %22, align 4, !tbaa !13
  %27 = and i32 %26, -16
  store volatile i32 %27, ptr %22, align 4, !tbaa !13
  %28 = load volatile i32, ptr %22, align 4, !tbaa !13
  %29 = or i32 %28, 5
  store volatile i32 %29, ptr %22, align 4, !tbaa !13
  %30 = tail call i32 @HAL_GetTick() #2
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %1, ptr %31, align 8, !tbaa !14
  %32 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %3, ptr %32, align 8, !tbaa !15
  %33 = and i32 %2, -4
  %34 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %33, ptr %34, align 8, !tbaa !16
  %35 = and i32 %4, -4
  %36 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %35, ptr %36, align 4, !tbaa !17
  %37 = getelementptr inbounds i8, ptr %0, i64 48
  store volatile i32 0, ptr %37, align 8, !tbaa !18
  %38 = getelementptr inbounds i8, ptr %0, i64 52
  store volatile i32 0, ptr %38, align 4, !tbaa !19
  tail call void @JPEG_Init_Process(ptr noundef nonnull %0)
  %39 = tail call i32 @JPEG_Process(ptr noundef nonnull %0)
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %25
  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
  %41 = tail call i32 @JPEG_Process(ptr noundef %0)
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !20

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

.lr.ph.split.split:                               ; preds = %.lr.ph, %50
  %44 = tail call i32 @HAL_GetTick() #2
  %45 = sub i32 %44, %30
  %46 = icmp ugt i32 %45, %5
  br i1 %46, label %.split, label %50

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

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

._crit_edge:                                      ; preds = %.lr.ph.split.us, %50, %25
  store i32 0, ptr %11, align 8, !tbaa !5
  store volatile i32 1, ptr %15, align 4, !tbaa !12
  br label %54

53:                                               ; preds = %21
  store i32 0, ptr %11, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %18, %._crit_edge, %10, %6, %53, %.split, %17
  %.0 = phi i32 [ 2, %17 ], [ 3, %.split ], [ 1, %53 ], [ 1, %6 ], [ 2, %10 ], [ 0, %._crit_edge ], [ 0, %18 ]
  ret i32 %.0
}

declare i32 @HAL_GetTick() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @JPEG_Process(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" }
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 }

!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