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

%struct.MIFARE_Key = type { [6 x i8] }
%struct.MFRC522_Uid = type { i8, [10 x i8], i8 }

@MFRC522_PICC_DumpToSerial.str = external hidden constant [60 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 i32 @MFRC522_PICC_GetType(i8 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @MFRC522_PICC_DumpToSerial(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.MIFARE_Key, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 6, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  call void @MFRC522_PICC_DumpDetailsToSerial(ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MFRC522_Uid, ptr %7, i32 0, i32 2
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = call i32 @MFRC522_PICC_GetType(i8 noundef zeroext %9)
  store i32 %10, ptr %5, align 4, !tbaa !11
  %11 = load i32, ptr %5, align 4, !tbaa !11
  switch i32 %11, label %34 [
    i32 3, label %12
    i32 4, label %12
    i32 5, label %12
    i32 6, label %28
    i32 1, label %29
    i32 2, label %29
    i32 7, label %29
    i32 8, label %29
    i32 0, label %33
    i32 255, label %33
  ]

12:                                               ; preds = %1, %1, %1
  store i8 0, ptr %4, align 1, !tbaa !13
  br label %13

13:                                               ; preds = %22, %12
  %14 = load i8, ptr %4, align 1, !tbaa !13
  %15 = zext i8 %14 to i32
  %16 = icmp slt i32 %15, 6
  br i1 %16, label %17, label %25

17:                                               ; preds = %13
  %18 = getelementptr inbounds %struct.MIFARE_Key, ptr %3, i32 0, i32 0
  %19 = load i8, ptr %4, align 1, !tbaa !13
  %20 = zext i8 %19 to i64
  %21 = getelementptr inbounds [6 x i8], ptr %18, i64 0, i64 %20
  store i8 -1, ptr %21, align 1, !tbaa !13
  br label %22

22:                                               ; preds = %17
  %23 = load i8, ptr %4, align 1, !tbaa !13
  %24 = add i8 %23, 1
  store i8 %24, ptr %4, align 1, !tbaa !13
  br label %13, !llvm.loop !14

25:                                               ; preds = %13
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !11
  call void @MFRC522_PICC_DumpMifareClassicToSerial(ptr noundef %26, i32 noundef %27, ptr noundef %3)
  br label %35

28:                                               ; preds = %1
  call void @MFRC522_PICC_DumpMifareUltralightToSerial()
  br label %35

29:                                               ; preds = %1, %1, %1, %1
  br label %30

30:                                               ; preds = %29
  call void (ptr, ...) @dhdebug_ram(ptr noundef @MFRC522_PICC_DumpToSerial.str)
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %35

33:                                               ; preds = %1, %1
  br label %34

34:                                               ; preds = %33, %1
  br label %35

35:                                               ; preds = %34, %32, %28, %25
  %36 = call i32 @MFRC522_PICC_HaltA()
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 6, ptr %3) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PICC_DumpDetailsToSerial(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PICC_DumpMifareClassicToSerial(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PICC_DumpMifareUltralightToSerial() #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, !7, i64 11}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 11}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%struct.MIFARE_Key = type { [6 x i8] }

@MFRC522_PICC_DumpToSerial.str = external hidden constant [60 x i8], align 4

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

; Function Attrs: mustprogress 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() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @MFRC522_PICC_GetType(i8 noundef zeroext) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @MFRC522_PICC_DumpToSerial(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.MIFARE_Key, align 1
  call void @llvm.lifetime.start.p0(i64 6, ptr nonnull %2) #4
  tail call void @MFRC522_PICC_DumpDetailsToSerial(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 11
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = tail call i32 @MFRC522_PICC_GetType(i8 noundef zeroext %4)
  switch i32 %5, label %9 [
    i32 3, label %6
    i32 4, label %6
    i32 5, label %6
    i32 6, label %7
    i32 1, label %8
    i32 2, label %8
    i32 7, label %8
    i32 8, label %8
  ]

6:                                                ; preds = %1, %1, %1
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %2, i8 -1, i64 6, i1 false), !tbaa !9
  call void @MFRC522_PICC_DumpMifareClassicToSerial(ptr noundef nonnull %0, i32 noundef %5, ptr noundef nonnull %2)
  br label %9

7:                                                ; preds = %1
  tail call void @MFRC522_PICC_DumpMifareUltralightToSerial()
  br label %9

8:                                                ; preds = %1, %1, %1, %1
  tail call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @MFRC522_PICC_DumpToSerial.str) #4
  br label %9

9:                                                ; preds = %1, %8, %7, %6
  %10 = call i32 @MFRC522_PICC_HaltA()
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %2) #4
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @MFRC522_PICC_DumpMifareClassicToSerial(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !7, i64 11}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 11}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass