; LLVM IR from eclipse-threadx/threadx :: ports_smp/cortex_a5x_smp/green/example_build/sample_threadx (stdio_ghs)

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

; Function Attrs: nounwind uwtable
define dso_local i64 @write(i32 noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i64 -1, ptr %4, align 8
  br label %48

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %15, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %16 = load ptr, ptr %8, align 8, !tbaa !9
  %17 = load i64, ptr %7, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  store ptr %18, ptr %9, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %43, %14
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = load ptr, ptr %9, align 8, !tbaa !9
  %22 = icmp ult ptr %20, %21
  br i1 %22, label %23, label %46

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #2
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %24, i32 1
  store ptr %25, ptr %8, align 8, !tbaa !9
  %26 = load i8, ptr %24, align 1, !tbaa !13
  store i8 %26, ptr %10, align 1, !tbaa !13
  %27 = load i8, ptr %10, align 1, !tbaa !13
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 10
  br i1 %29, label %30, label %37

30:                                               ; preds = %23
  br label %31

31:                                               ; preds = %35, %30
  %32 = load volatile i32, ptr inttoptr (i64 4278190124 to ptr), align 4, !tbaa !5
  %33 = and i32 %32, 16
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  br label %31, !llvm.loop !14

36:                                               ; preds = %31
  store volatile i32 13, ptr inttoptr (i64 4278190128 to ptr), align 4, !tbaa !5
  br label %37

37:                                               ; preds = %36, %23
  br label %38

38:                                               ; preds = %42, %37
  %39 = load volatile i32, ptr inttoptr (i64 4278190124 to ptr), align 4, !tbaa !5
  %40 = and i32 %39, 16
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  br label %38, !llvm.loop !16

43:                                               ; preds = %38
  %44 = load i8, ptr %10, align 1, !tbaa !13
  %45 = sext i8 %44 to i32
  store volatile i32 %45, ptr inttoptr (i64 4278190128 to ptr), align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  br label %19, !llvm.loop !17

46:                                               ; preds = %19
  %47 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %47, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %48

48:                                               ; preds = %46, %13
  %49 = load i64, ptr %4, align 8
  ret i64 %49
}

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

; 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 = { 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 = !{!"int", !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 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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 noundef i64 @write(i32 noundef %0, ptr noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 1
  br i1 %.not, label %4, label %.loopexit

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 %2
  %6 = icmp sgt i64 %2, 0
  br i1 %6, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4, %17
  %.01013 = phi ptr [ %7, %17 ], [ %1, %4 ]
  %7 = getelementptr inbounds i8, ptr %.01013, i64 1
  %8 = load i8, ptr %.01013, align 1, !tbaa !5
  %9 = sext i8 %8 to i32
  %10 = icmp eq i8 %8, 10
  br i1 %10, label %.preheader, label %.preheader14

.preheader:                                       ; preds = %.lr.ph, %.preheader
  %11 = load volatile i32, ptr inttoptr (i64 4278190124 to ptr), align 4, !tbaa !8
  %12 = and i32 %11, 16
  %.not11 = icmp eq i32 %12, 0
  br i1 %.not11, label %13, label %.preheader, !llvm.loop !10

13:                                               ; preds = %.preheader
  store volatile i32 13, ptr inttoptr (i64 4278190128 to ptr), align 16, !tbaa !8
  br label %.preheader14

.preheader14:                                     ; preds = %13, %.lr.ph
  br label %14

14:                                               ; preds = %.preheader14, %14
  %15 = load volatile i32, ptr inttoptr (i64 4278190124 to ptr), align 4, !tbaa !8
  %16 = and i32 %15, 16
  %.not12 = icmp eq i32 %16, 0
  br i1 %.not12, label %17, label %14, !llvm.loop !12

17:                                               ; preds = %14
  store volatile i32 %9, ptr inttoptr (i64 4278190128 to ptr), align 16, !tbaa !8
  %18 = icmp ult ptr %7, %5
  br i1 %18, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %17, %4, %3
  %.0 = phi i64 [ -1, %3 ], [ %2, %4 ], [ %2, %17 ]
  ret i64 %.0
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass