; LLVM IR from beagleboard/librobotcontrol :: library/src/pru (pru)

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

@stderr = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [73 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rc_pru_stop(i32 noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [64 x i8], align 16
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #6
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %16

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 1
  br i1 %12, label %13, label %16

13:                                               ; preds = %10
  %14 = load ptr, ptr @stderr, align 8, !tbaa !9
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str.22) #6
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

16:                                               ; preds = %10, %1
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.9, i32 noundef 0)
  store i32 %20, ptr %4, align 4, !tbaa !5
  br label %23

21:                                               ; preds = %16
  %22 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.10, i32 noundef 0)
  store i32 %22, ptr %4, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %21, %19
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  call void @perror(ptr noundef @.str.23)
  %27 = load ptr, ptr @stderr, align 8, !tbaa !9
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.11) #6
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

29:                                               ; preds = %23
  %30 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %30, i8 0, i64 64, i1 false)
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  %33 = call i64 @read(i32 noundef %31, ptr noundef %32, i64 noundef 64)
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = call i32 @close(i32 noundef %35)
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = icmp eq i32 %37, -1
  br i1 %38, label %39, label %42

39:                                               ; preds = %29
  call void @perror(ptr noundef @.str.24)
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = call i32 @close(i32 noundef %40)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

42:                                               ; preds = %29
  %43 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  %44 = call i32 @strcmp(ptr noundef %43, ptr noundef @.str.25) #7
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

47:                                               ; preds = %42
  %48 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  %49 = call i32 @strcmp(ptr noundef %48, ptr noundef @.str.15) #7
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %68

51:                                               ; preds = %47
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.9, i32 noundef 1)
  store i32 %55, ptr %4, align 4, !tbaa !5
  br label %58

56:                                               ; preds = %51
  %57 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.10, i32 noundef 1)
  store i32 %57, ptr %4, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %56, %54
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = call i64 @write(i32 noundef %59, ptr noundef @.str.26, i64 noundef 4)
  %61 = trunc i64 %60 to i32
  store i32 %61, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = call i32 @close(i32 noundef %62)
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = icmp eq i32 %64, -1
  br i1 %65, label %66, label %67

66:                                               ; preds = %58
  call void @perror(ptr noundef @.str.27)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

67:                                               ; preds = %58
  br label %72

68:                                               ; preds = %47
  %69 = load ptr, ptr @stderr, align 8, !tbaa !9
  %70 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef @.str.28, ptr noundef %70) #6
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

72:                                               ; preds = %67
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = icmp eq i32 %74, 0
  br i1 %75, label %76, label %78

76:                                               ; preds = %73
  %77 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.9, i32 noundef 0)
  store i32 %77, ptr %4, align 4, !tbaa !5
  br label %80

78:                                               ; preds = %73
  %79 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.10, i32 noundef 0)
  store i32 %79, ptr %4, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %78, %76
  %81 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %81, i8 0, i64 64, i1 false)
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  %84 = call i64 @read(i32 noundef %82, ptr noundef %83, i64 noundef 64)
  %85 = trunc i64 %84 to i32
  store i32 %85, ptr %5, align 4, !tbaa !5
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = call i32 @close(i32 noundef %86)
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = icmp eq i32 %88, -1
  br i1 %89, label %90, label %91

90:                                               ; preds = %80
  call void @perror(ptr noundef @.str.29)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

91:                                               ; preds = %80
  %92 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  %93 = call i32 @strcmp(ptr noundef %92, ptr noundef @.str.25) #7
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %99

95:                                               ; preds = %91
  %96 = load ptr, ptr @stderr, align 8, !tbaa !9
  %97 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 0
  %98 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %96, ptr noundef @.str.30, ptr noundef %97) #6
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

99:                                               ; preds = %91
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %100

100:                                              ; preds = %99, %95, %90, %68, %66, %46, %39, %26, %13
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  %101 = load i32, ptr %2, align 4
  ret i32 %101
}

declare i32 @open(ptr noundef, i32 noundef, ...) #4

declare void @perror(ptr noundef) #4

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #4

declare i32 @close(i32 noundef) #4

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { "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 #5 = { nounwind willreturn memory(read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [73 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @rc_pru_stop(i32 noundef %0) local_unnamed_addr #3 {
  %2 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #7
  %or.cond = icmp ugt i32 %0, 1
  br i1 %or.cond, label %3, label %6

3:                                                ; preds = %1
  %4 = load ptr, ptr @stderr, align 8, !tbaa !5
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.22) #8
  br label %48

6:                                                ; preds = %1
  %7 = icmp eq i32 %0, 0
  %.str.9..str.10 = select i1 %7, ptr @.str.9, ptr @.str.10
  %8 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %.str.9..str.10, i32 noundef 0) #7
  %9 = icmp eq i32 %8, -1
  br i1 %9, label %10, label %13

10:                                               ; preds = %6
  tail call void @perror(ptr noundef nonnull @.str.23) #9
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.11) #8
  br label %48

13:                                               ; preds = %6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %2, i8 0, i64 64, i1 false)
  %14 = call i64 @read(i32 noundef %8, ptr noundef nonnull %2, i64 noundef 64) #7
  %15 = tail call i32 @close(i32 noundef %8) #7
  %16 = and i64 %14, 4294967295
  %17 = icmp eq i64 %16, 4294967295
  br i1 %17, label %18, label %20

18:                                               ; preds = %13
  tail call void @perror(ptr noundef nonnull @.str.24) #9
  %19 = tail call i32 @close(i32 noundef %8) #7
  br label %48

20:                                               ; preds = %13
  %21 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.25) #10
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %48, label %23

23:                                               ; preds = %20
  %24 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.15) #10
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %33

26:                                               ; preds = %23
  %.str.9..str.1021 = select i1 %7, ptr @.str.9, ptr @.str.10
  %27 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %.str.9..str.1021, i32 noundef 1) #7
  %28 = tail call i64 @write(i32 noundef %27, ptr noundef nonnull @.str.26, i64 noundef 4) #7
  %29 = tail call i32 @close(i32 noundef %27) #7
  %30 = and i64 %28, 4294967295
  %31 = icmp eq i64 %30, 4294967295
  br i1 %31, label %32, label %36

32:                                               ; preds = %26
  tail call void @perror(ptr noundef nonnull @.str.27) #9
  br label %48

33:                                               ; preds = %23
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.28, ptr noundef nonnull %2) #8
  br label %48

36:                                               ; preds = %26
  %.str.9..str.1022 = select i1 %7, ptr @.str.9, ptr @.str.10
  %37 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %.str.9..str.1022, i32 noundef 0) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %2, i8 0, i64 64, i1 false)
  %38 = call i64 @read(i32 noundef %37, ptr noundef nonnull %2, i64 noundef 64) #7
  %39 = tail call i32 @close(i32 noundef %37) #7
  %40 = and i64 %38, 4294967295
  %41 = icmp eq i64 %40, 4294967295
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  tail call void @perror(ptr noundef nonnull @.str.29) #9
  br label %48

43:                                               ; preds = %36
  %44 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.25) #10
  %.not = icmp eq i32 %44, 0
  br i1 %.not, label %48, label %45

45:                                               ; preds = %43
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef nonnull @.str.30, ptr noundef nonnull %2) #8
  br label %48

48:                                               ; preds = %43, %20, %45, %42, %33, %32, %18, %10, %3
  %.018 = phi i32 [ -1, %3 ], [ -1, %10 ], [ -1, %18 ], [ -1, %32 ], [ -1, %42 ], [ -1, %45 ], [ -1, %33 ], [ 0, %20 ], [ 0, %43 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #7
  ret i32 %.018
}

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

declare i32 @close(i32 noundef) local_unnamed_addr #5

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #6

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { nofree "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 #5 = { "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 #6 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #7 = { nounwind }
attributes #8 = { cold nounwind }
attributes #9 = { cold }
attributes #10 = { nounwind willreturn memory(read) }

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


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