; LLVM IR from lfarcaro/ARINC653_ARMV7A_AM335X :: Hardware (pruss)

; 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 i32 @PRUSSExecBuffer(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %29

14:                                               ; preds = %5
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 inttoptr (i64 1244872704 to ptr), ptr align 1 %15, i64 %17, i1 false)
  %18 = load ptr, ptr %10, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %24

20:                                               ; preds = %14
  %21 = load ptr, ptr %10, align 8, !tbaa !9
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 inttoptr (i64 1244659712 to ptr), ptr align 1 %21, i64 %23, i1 false)
  br label %24

24:                                               ; preds = %20, %14
  %25 = load volatile i32, ptr inttoptr (i64 1244798976 to ptr), align 4, !tbaa !5
  %26 = or i32 %25, 69206016
  store volatile i32 %26, ptr inttoptr (i64 1244798976 to ptr), align 4, !tbaa !5
  %27 = load volatile i32, ptr inttoptr (i64 1244798976 to ptr), align 4, !tbaa !5
  %28 = or i32 %27, 2
  store volatile i32 %28, ptr inttoptr (i64 1244798976 to ptr), align 4, !tbaa !5
  br label %49

29:                                               ; preds = %5
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %47

32:                                               ; preds = %29
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 inttoptr (i64 1244889088 to ptr), ptr align 1 %33, i64 %35, i1 false)
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %42

38:                                               ; preds = %32
  %39 = load ptr, ptr %10, align 8, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = zext i32 %40 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 inttoptr (i64 1244667904 to ptr), ptr align 1 %39, i64 %41, i1 false)
  br label %42

42:                                               ; preds = %38, %32
  %43 = load volatile i32, ptr inttoptr (i64 1244807168 to ptr), align 4, !tbaa !5
  %44 = or i32 %43, 69206016
  store volatile i32 %44, ptr inttoptr (i64 1244807168 to ptr), align 4, !tbaa !5
  %45 = load volatile i32, ptr inttoptr (i64 1244807168 to ptr), align 4, !tbaa !5
  %46 = or i32 %45, 2
  store volatile i32 %46, ptr inttoptr (i64 1244807168 to ptr), align 4, !tbaa !5
  br label %48

47:                                               ; preds = %29
  store i32 -1, ptr %6, align 4
  br label %50

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %48, %24
  store i32 0, ptr %6, align 4
  br label %50

50:                                               ; preds = %49, %47
  %51 = load i32, ptr %6, align 4
  ret i32 %51
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 nounwind willreturn memory(argmem: readwrite) }

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


; 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 -1, 1) i32 @PRUSSExecBuffer(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef readonly %3, i32 noundef %4) local_unnamed_addr #0 {
  switch i32 %0, label %18 [
    i32 0, label %6
    i32 1, label %10
  ]

6:                                                ; preds = %5
  %7 = zext i32 %2 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16384 inttoptr (i64 1244872704 to ptr), ptr align 1 %1, i64 %7, i1 false)
  %.not14 = icmp eq ptr %3, null
  br i1 %.not14, label %.sink.split, label %8

8:                                                ; preds = %6
  %9 = zext i32 %4 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1048576 inttoptr (i64 1244659712 to ptr), ptr nonnull align 1 %3, i64 %9, i1 false)
  br label %.sink.split

10:                                               ; preds = %5
  %11 = zext i32 %2 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 32768 inttoptr (i64 1244889088 to ptr), ptr align 1 %1, i64 %11, i1 false)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.sink.split, label %12

12:                                               ; preds = %10
  %13 = zext i32 %4 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8192 inttoptr (i64 1244667904 to ptr), ptr nonnull align 1 %3, i64 %13, i1 false)
  br label %.sink.split

.sink.split:                                      ; preds = %10, %12, %6, %8
  %.sink20 = phi ptr [ inttoptr (i64 1244798976 to ptr), %8 ], [ inttoptr (i64 1244798976 to ptr), %6 ], [ inttoptr (i64 1244807168 to ptr), %12 ], [ inttoptr (i64 1244807168 to ptr), %10 ]
  %14 = load volatile i32, ptr %.sink20, align 8192, !tbaa !5
  %15 = or i32 %14, 69206016
  store volatile i32 %15, ptr %.sink20, align 8192, !tbaa !5
  %16 = load volatile i32, ptr %.sink20, align 8192, !tbaa !5
  %17 = or i32 %16, 2
  store volatile i32 %17, ptr %.sink20, align 8192, !tbaa !5
  br label %18

18:                                               ; preds = %.sink.split, %5
  %.0 = phi i32 [ -1, %5 ], [ 0, %.sink.split ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

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


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