; LLVM IR from ARM-software/Arm-2D :: examples/common/platform/mps2 (stdout_USART)

; 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.CMSDK_UART_TypeDef = type { i32, i32, i32, %union.anon, i32 }
%union.anon = type { i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @stdout_putchar(i8 noundef signext %0) #0 {
  %2 = alloca i8, align 1
  store i8 %0, ptr %2, align 1, !tbaa !5
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = sext i8 %3 to i32
  %5 = icmp eq i32 %4, 10
  br i1 %5, label %6, label %8

6:                                                ; preds = %1
  %7 = call i32 @stdout_putchar(i8 noundef signext 13)
  br label %8

8:                                                ; preds = %6, %1
  br label %9

9:                                                ; preds = %14, %8
  %10 = load volatile i32, ptr getelementptr inbounds (%struct.CMSDK_UART_TypeDef, ptr inttoptr (i64 1073758208 to ptr), i32 0, i32 1), align 4, !tbaa !8
  %11 = zext i32 %10 to i64
  %12 = and i64 %11, 1
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %9
  br label %9, !llvm.loop !11

15:                                               ; preds = %9
  %16 = load i8, ptr %2, align 1, !tbaa !5
  %17 = sext i8 %16 to i32
  store volatile i32 %17, ptr inttoptr (i64 1073758208 to ptr), align 4, !tbaa !13
  %18 = load i8, ptr %2, align 1, !tbaa !5
  %19 = sext i8 %18 to i32
  ret i32 %19
}

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

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

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 -128, 128) i32 @stdout_putchar(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = icmp eq i8 %0, 10
  br i1 %2, label %.preheader, label %.preheader3

.preheader:                                       ; preds = %1, %.preheader
  %3 = load volatile i32, ptr inttoptr (i64 1073758212 to ptr), align 4, !tbaa !5
  %4 = and i32 %3, 1
  %.not.i = icmp eq i32 %4, 0
  br i1 %.not.i, label %stdout_putchar.exit, label %.preheader, !llvm.loop !10

stdout_putchar.exit:                              ; preds = %.preheader
  store volatile i32 13, ptr inttoptr (i64 1073758208 to ptr), align 16384, !tbaa !12
  br label %.preheader3

.preheader3:                                      ; preds = %stdout_putchar.exit, %1
  br label %5

5:                                                ; preds = %.preheader3, %5
  %6 = load volatile i32, ptr inttoptr (i64 1073758212 to ptr), align 4, !tbaa !5
  %7 = and i32 %6, 1
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %5, !llvm.loop !10

8:                                                ; preds = %5
  %9 = sext i8 %0 to i32
  store volatile i32 %9, ptr inttoptr (i64 1073758208 to ptr), align 16384, !tbaa !12
  ret i32 %9
}

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

!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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InlinerPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass