; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/picojpeg (libpicojpeg)

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

@gCallbackStatus = external hidden global i8, align 1
@gNumMCUSRemaining = external hidden global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @pjpeg_decode_mcu() #0 {
  %1 = alloca i8, align 1
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #2
  %4 = load i8, ptr @gCallbackStatus, align 1, !tbaa !5
  %5 = icmp ne i8 %4, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %0
  %7 = load i8, ptr @gCallbackStatus, align 1, !tbaa !5
  store i8 %7, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %37

8:                                                ; preds = %0
  %9 = load i16, ptr @gNumMCUSRemaining, align 2, !tbaa !8
  %10 = icmp ne i16 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i8 1, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %37

12:                                               ; preds = %8
  %13 = call zeroext i8 @decodeNextMCU()
  store i8 %13, ptr %2, align 1, !tbaa !5
  %14 = load i8, ptr %2, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %21, label %17

17:                                               ; preds = %12
  %18 = load i8, ptr @gCallbackStatus, align 1, !tbaa !5
  %19 = zext i8 %18 to i32
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %34

21:                                               ; preds = %17, %12
  %22 = load i8, ptr @gCallbackStatus, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load i8, ptr @gCallbackStatus, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  br label %31

28:                                               ; preds = %21
  %29 = load i8, ptr %2, align 1, !tbaa !5
  %30 = zext i8 %29 to i32
  br label %31

31:                                               ; preds = %28, %25
  %32 = phi i32 [ %27, %25 ], [ %30, %28 ]
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %37

34:                                               ; preds = %17
  %35 = load i16, ptr @gNumMCUSRemaining, align 2, !tbaa !8
  %36 = add i16 %35, -1
  store i16 %36, ptr @gNumMCUSRemaining, align 2, !tbaa !8
  store i8 0, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %37

37:                                               ; preds = %34, %31, %11, %6
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #2
  %38 = load i8, ptr %1, align 1
  ret i8 %38
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @decodeNextMCU() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}


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

@gCallbackStatus = external hidden local_unnamed_addr global i8, align 1
@gNumMCUSRemaining = external hidden local_unnamed_addr global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @pjpeg_decode_mcu() local_unnamed_addr #0 {
  %1 = load i8, ptr @gCallbackStatus, align 1, !tbaa !5
  %.not = icmp eq i8 %1, 0
  br i1 %.not, label %2, label %13

2:                                                ; preds = %0
  %3 = load i16, ptr @gNumMCUSRemaining, align 2, !tbaa !8
  %.not6 = icmp eq i16 %3, 0
  br i1 %.not6, label %13, label %4

4:                                                ; preds = %2
  %5 = tail call zeroext i8 @decodeNextMCU()
  %6 = icmp ne i8 %5, 0
  %7 = load i8, ptr @gCallbackStatus, align 1
  %8 = icmp ne i8 %7, 0
  %or.cond = select i1 %6, i1 true, i1 %8
  br i1 %or.cond, label %9, label %10

9:                                                ; preds = %4
  %.v = select i1 %8, i8 %7, i8 %5
  br label %13

10:                                               ; preds = %4
  %11 = load i16, ptr @gNumMCUSRemaining, align 2, !tbaa !8
  %12 = add i16 %11, -1
  store i16 %12, ptr @gNumMCUSRemaining, align 2, !tbaa !8
  br label %13

13:                                               ; preds = %2, %0, %10, %9
  %.0 = phi i8 [ %.v, %9 ], [ 0, %10 ], [ %1, %0 ], [ 1, %2 ]
  ret i8 %.0
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @decodeNextMCU() 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}


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