; LLVM IR from carlk3/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico :: src/src (ff_stdio)

; 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.FIL = type { %struct.FFOBJID, i8, i8, i64, i32, i64, i64, ptr, ptr, [512 x i8] }
%struct.FFOBJID = type { ptr, i16, i8, i8, i32, i64, i32, i32, i32, i32, i32, i32 }

@__func__.ff_truncate = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @fresult2errno(i32 noundef) #0

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

declare i32 @f_open(ptr noundef, ptr noundef, i8 noundef zeroext) #4

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

declare i32 @f_write(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

declare i32 @f_lseek(ptr noundef, i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @ff_truncate(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %11 = call noalias ptr @malloc(i64 noundef 616) #6
  store ptr %11, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %16, label %14

14:                                               ; preds = %2
  %15 = call ptr @__errno_location() #7
  store i32 12, ptr %15, align 4, !tbaa !11
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %96

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call i32 @f_open(ptr noundef %17, ptr noundef %18, i8 noundef zeroext 50)
  store i32 %19, ptr %8, align 4, !tbaa !11
  %20 = load i32, ptr %8, align 4, !tbaa !11
  %21 = icmp ne i32 0, %20
  br i1 %21, label %22, label %27

22:                                               ; preds = %16
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = call ptr @FRESULT_str(i32 noundef %23)
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = call i32 (ptr, i32, ptr, ...) @error_message_printf(ptr noundef @__func__.ff_truncate, i32 noundef 408, ptr noundef @.str.7, ptr noundef @__func__.ff_truncate, ptr noundef %24, i32 noundef %25)
  br label %27

27:                                               ; preds = %22, %16
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = call i32 @fresult2errno(i32 noundef %28)
  %30 = call ptr @__errno_location() #7
  store i32 %29, ptr %30, align 4, !tbaa !11
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = icmp ne i32 0, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %95

34:                                               ; preds = %27
  br label %35

35:                                               ; preds = %57, %34
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.FIL, ptr %36, i32 0, i32 3
  %38 = load i64, ptr %37, align 8, !tbaa !13
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %41, label %58

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  store i8 0, ptr %10, align 1, !tbaa !17
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i32 @f_write(ptr noundef %42, ptr noundef %10, i32 noundef 1, ptr noundef %9)
  store i32 %43, ptr %8, align 4, !tbaa !11
  %44 = load i32, ptr %8, align 4, !tbaa !11
  %45 = icmp ne i32 0, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %41
  br label %47

47:                                               ; preds = %46, %41
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = call i32 @fresult2errno(i32 noundef %48)
  %50 = call ptr @__errno_location() #7
  store i32 %49, ptr %50, align 4, !tbaa !11
  %51 = load i32, ptr %9, align 4, !tbaa !11
  %52 = icmp ne i32 1, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %47
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %55

54:                                               ; preds = %47
  store i32 0, ptr %7, align 4
  br label %55

55:                                               ; preds = %54, %53
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  %56 = load i32, ptr %7, align 4
  switch i32 %56, label %95 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %35, !llvm.loop !18

58:                                               ; preds = %35
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !9
  %61 = call i32 @f_lseek(ptr noundef %59, i64 noundef %60)
  store i32 %61, ptr %8, align 4, !tbaa !11
  %62 = load i32, ptr %8, align 4, !tbaa !11
  %63 = call i32 @fresult2errno(i32 noundef %62)
  %64 = call ptr @__errno_location() #7
  store i32 %63, ptr %64, align 4, !tbaa !11
  %65 = load i32, ptr %8, align 4, !tbaa !11
  %66 = icmp ne i32 0, %65
  br i1 %66, label %67, label %72

67:                                               ; preds = %58
  %68 = load i32, ptr %8, align 4, !tbaa !11
  %69 = call ptr @FRESULT_str(i32 noundef %68)
  %70 = load i32, ptr %8, align 4, !tbaa !11
  %71 = call i32 (ptr, i32, ptr, ...) @error_message_printf(ptr noundef @__func__.ff_truncate, i32 noundef 423, ptr noundef @.str.8, ptr noundef @__func__.ff_truncate, ptr noundef %69, i32 noundef %70)
  br label %72

72:                                               ; preds = %67, %58
  %73 = load i32, ptr %8, align 4, !tbaa !11
  %74 = icmp ne i32 0, %73
  br i1 %74, label %75, label %76

75:                                               ; preds = %72
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %95

76:                                               ; preds = %72
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = call i32 @f_truncate(ptr noundef %77)
  store i32 %78, ptr %8, align 4, !tbaa !11
  %79 = load i32, ptr %8, align 4, !tbaa !11
  %80 = icmp ne i32 0, %79
  br i1 %80, label %81, label %86

81:                                               ; preds = %76
  %82 = load i32, ptr %8, align 4, !tbaa !11
  %83 = call ptr @FRESULT_str(i32 noundef %82)
  %84 = load i32, ptr %8, align 4, !tbaa !11
  %85 = call i32 (ptr, i32, ptr, ...) @error_message_printf(ptr noundef @__func__.ff_truncate, i32 noundef 428, ptr noundef @.str.9, ptr noundef @__func__.ff_truncate, ptr noundef %83, i32 noundef %84)
  br label %86

86:                                               ; preds = %81, %76
  %87 = load i32, ptr %8, align 4, !tbaa !11
  %88 = call i32 @fresult2errno(i32 noundef %87)
  %89 = call ptr @__errno_location() #7
  store i32 %88, ptr %89, align 4, !tbaa !11
  %90 = load i32, ptr %8, align 4, !tbaa !11
  %91 = icmp eq i32 0, %90
  br i1 %91, label %92, label %94

92:                                               ; preds = %86
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %93, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %95

94:                                               ; preds = %86
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %95

95:                                               ; preds = %94, %92, %75, %55, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %96

96:                                               ; preds = %95, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %97 = load ptr, ptr %3, align 8
  ret ptr %97
}

declare i32 @error_message_printf(ptr noundef, i32 noundef, ptr noundef, ...) #4

declare ptr @FRESULT_str(i32 noundef) #4

declare i32 @f_truncate(ptr noundef) #4

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 allocsize(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 willreturn memory(none) "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 #4 = { "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { nounwind willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 56}
!14 = !{!"", !15, i64 0, !7, i64 48, !7, i64 49, !10, i64 56, !12, i64 64, !10, i64 72, !10, i64 80, !6, i64 88, !6, i64 96, !7, i64 104}
!15 = !{!"", !6, i64 0, !16, i64 8, !7, i64 10, !7, i64 11, !12, i64 12, !10, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!16 = !{!"short", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@__func__.ff_truncate = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

declare i32 @f_open(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #4

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

declare i32 @f_write(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

declare i32 @f_lseek(ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @ff_truncate(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = tail call noalias dereferenceable_or_null(616) ptr @malloc(i64 noundef 616) #5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call ptr @__errno_location() #6
  store i32 12, ptr %7, align 4, !tbaa !5
  br label %.loopexit

8:                                                ; preds = %2
  %9 = tail call i32 @f_open(ptr noundef nonnull %5, ptr noundef %0, i8 noundef zeroext 50) #7
  %.not34 = icmp eq i32 %9, 0
  br i1 %.not34, label %13, label %10

10:                                               ; preds = %8
  %11 = tail call ptr @FRESULT_str(i32 noundef %9) #7
  %12 = tail call i32 (ptr, i32, ptr, ...) @error_message_printf(ptr noundef nonnull @__func__.ff_truncate, i32 noundef 408, ptr noundef nonnull @.str.7, ptr noundef nonnull @__func__.ff_truncate, ptr noundef %11, i32 noundef %9) #7
  br label %13

13:                                               ; preds = %10, %8
  %14 = tail call i32 @fresult2errno(i32 noundef %9)
  %15 = tail call ptr @__errno_location() #6
  store i32 %14, ptr %15, align 4, !tbaa !5
  br i1 %.not34, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %13
  %16 = getelementptr inbounds i8, ptr %5, i64 56
  br label %17

17:                                               ; preds = %.preheader, %20
  %18 = load i64, ptr %16, align 8, !tbaa !9
  %19 = icmp ult i64 %18, %1
  br i1 %19, label %20, label %24

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #7
  store i8 0, ptr %4, align 1, !tbaa !15
  %21 = call i32 @f_write(ptr noundef nonnull %5, ptr noundef nonnull %4, i32 noundef 1, ptr noundef nonnull %3) #7
  %22 = call i32 @fresult2errno(i32 noundef %21)
  store i32 %22, ptr %15, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %.not37 = icmp eq i32 %23, 1
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #7
  br i1 %.not37, label %17, label %.loopexit, !llvm.loop !16

24:                                               ; preds = %17
  %25 = call i32 @f_lseek(ptr noundef nonnull %5, i64 noundef %1) #7
  %26 = call i32 @fresult2errno(i32 noundef %25)
  store i32 %26, ptr %15, align 4, !tbaa !5
  %.not35 = icmp eq i32 %25, 0
  br i1 %.not35, label %.critedge, label %27

27:                                               ; preds = %24
  %28 = call ptr @FRESULT_str(i32 noundef %25) #7
  %29 = call i32 (ptr, i32, ptr, ...) @error_message_printf(ptr noundef nonnull @__func__.ff_truncate, i32 noundef 423, ptr noundef nonnull @.str.8, ptr noundef nonnull @__func__.ff_truncate, ptr noundef %28, i32 noundef %25) #7
  br label %.loopexit

.critedge:                                        ; preds = %24
  %30 = call i32 @f_truncate(ptr noundef nonnull %5) #7
  %.not36 = icmp eq i32 %30, 0
  br i1 %.not36, label %34, label %31

31:                                               ; preds = %.critedge
  %32 = call ptr @FRESULT_str(i32 noundef %30) #7
  %33 = call i32 (ptr, i32, ptr, ...) @error_message_printf(ptr noundef nonnull @__func__.ff_truncate, i32 noundef 428, ptr noundef nonnull @.str.9, ptr noundef nonnull @__func__.ff_truncate, ptr noundef %32, i32 noundef %30) #7
  br label %34

34:                                               ; preds = %31, %.critedge
  %. = phi ptr [ null, %31 ], [ %5, %.critedge ]
  %35 = call i32 @fresult2errno(i32 noundef %30)
  store i32 %35, ptr %15, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %20, %27, %13, %34, %6
  %.3 = phi ptr [ null, %6 ], [ null, %13 ], [ null, %27 ], [ %., %34 ], [ null, %20 ]
  ret ptr %.3
}

declare i32 @error_message_printf(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #4

declare ptr @FRESULT_str(i32 noundef) local_unnamed_addr #4

declare i32 @f_truncate(ptr noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #4 = { "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 #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind willreturn memory(none) }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 56}
!10 = !{!"", !11, i64 0, !7, i64 48, !7, i64 49, !14, i64 56, !6, i64 64, !14, i64 72, !14, i64 80, !12, i64 88, !12, i64 96, !7, i64 104}
!11 = !{!"", !12, i64 0, !13, i64 8, !7, i64 10, !7, i64 11, !6, i64 12, !14, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass