; LLVM IR from Stephane-D/SGDK :: src (bmp)

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

@flag = external hidden global i16, align 2
@bmp_plan = external dso_local global i32, align 4
@bmp_buffer_1 = external hidden global ptr, align 8
@bmp_buffer_read = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @BMP_showFPS(i16 noundef zeroext %0, i16 noundef zeroext %1, i16 noundef zeroext %2) #0 {
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca [16 x i8], align 16
  store i16 %0, ptr %4, align 2, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !5
  store i16 %2, ptr %6, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %8 = load i16, ptr @flag, align 2, !tbaa !5
  %9 = zext i16 %8 to i32
  %10 = and i32 %9, 1
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %16

12:                                               ; preds = %3
  %13 = load ptr, ptr @bmp_buffer_read, align 8, !tbaa !9
  %14 = load ptr, ptr @bmp_buffer_1, align 8, !tbaa !9
  %15 = icmp eq ptr %13, %14
  br label %16

16:                                               ; preds = %12, %3
  %17 = phi i1 [ false, %3 ], [ %15, %12 ]
  %18 = zext i1 %17 to i64
  %19 = select i1 %17, i32 36, i32 4
  %20 = load i16, ptr %6, align 2, !tbaa !5
  %21 = zext i16 %20 to i32
  %22 = add nsw i32 %19, %21
  %23 = trunc i32 %22 to i16
  store i16 %23, ptr %6, align 2, !tbaa !5
  %24 = load i16, ptr %4, align 2, !tbaa !5
  %25 = icmp ne i16 %24, 0
  br i1 %25, label %26, label %33

26:                                               ; preds = %16
  %27 = call i64 @SYS_getFPSAsFloat()
  %28 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  call void @fix32ToStr(i64 noundef %27, ptr noundef %28, i16 noundef zeroext 1)
  %29 = load i32, ptr @bmp_plan, align 4, !tbaa !11
  %30 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  %31 = load i16, ptr %5, align 2, !tbaa !5
  %32 = load i16, ptr %6, align 2, !tbaa !5
  call void @VDP_drawTextBGFill(i32 noundef %29, ptr noundef %30, i16 noundef zeroext %31, i16 noundef zeroext %32, i16 noundef zeroext 4)
  br label %41

33:                                               ; preds = %16
  %34 = call i64 @SYS_getFPS()
  %35 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  %36 = call zeroext i16 @uintToStr(i64 noundef %34, ptr noundef %35, i16 noundef zeroext 1)
  %37 = load i32, ptr @bmp_plan, align 4, !tbaa !11
  %38 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  %39 = load i16, ptr %5, align 2, !tbaa !5
  %40 = load i16, ptr %6, align 2, !tbaa !5
  call void @VDP_drawTextBGFill(i32 noundef %37, ptr noundef %38, i16 noundef zeroext %39, i16 noundef zeroext %40, i16 noundef zeroext 2)
  br label %41

41:                                               ; preds = %33, %26
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  ret void
}

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

declare void @fix32ToStr(i64 noundef, ptr noundef, i16 noundef zeroext) #2

declare i64 @SYS_getFPSAsFloat() #2

declare void @VDP_drawTextBGFill(i32 noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) #2

declare zeroext i16 @uintToStr(i64 noundef, ptr noundef, i16 noundef zeroext) #2

declare i64 @SYS_getFPS() #2

; 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 = { "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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, 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"

@flag = external hidden local_unnamed_addr global i16, align 2
@bmp_plan = external dso_local local_unnamed_addr global i32, align 4
@bmp_buffer_1 = external hidden local_unnamed_addr global ptr, align 8
@bmp_buffer_read = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @BMP_showFPS(i16 noundef zeroext %0, i16 noundef zeroext %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = load i16, ptr @flag, align 2, !tbaa !5
  %6 = load ptr, ptr @bmp_buffer_read, align 8
  %7 = load ptr, ptr @bmp_buffer_1, align 8
  %.not = icmp eq i16 %0, 0
  br i1 %.not, label %10, label %8

8:                                                ; preds = %3
  %9 = tail call i64 @SYS_getFPSAsFloat() #3
  call void @fix32ToStr(i64 noundef %9, ptr noundef nonnull %4, i16 noundef zeroext 1) #3
  br label %13

10:                                               ; preds = %3
  %11 = tail call i64 @SYS_getFPS() #3
  %12 = call zeroext i16 @uintToStr(i64 noundef %11, ptr noundef nonnull %4, i16 noundef zeroext 1) #3
  br label %13

13:                                               ; preds = %10, %8
  %.sink6 = phi i16 [ 2, %10 ], [ 4, %8 ]
  %14 = and i16 %5, 1
  %15 = icmp ne i16 %14, 0
  %16 = icmp eq ptr %6, %7
  %17 = select i1 %15, i1 %16, i1 false
  %18 = select i1 %17, i16 36, i16 4
  %19 = add i16 %18, %2
  %20 = load i32, ptr @bmp_plan, align 4, !tbaa !9
  call void @VDP_drawTextBGFill(i32 noundef %20, ptr noundef nonnull %4, i16 noundef zeroext %1, i16 noundef zeroext %19, i16 noundef zeroext %.sink6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  ret void
}

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

declare void @fix32ToStr(i64 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

declare i64 @SYS_getFPSAsFloat() local_unnamed_addr #2

declare void @VDP_drawTextBGFill(i32 noundef, ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #2

declare zeroext i16 @uintToStr(i64 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

declare i64 @SYS_getFPS() local_unnamed_addr #2

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


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