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

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

@init_flag = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [50 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [56 x i8], align 1
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@fd = external hidden global [8 x i32], align 16

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

8:                                                ; preds = %0
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %33

9:                                                ; preds = %0
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %29, %9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 8
  br i1 %12, label %13, label %32

13:                                               ; preds = %10
  %14 = getelementptr inbounds [64 x i8], ptr %2, i64 0, i64 0
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %14, i64 noundef 64, ptr noundef @.str, i32 noundef %15) #4
  %17 = getelementptr inbounds [64 x i8], ptr %2, i64 0, i64 0
  %18 = call i32 (ptr, i32, ...) @open(ptr noundef %17, i32 noundef 0)
  store i32 %18, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %13
  call void @perror(ptr noundef @.str.1)
  %22 = load ptr, ptr @stderr, align 8, !tbaa !9
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.2) #4
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %33

24:                                               ; preds = %13
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [8 x i32], ptr @fd, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %24
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %10, !llvm.loop !11

32:                                               ; preds = %10
  store i32 1, ptr @init_flag, align 4, !tbaa !5
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %33

33:                                               ; preds = %32, %21, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %2) #4
  %34 = load i32, ptr %1, align 4
  ret i32 %34
}

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

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #2

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

declare void @perror(ptr noundef) #3

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

; 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 "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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@init_flag = external hidden local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [50 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [56 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@fd = external hidden local_unnamed_addr global [8 x i32], align 16

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 -1, 1) i32 @rc_adc_init() local_unnamed_addr #0 {
  %1 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #4
  %2 = load i32, ptr @init_flag, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %.preheader.preheader, label %31

.preheader.preheader:                             ; preds = %0
  %3 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 0) #4
  %4 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %6, label %.preheader.1

6:                                                ; preds = %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  tail call void @perror(ptr noundef nonnull @.str.1) #5
  %7 = load ptr, ptr @stderr, align 8, !tbaa !9
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.2) #6
  br label %31

.preheader.1:                                     ; preds = %.preheader.preheader
  store i32 %4, ptr @fd, align 16, !tbaa !5
  %9 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 1) #4
  %10 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %6, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  store i32 %10, ptr getelementptr inbounds (i8, ptr @fd, i64 4), align 4, !tbaa !5
  %12 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 2) #4
  %13 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %6, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  store i32 %13, ptr getelementptr inbounds (i8, ptr @fd, i64 8), align 8, !tbaa !5
  %15 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 3) #4
  %16 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %6, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  store i32 %16, ptr getelementptr inbounds (i8, ptr @fd, i64 12), align 4, !tbaa !5
  %18 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 4) #4
  %19 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %6, label %.preheader.5

.preheader.5:                                     ; preds = %.preheader.4
  store i32 %19, ptr getelementptr inbounds (i8, ptr @fd, i64 16), align 16, !tbaa !5
  %21 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 5) #4
  %22 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %6, label %.preheader.6

.preheader.6:                                     ; preds = %.preheader.5
  store i32 %22, ptr getelementptr inbounds (i8, ptr @fd, i64 20), align 4, !tbaa !5
  %24 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 6) #4
  %25 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %6, label %.preheader.7

.preheader.7:                                     ; preds = %.preheader.6
  store i32 %25, ptr getelementptr inbounds (i8, ptr @fd, i64 24), align 8, !tbaa !5
  %27 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64, ptr noundef nonnull @.str, i32 noundef 7) #4
  %28 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %1, i32 noundef 0) #4
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %6, label %30

30:                                               ; preds = %.preheader.7
  store i32 %28, ptr getelementptr inbounds (i8, ptr @fd, i64 28), align 4, !tbaa !5
  store i32 1, ptr @init_flag, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %0, %30, %6
  %.0 = phi i32 [ -1, %6 ], [ 0, %30 ], [ 0, %0 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #4
  ret i32 %.0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

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

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass