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

@.str = external hidden unnamed_addr constant [92 x i8], align 1
@__func__.ff_fseek = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [15 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 willreturn memory(none)
declare ptr @__errno_location() #2

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

; Function Attrs: noreturn
declare void @my_assert_func(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #3

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

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.FIL, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = trunc i64 %14 to i32
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = add nsw i32 %15, %16
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %11
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %67

20:                                               ; preds = %11
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.FIL, ptr %22, i32 0, i32 3
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = add i64 %24, %26
  %28 = call i32 @f_lseek(ptr noundef %21, i64 noundef %27)
  store i32 %28, ptr %8, align 4, !tbaa !9
  br label %59

29:                                               ; preds = %3
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.FIL, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.FFOBJID, ptr %31, i32 0, i32 5
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = trunc i64 %33 to i32
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = add nsw i32 %34, %35
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %29
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %67

39:                                               ; preds = %29
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.FIL, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.FFOBJID, ptr %42, i32 0, i32 5
  %44 = load i64, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = add i64 %44, %46
  %48 = call i32 @f_lseek(ptr noundef %40, i64 noundef %47)
  store i32 %48, ptr %8, align 4, !tbaa !9
  br label %59

49:                                               ; preds = %3
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = icmp slt i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %67

53:                                               ; preds = %49
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = call i32 @f_lseek(ptr noundef %54, i64 noundef %56)
  store i32 %57, ptr %8, align 4, !tbaa !9
  br label %59

58:                                               ; preds = %3
  call void @my_assert_func(ptr noundef @.str, i32 noundef 337, ptr noundef @__func__.ff_fseek, ptr noundef @.str.5) #6
  unreachable

59:                                               ; preds = %53, %39, %20
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = call i32 @fresult2errno(i32 noundef %60)
  %62 = call ptr @__errno_location() #7
  store i32 %61, ptr %62, align 4, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = icmp eq i32 0, %63
  br i1 %64, label %65, label %66

65:                                               ; preds = %59
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %67

66:                                               ; preds = %59
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %67

67:                                               ; preds = %66, %65, %52, %38, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %68 = load i32, ptr %4, align 4
  ret i32 %68
}

declare i32 @f_lseek(ptr noundef, i64 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 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 #3 = { noreturn "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 = { noreturn }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 56}
!12 = !{!"", !13, i64 0, !7, i64 48, !7, i64 49, !15, i64 56, !10, i64 64, !15, i64 72, !15, i64 80, !6, i64 88, !6, i64 96, !7, i64 104}
!13 = !{!"", !6, i64 0, !14, i64 8, !7, i64 10, !7, i64 11, !10, i64 12, !15, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !15, i64 16}


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

@.str = external hidden unnamed_addr constant [92 x i8], align 1
@__func__.ff_fseek = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [15 x i8], align 1

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

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

; Function Attrs: noreturn
declare void @my_assert_func(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ff_fseek(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  switch i32 %2, label %29 [
    i32 1, label %4
    i32 2, label %14
    i32 0, label %24
  ]

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = trunc i64 %6 to i32
  %8 = add nsw i32 %7, %1
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %34, label %10

10:                                               ; preds = %4
  %11 = sext i32 %1 to i64
  %12 = add i64 %6, %11
  %13 = tail call i32 @f_lseek(ptr noundef nonnull %0, i64 noundef %12) #4
  br label %30

14:                                               ; preds = %3
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = trunc i64 %16 to i32
  %18 = add nsw i32 %17, %1
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %34, label %20

20:                                               ; preds = %14
  %21 = sext i32 %1 to i64
  %22 = add i64 %16, %21
  %23 = tail call i32 @f_lseek(ptr noundef nonnull %0, i64 noundef %22) #4
  br label %30

24:                                               ; preds = %3
  %25 = icmp slt i32 %1, 0
  br i1 %25, label %34, label %26

26:                                               ; preds = %24
  %27 = zext nneg i32 %1 to i64
  %28 = tail call i32 @f_lseek(ptr noundef %0, i64 noundef %27) #4
  br label %30

29:                                               ; preds = %3
  tail call void @my_assert_func(ptr noundef nonnull @.str, i32 noundef 337, ptr noundef nonnull @__func__.ff_fseek, ptr noundef nonnull @.str.5) #5
  unreachable

30:                                               ; preds = %26, %20, %10
  %.0 = phi i32 [ %28, %26 ], [ %23, %20 ], [ %13, %10 ]
  %31 = tail call i32 @fresult2errno(i32 noundef %.0)
  %32 = tail call ptr @__errno_location() #6
  store i32 %31, ptr %32, align 4, !tbaa !15
  %33 = icmp ne i32 %.0, 0
  %. = sext i1 %33 to i32
  br label %34

34:                                               ; preds = %30, %24, %14, %4
  %.016 = phi i32 [ -1, %4 ], [ -1, %14 ], [ -1, %24 ], [ %., %30 ]
  ret i32 %.016
}

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

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 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 #2 = { noreturn "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 = { "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 = { nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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, !13, i64 56}
!6 = !{!"", !7, i64 0, !9, i64 48, !9, i64 49, !13, i64 56, !12, i64 64, !13, i64 72, !13, i64 80, !8, i64 88, !8, i64 96, !9, i64 104}
!7 = !{!"", !8, i64 0, !11, i64 8, !9, i64 10, !9, i64 11, !12, i64 12, !13, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!6, !13, i64 16}
!15 = !{!12, !12, i64 0}


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