; LLVM IR from beagleboard/librobotcontrol :: examples/src (rc_check_battery)

; 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 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@stdout = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = call i32 @rc_enable_signal_handler()
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %8, label %9

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

9:                                                ; preds = %0
  %10 = call i32 @rc_adc_init()
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %47

13:                                               ; preds = %9
  br label %14

14:                                               ; preds = %36, %13
  %15 = call i32 @rc_get_state()
  %16 = icmp ne i32 %15, 3
  br i1 %16, label %17, label %45

17:                                               ; preds = %14
  %18 = call double @rc_adc_batt()
  store double %18, ptr %2, align 8, !tbaa !5
  %19 = call double @rc_adc_dc_jack()
  store double %19, ptr %4, align 8, !tbaa !5
  %20 = load double, ptr %2, align 8, !tbaa !5
  %21 = fcmp olt double %20, 0.000000e+00
  br i1 %21, label %25, label %22

22:                                               ; preds = %17
  %23 = load double, ptr %4, align 8, !tbaa !5
  %24 = fcmp olt double %23, 0.000000e+00
  br i1 %24, label %25, label %28

25:                                               ; preds = %22, %17
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str) #4
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %47

28:                                               ; preds = %22
  %29 = load double, ptr %2, align 8, !tbaa !5
  %30 = fcmp olt double %29, 1.000000e+00
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %31, %28
  %33 = load double, ptr %4, align 8, !tbaa !5
  %34 = fcmp olt double %33, 1.000000e+00
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %35, %32
  %37 = load double, ptr %2, align 8, !tbaa !5
  %38 = fdiv double %37, 2.000000e+00
  store double %38, ptr %3, align 8, !tbaa !5
  %39 = load double, ptr %2, align 8, !tbaa !5
  %40 = load double, ptr %3, align 8, !tbaa !5
  %41 = load double, ptr %4, align 8, !tbaa !5
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %39, double noundef %40, double noundef %41)
  %43 = load ptr, ptr @stdout, align 8, !tbaa !9
  %44 = call i32 @fflush(ptr noundef %43)
  call void @rc_usleep(i32 noundef 100000)
  br label %14, !llvm.loop !11

45:                                               ; preds = %14
  %46 = call i32 @rc_adc_cleanup()
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %47

47:                                               ; preds = %45, %25, %12, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %48 = load i32, ptr %1, align 4
  ret i32 %48
}

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

declare i32 @rc_enable_signal_handler() #2

declare i32 @rc_adc_init() #2

declare i32 @rc_get_state() #2

declare double @rc_adc_batt() #2

declare double @rc_adc_dc_jack() #2

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

declare i32 @printf(ptr noundef, ...) #2

declare i32 @fflush(ptr noundef) #2

declare void @rc_usleep(i32 noundef) #2

declare i32 @rc_adc_cleanup() #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 = { "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 = { 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 #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 = !{!"double", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 @rc_enable_signal_handler() #3
  %2 = icmp eq i32 %1, -1
  br i1 %2, label %23, label %3

3:                                                ; preds = %0
  %4 = tail call i32 @rc_adc_init() #3
  %5 = icmp eq i32 %4, -1
  br i1 %5, label %23, label %.preheader

.preheader:                                       ; preds = %3
  %6 = tail call i32 @rc_get_state() #3
  %.not13 = icmp eq i32 %6, 3
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %14
  %7 = tail call double @rc_adc_batt() #3
  %8 = tail call double @rc_adc_dc_jack() #3
  %9 = fcmp olt double %7, 0.000000e+00
  %10 = fcmp olt double %8, 0.000000e+00
  %or.cond = select i1 %9, i1 true, i1 %10
  br i1 %or.cond, label %11, label %14

11:                                               ; preds = %.lr.ph
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str) #4
  br label %23

14:                                               ; preds = %.lr.ph
  %15 = fcmp olt double %7, 1.000000e+00
  %.010 = select i1 %15, double 0.000000e+00, double %7
  %16 = fcmp olt double %8, 1.000000e+00
  %.0 = select i1 %16, double 0.000000e+00, double %8
  %17 = fmul double %.010, 5.000000e-01
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %.010, double noundef %17, double noundef %.0)
  %19 = load ptr, ptr @stdout, align 8, !tbaa !5
  %20 = tail call i32 @fflush(ptr noundef %19)
  tail call void @rc_usleep(i32 noundef 100000) #3
  %21 = tail call i32 @rc_get_state() #3
  %.not = icmp eq i32 %21, 3
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %14, %.preheader
  %22 = tail call i32 @rc_adc_cleanup() #3
  br label %23

23:                                               ; preds = %3, %0, %._crit_edge, %11
  %.09 = phi i32 [ -1, %11 ], [ 0, %._crit_edge ], [ -1, %0 ], [ -1, %3 ]
  ret i32 %.09
}

declare i32 @rc_enable_signal_handler() local_unnamed_addr #1

declare i32 @rc_adc_init() local_unnamed_addr #1

declare i32 @rc_get_state() local_unnamed_addr #1

declare double @rc_adc_batt() local_unnamed_addr #1

declare double @rc_adc_dc_jack() local_unnamed_addr #1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #2

declare void @rc_usleep(i32 noundef) local_unnamed_addr #1

declare i32 @rc_adc_cleanup() local_unnamed_addr #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 = { "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 = { 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 = { nounwind }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass