; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/devices (mfrc522)

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

@MFRC522_PICC_DumpMifareClassicToSerial.str = external hidden constant [77 x i8], align 4

; 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
declare dso_local i32 @MFRC522_PICC_HaltA() #1

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PCD_StopCrypto1() #1

declare void @dhdebug_ram(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @MFRC522_PICC_DumpMifareClassicToSerial(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 0, ptr %7, align 1, !tbaa !11
  %9 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %9, label %13 [
    i32 3, label %10
    i32 4, label %11
    i32 5, label %12
  ]

10:                                               ; preds = %3
  store i8 5, ptr %7, align 1, !tbaa !11
  br label %14

11:                                               ; preds = %3
  store i8 16, ptr %7, align 1, !tbaa !11
  br label %14

12:                                               ; preds = %3
  store i8 40, ptr %7, align 1, !tbaa !11
  br label %14

13:                                               ; preds = %3
  br label %14

14:                                               ; preds = %13, %12, %11, %10
  %15 = load i8, ptr %7, align 1, !tbaa !11
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %37

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  call void (ptr, ...) @dhdebug_ram(ptr noundef @MFRC522_PICC_DumpMifareClassicToSerial.str)
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %21 = load i8, ptr %7, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = sub nsw i32 %22, 1
  %24 = trunc i32 %23 to i8
  store i8 %24, ptr %8, align 1, !tbaa !11
  br label %25

25:                                               ; preds = %33, %20
  %26 = load i8, ptr %8, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %36

29:                                               ; preds = %25
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i8, ptr %8, align 1, !tbaa !11
  call void @MFRC522_PICC_DumpMifareClassicSectorToSerial(ptr noundef %30, ptr noundef %31, i8 noundef zeroext %32)
  br label %33

33:                                               ; preds = %29
  %34 = load i8, ptr %8, align 1, !tbaa !11
  %35 = add i8 %34, -1
  store i8 %35, ptr %8, align 1, !tbaa !11
  br label %25, !llvm.loop !12

36:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  br label %37

37:                                               ; preds = %36, %14
  %38 = call i32 @MFRC522_PICC_HaltA()
  call void @MFRC522_PCD_StopCrypto1()
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PICC_DumpMifareClassicSectorToSerial(ptr noundef, ptr noundef, i8 noundef zeroext) #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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@MFRC522_PICC_DumpMifareClassicToSerial.str = external hidden constant [77 x i8], align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @MFRC522_PICC_HaltA() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PCD_StopCrypto1() local_unnamed_addr #0

declare void @dhdebug_ram(ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @MFRC522_PICC_DumpMifareClassicToSerial(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %switch.tableidx = add i32 %1, -3
  %4 = icmp ult i32 %switch.tableidx, 3
  br i1 %4, label %switch.lookup, label %7

switch.lookup:                                    ; preds = %3
  %switch.cast = trunc nuw i32 %switch.tableidx to i24
  %switch.shiftamt = shl nuw nsw i24 %switch.cast, 3
  %switch.downshift = lshr i24 2559748, %switch.shiftamt
  %switch.masked = trunc i24 %switch.downshift to i8
  tail call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @MFRC522_PICC_DumpMifareClassicToSerial.str) #2
  br label %5

5:                                                ; preds = %5, %switch.lookup
  %.0 = phi i8 [ %switch.masked, %switch.lookup ], [ %6, %5 ]
  tail call void @MFRC522_PICC_DumpMifareClassicSectorToSerial(ptr noundef %0, ptr noundef %2, i8 noundef zeroext %.0)
  %6 = add i8 %.0, -1
  br label %5, !llvm.loop !5

7:                                                ; preds = %3
  %8 = tail call i32 @MFRC522_PICC_HaltA()
  tail call void @MFRC522_PCD_StopCrypto1()
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PICC_DumpMifareClassicSectorToSerial(ptr noundef, ptr noundef, i8 noundef zeroext) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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