; LLVM IR from ARM-software/Arm-2D :: Helper/Source (arm_2d_helper_font)

; 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.anon.13 = type { %struct.arm_2d_region_t, %struct.arm_2d_region_t, %struct.arm_2d_location_t, %struct.anon.14, ptr, i32, i32, i8, i8, %struct.anon.15, %struct.anon.16, %struct.anon.17, %struct.arm_2d_scratch_mem_t, %struct.arm_2d_region_t, ptr }
%struct.arm_2d_location_t = type { i16, i16 }
%struct.anon.14 = type { i16, i16 }
%struct.anon.15 = type { i8, i8 }
%struct.anon.16 = type { %struct.arm_2d_size_t, %struct.arm_2d_size_t, %struct.arm_2d_region_t }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.anon.17 = type { %union.anon.18, i16, i16, [65 x i8] }
%union.anon.18 = type { i16 }
%struct.arm_2d_scratch_mem_t = type { %union.anon.19, i64 }
%union.anon.19 = type { %union.anon.20 }
%union.anon.20 = type { %struct.anon.21 }
%struct.anon.21 = type { i32 }
%struct.arm_2d_region_t = type { %union.anon.10, %union.anon.11 }
%union.anon.10 = type { %struct.arm_2d_location_t }
%union.anon.11 = type { %struct.arm_2d_size_t }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }

@s_tLCDTextControl = external hidden global %struct.anon.13, align 8

; 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 @arm_lcd_text_set_font(ptr noundef) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: nounwind
declare i32 @vsnprintf(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_lcd_printf_to_buffer(ptr noundef %0, ptr noundef %1, ...) #1 {
  %3 = alloca %struct.arm_2d_size_t, align 2
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca [1 x %struct.__va_list_tag], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  %8 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %8)
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  %11 = call i32 @vsnprintf(ptr noundef getelementptr inbounds (%struct.anon.17, ptr getelementptr inbounds (%struct.anon.13, ptr @s_tLCDTextControl, i32 0, i32 11), i32 0, i32 3), i64 noundef 64, ptr noundef %9, ptr noundef %10) #4
  %12 = sext i32 %11 to i64
  store i64 %12, ptr %6, align 8, !tbaa !9
  %13 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %13)
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ult i64 64, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  br label %19

17:                                               ; preds = %2
  %18 = load i64, ptr %6, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %17, %16
  %20 = phi i64 [ 64, %16 ], [ %18, %17 ]
  store i64 %20, ptr %6, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds [65 x i8], ptr getelementptr inbounds (%struct.anon.17, ptr getelementptr inbounds (%struct.anon.13, ptr @s_tLCDTextControl, i32 0, i32 11), i32 0, i32 3), i64 0, i64 %21
  store i8 0, ptr %22, align 1, !tbaa !11
  store i16 0, ptr getelementptr inbounds (%struct.anon.13, ptr @s_tLCDTextControl, i32 0, i32 11), align 4, !tbaa !11
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = trunc i64 %23 to i16
  store i16 %24, ptr getelementptr inbounds (%struct.anon.17, ptr getelementptr inbounds (%struct.anon.13, ptr @s_tLCDTextControl, i32 0, i32 11), i32 0, i32 2), align 4, !tbaa !12
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = trunc i64 %25 to i16
  store i16 %26, ptr getelementptr inbounds (%struct.anon.17, ptr getelementptr inbounds (%struct.anon.13, ptr @s_tLCDTextControl, i32 0, i32 11), i32 0, i32 1), align 2, !tbaa !24
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call i32 @arm_lcd_text_set_font(ptr noundef %27)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i32 @__arm_lcd_get_string_line_box(ptr noundef getelementptr inbounds (%struct.anon.17, ptr getelementptr inbounds (%struct.anon.13, ptr @s_tLCDTextControl, i32 0, i32 11), i32 0, i32 3), ptr noundef %29)
  store i32 %30, ptr %3, align 2
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %31 = load i32, ptr %3, align 2
  ret i32 %31
}

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nounwind "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 }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !16, i64 64}
!13 = !{!"", !14, i64 0, !14, i64 8, !15, i64 16, !17, i64 20, !6, i64 24, !18, i64 32, !18, i64 36, !7, i64 40, !7, i64 41, !19, i64 42, !20, i64 44, !22, i64 60, !23, i64 136, !14, i64 152, !6, i64 160}
!14 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!15 = !{!"arm_2d_location_t", !16, i64 0, !16, i64 2}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !16, i64 0, !16, i64 2}
!18 = !{!"int", !7, i64 0}
!19 = !{!"", !7, i64 0, !7, i64 1}
!20 = !{!"", !21, i64 0, !21, i64 4, !14, i64 8}
!21 = !{!"arm_2d_size_t", !16, i64 0, !16, i64 2}
!22 = !{!"", !7, i64 0, !16, i64 2, !16, i64 4, !7, i64 6}
!23 = !{!"arm_2d_scratch_mem_t", !7, i64 0, !10, i64 8}
!24 = !{!13, !16, i64 62}


; 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.anon.13 = type { %struct.arm_2d_region_t, %struct.arm_2d_region_t, %struct.arm_2d_location_t, %struct.anon.14, ptr, i32, i32, i8, i8, %struct.anon.15, %struct.anon.16, %struct.anon.17, %struct.arm_2d_scratch_mem_t, %struct.arm_2d_region_t, ptr }
%struct.arm_2d_location_t = type { i16, i16 }
%struct.anon.14 = type { i16, i16 }
%struct.anon.15 = type { i8, i8 }
%struct.anon.16 = type { %struct.arm_2d_size_t, %struct.arm_2d_size_t, %struct.arm_2d_region_t }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.anon.17 = type { %union.anon.18, i16, i16, [65 x i8] }
%union.anon.18 = type { i16 }
%struct.arm_2d_scratch_mem_t = type { %union.anon.19, i64 }
%union.anon.19 = type { %union.anon.20 }
%union.anon.20 = type { %struct.anon.21 }
%struct.anon.21 = type { i32 }
%struct.arm_2d_region_t = type { %union.anon.10, %union.anon.11 }
%union.anon.10 = type { %struct.arm_2d_location_t }
%union.anon.11 = type { %struct.arm_2d_size_t }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }

@s_tLCDTextControl = external hidden global %struct.anon.13, align 8

; 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 @arm_lcd_text_set_font(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: nofree nounwind
declare noundef i32 @vsnprintf(ptr nocapture noundef, i64 noundef, ptr nocapture noundef readonly, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_lcd_printf_to_buffer(ptr noundef %0, ptr nocapture noundef readonly %1, ...) local_unnamed_addr #1 {
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.va_start.p0(ptr nonnull %3)
  %4 = call i32 @vsnprintf(ptr noundef nonnull getelementptr inbounds (i8, ptr @s_tLCDTextControl, i64 66), i64 noundef 64, ptr noundef %1, ptr noundef nonnull %3) #5
  call void @llvm.va_end.p0(ptr nonnull %3)
  %5 = call i32 @llvm.umin.i32(i32 %4, i32 64)
  %6 = zext nneg i32 %5 to i64
  %7 = getelementptr inbounds [65 x i8], ptr getelementptr inbounds (i8, ptr @s_tLCDTextControl, i64 66), i64 0, i64 %6
  store i8 0, ptr %7, align 1, !tbaa !5
  store i16 0, ptr getelementptr inbounds (i8, ptr @s_tLCDTextControl, i64 60), align 4, !tbaa !5
  %8 = trunc nuw nsw i32 %5 to i16
  store i16 %8, ptr getelementptr inbounds (i8, ptr @s_tLCDTextControl, i64 64), align 8, !tbaa !8
  store i16 %8, ptr getelementptr inbounds (i8, ptr @s_tLCDTextControl, i64 62), align 2, !tbaa !22
  %9 = call i32 @arm_lcd_text_set_font(ptr noundef %0)
  %10 = call i32 @__arm_lcd_get_string_line_box(ptr noundef nonnull getelementptr inbounds (i8, ptr @s_tLCDTextControl, i64 66), ptr noundef %0)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret i32 %10
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { nofree nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !12, i64 64}
!9 = !{!"", !10, i64 0, !10, i64 8, !11, i64 16, !13, i64 20, !14, i64 24, !15, i64 32, !15, i64 36, !6, i64 40, !6, i64 41, !16, i64 42, !17, i64 44, !19, i64 60, !20, i64 136, !10, i64 152, !14, i64 160}
!10 = !{!"arm_2d_region_t", !6, i64 0, !6, i64 4}
!11 = !{!"arm_2d_location_t", !12, i64 0, !12, i64 2}
!12 = !{!"short", !6, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 2}
!14 = !{!"any pointer", !6, i64 0}
!15 = !{!"int", !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 1}
!17 = !{!"", !18, i64 0, !18, i64 4, !10, i64 8}
!18 = !{!"arm_2d_size_t", !12, i64 0, !12, i64 2}
!19 = !{!"", !6, i64 0, !12, i64 2, !12, i64 4, !6, i64 6}
!20 = !{!"arm_2d_scratch_mem_t", !6, i64 0, !21, i64 8}
!21 = !{!"long", !6, i64 0}
!22 = !{!9, !12, i64 62}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass