; LLVM IR from alekras/ao.rtos.cpp :: Tools/ARM-Raspberry_Pi/loadable-app (main)

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

%class.FormatParser = type { %class.Fsm, ptr, ptr, i32, i32, [1 x %struct.__va_list_tag] }
%class.Fsm = type { { i64, i64 } }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }
%class.Gpio = type { i32, i32, i32, i32 }

@out = external dso_local global [200 x i8], align 16
@fp = external dso_local global %class.FormatParser, align 8
@gpio47 = external global ptr, align 8
@gpio10 = external global ptr, align 8
@gpio22 = external global ptr, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %class.Gpio, align 4
  %4 = alloca %class.Gpio, align 4
  %5 = alloca %class.Gpio, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  call void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16) %3, i32 noundef 47)
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  call void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16) %4, i32 noundef 10)
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  call void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16) %5, i32 noundef 22)
  store ptr %3, ptr @gpio47, align 8, !tbaa !5
  store ptr %4, ptr @gpio10, align 8, !tbaa !5
  store ptr %5, ptr @gpio22, align 8, !tbaa !5
  call void @irq_vectors_setup()
  call void @arm_timer_setup(i32 noundef 500)
  call void @led_setup()
  call void @uart_init()
  call void @dump_debug_init()
  call void @enable_irq()
  call void @sendString(ptr noundef @.str)
  call void @sendString(ptr noundef @.str.1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 16777215, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %19, %0
  br label %9

9:                                                ; preds = %10, %8
  br label %10

10:                                               ; preds = %9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = add i32 %11, -1
  store i32 %12, ptr %6, align 4, !tbaa !9
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %9, label %14, !llvm.loop !11

14:                                               ; preds = %10
  %15 = call ptr @get_sp()
  store ptr %15, ptr %2, align 8, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = add i32 %16, 1
  store i32 %17, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @_ZN12FormatParser6formatEPcPKcz(ptr noundef nonnull align 8 dereferenceable(64) @fp, ptr noundef @out, ptr noundef @.str.2, i32 noundef %16, ptr noundef %18)
  call void @sendString(ptr noundef @out)
  store i32 16777215, ptr %6, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %14
  br i1 true, label %8, label %20, !llvm.loop !13

20:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16), i32 noundef) unnamed_addr #2 align 2

declare void @irq_vectors_setup() #3

declare void @arm_timer_setup(i32 noundef) #3

declare void @led_setup() #3

declare void @uart_init() #3

declare void @dump_debug_init() #3

declare void @enable_irq() #3

declare void @sendString(ptr noundef) #3

declare ptr @get_sp() #3

declare void @_ZN12FormatParser6formatEPcPKcz(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, ptr noundef, ...) #3

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

attributes #0 = { mustprogress norecurse 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 = { mustprogress 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 #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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

%class.FormatParser = type { %class.Fsm, ptr, ptr, i32, i32, [1 x %struct.__va_list_tag] }
%class.Fsm = type { { i64, i64 } }
%struct.__va_list_tag = type { i32, i32, ptr, ptr }
%class.Gpio = type { i32, i32, i32, i32 }

@out = external dso_local global [200 x i8], align 16
@fp = external dso_local global %class.FormatParser, align 8
@gpio47 = external local_unnamed_addr global ptr, align 8
@gpio10 = external local_unnamed_addr global ptr, align 8
@gpio22 = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress norecurse noreturn uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %class.Gpio, align 4
  %2 = alloca %class.Gpio, align 4
  %3 = alloca %class.Gpio, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  call void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16) %1, i32 noundef 47)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  call void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16) %2, i32 noundef 10)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16) %3, i32 noundef 22)
  store ptr %1, ptr @gpio47, align 8, !tbaa !5
  store ptr %2, ptr @gpio10, align 8, !tbaa !5
  store ptr %3, ptr @gpio22, align 8, !tbaa !5
  call void @irq_vectors_setup()
  call void @arm_timer_setup(i32 noundef 500)
  call void @led_setup()
  call void @uart_init()
  call void @dump_debug_init()
  call void @enable_irq()
  call void @sendString(ptr noundef nonnull @.str)
  call void @sendString(ptr noundef nonnull @.str.1)
  br label %4

4:                                                ; preds = %4, %0
  %.0 = phi i32 [ 0, %0 ], [ %6, %4 ]
  %5 = call ptr @get_sp()
  %6 = add i32 %.0, 1
  call void (ptr, ptr, ptr, ...) @_ZN12FormatParser6formatEPcPKcz(ptr noundef nonnull align 8 dereferenceable(64) @fp, ptr noundef nonnull @out, ptr noundef nonnull @.str.2, i32 noundef %.0, ptr noundef %5)
  call void @sendString(ptr noundef nonnull @out)
  br label %4, !llvm.loop !9
}

; 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 nounwind uwtable
declare dso_local void @_ZN4GpioC2Ei(ptr noundef nonnull align 4 dereferenceable(16), i32 noundef) unnamed_addr #2 align 2

declare void @irq_vectors_setup() local_unnamed_addr #3

declare void @arm_timer_setup(i32 noundef) local_unnamed_addr #3

declare void @led_setup() local_unnamed_addr #3

declare void @uart_init() local_unnamed_addr #3

declare void @dump_debug_init() local_unnamed_addr #3

declare void @enable_irq() local_unnamed_addr #3

declare void @sendString(ptr noundef) local_unnamed_addr #3

declare ptr @get_sp() local_unnamed_addr #3

declare void @_ZN12FormatParser6formatEPcPKcz(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, ptr noundef, ...) local_unnamed_addr #3

attributes #0 = { mustprogress norecurse noreturn 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 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 #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 }

!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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass