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

; 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 [52 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [45 x i8], align 1
@mode = external hidden global i32, align 4
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1
@toggle = external hidden global i32, align 4
@us_delay = external hidden constant [3 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 @rc_kill_existing_process(float noundef 2.000000e+00)
  %3 = icmp slt i32 %2, -2
  br i1 %3, label %4, label %5

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

5:                                                ; preds = %0
  %6 = call i32 @rc_enable_signal_handler()
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %11

8:                                                ; preds = %5
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str) #3
  store i32 -1, ptr %1, align 4
  br label %66

11:                                               ; preds = %5
  %12 = call i32 @rc_button_init(i32 noundef 2, i32 noundef 5, i8 noundef signext 1, i32 noundef 2000)
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.1) #3
  store i32 -1, ptr %1, align 4
  br label %66

17:                                               ; preds = %11
  %18 = call i32 @rc_button_init(i32 noundef 2, i32 noundef 4, i8 noundef signext 1, i32 noundef 2000)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.1) #3
  store i32 -1, ptr %1, align 4
  br label %66

23:                                               ; preds = %17
  %24 = call i32 @rc_button_set_callbacks(i32 noundef 2, i32 noundef 5, ptr noundef @__on_pause_press, ptr noundef @__on_pause_release)
  %25 = call i32 @rc_button_set_callbacks(i32 noundef 2, i32 noundef 4, ptr noundef null, ptr noundef @__on_mode_release)
  %26 = call i32 @rc_led_set(i32 noundef 0, i32 noundef 0)
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.2) #3
  store i32 -1, ptr %1, align 4
  br label %66

31:                                               ; preds = %23
  %32 = call i32 @rc_led_set(i32 noundef 1, i32 noundef 0)
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.3) #3
  store i32 -1, ptr %1, align 4
  br label %66

37:                                               ; preds = %31
  %38 = call i32 @rc_make_pid_file()
  call void @rc_set_state(i32 noundef 1)
  store i32 0, ptr @mode, align 4, !tbaa !9
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %41

41:                                               ; preds = %57, %37
  %42 = call i32 @rc_get_state()
  %43 = icmp ne i32 %42, 3
  br i1 %43, label %44, label %62

44:                                               ; preds = %41
  %45 = call i32 @rc_get_state()
  %46 = icmp eq i32 %45, 1
  br i1 %46, label %47, label %57

47:                                               ; preds = %44
  %48 = load i32, ptr @toggle, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = call i32 @rc_led_set(i32 noundef 0, i32 noundef 0)
  %52 = call i32 @rc_led_set(i32 noundef 1, i32 noundef 1)
  store i32 0, ptr @toggle, align 4, !tbaa !9
  br label %56

53:                                               ; preds = %47
  %54 = call i32 @rc_led_set(i32 noundef 0, i32 noundef 1)
  %55 = call i32 @rc_led_set(i32 noundef 1, i32 noundef 0)
  store i32 1, ptr @toggle, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %53, %50
  br label %57

57:                                               ; preds = %56, %44
  %58 = load i32, ptr @mode, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [3 x i32], ptr @us_delay, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  call void @rc_usleep(i32 noundef %61)
  br label %41, !llvm.loop !11

62:                                               ; preds = %41
  %63 = call i32 @rc_led_set(i32 noundef 0, i32 noundef 0)
  %64 = call i32 @rc_led_set(i32 noundef 1, i32 noundef 0)
  call void @rc_led_cleanup()
  call void @rc_button_cleanup()
  %65 = call i32 @rc_remove_pid_file()
  store i32 0, ptr %1, align 4
  br label %66

66:                                               ; preds = %62, %34, %28, %20, %14, %8, %4
  %67 = load i32, ptr %1, align 4
  ret i32 %67
}

declare i32 @rc_kill_existing_process(float noundef) #1

declare i32 @rc_enable_signal_handler() #1

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

declare i32 @rc_button_init(i32 noundef, i32 noundef, i8 noundef signext, i32 noundef) #1

declare i32 @rc_button_set_callbacks(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @__on_pause_press() #0

; Function Attrs: nounwind uwtable
declare hidden void @__on_pause_release() #0

; Function Attrs: nounwind uwtable
declare hidden void @__on_mode_release() #0

declare i32 @rc_led_set(i32 noundef, i32 noundef) #1

declare i32 @rc_make_pid_file() #1

declare void @rc_set_state(i32 noundef) #1

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

declare i32 @rc_get_state() #1

declare void @rc_usleep(i32 noundef) #1

declare void @rc_led_cleanup() #1

declare void @rc_button_cleanup() #1

declare i32 @rc_remove_pid_file() #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 = { 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 }

!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 = !{!10, !10, i64 0}
!10 = !{!"int", !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 [52 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [45 x i8], align 1
@mode = external hidden local_unnamed_addr global i32, align 4
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1
@toggle = external hidden local_unnamed_addr global i32, align 4
@us_delay = external hidden local_unnamed_addr constant [3 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 @rc_kill_existing_process(float noundef 2.000000e+00) #3
  %2 = icmp slt i32 %1, -2
  br i1 %2, label %52, label %3

3:                                                ; preds = %0
  %4 = tail call i32 @rc_enable_signal_handler() #3
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %6, label %9

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

9:                                                ; preds = %3
  %10 = tail call i32 @rc_button_init(i32 noundef 2, i32 noundef 5, i8 noundef signext 1, i32 noundef 2000) #3
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %14, label %11

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

14:                                               ; preds = %9
  %15 = tail call i32 @rc_button_init(i32 noundef 2, i32 noundef 4, i8 noundef signext 1, i32 noundef 2000) #3
  %.not1 = icmp eq i32 %15, 0
  br i1 %.not1, label %19, label %16

16:                                               ; preds = %14
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.1) #4
  br label %52

19:                                               ; preds = %14
  %20 = tail call i32 @rc_button_set_callbacks(i32 noundef 2, i32 noundef 5, ptr noundef nonnull @__on_pause_press, ptr noundef nonnull @__on_pause_release) #3
  %21 = tail call i32 @rc_button_set_callbacks(i32 noundef 2, i32 noundef 4, ptr noundef null, ptr noundef nonnull @__on_mode_release) #3
  %22 = tail call i32 @rc_led_set(i32 noundef 0, i32 noundef 0) #3
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.2) #4
  br label %52

27:                                               ; preds = %19
  %28 = tail call i32 @rc_led_set(i32 noundef 1, i32 noundef 0) #3
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.3) #4
  br label %52

33:                                               ; preds = %27
  %34 = tail call i32 @rc_make_pid_file() #3
  tail call void @rc_set_state(i32 noundef 1) #3
  store i32 0, ptr @mode, align 4, !tbaa !9
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %37 = tail call i32 @rc_get_state() #3
  %.not24 = icmp eq i32 %37, 3
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %33, %43
  %38 = tail call i32 @rc_get_state() #3
  %39 = icmp eq i32 %38, 1
  br i1 %39, label %.sink.split, label %43

.sink.split:                                      ; preds = %.lr.ph
  %40 = load i32, ptr @toggle, align 4, !tbaa !9
  %.not3 = icmp eq i32 %40, 0
  %. = zext i1 %.not3 to i32
  %not..not3 = xor i1 %.not3, true
  %.7 = zext i1 %not..not3 to i32
  %41 = tail call i32 @rc_led_set(i32 noundef 0, i32 noundef %.) #3
  %42 = tail call i32 @rc_led_set(i32 noundef 1, i32 noundef %.7) #3
  store i32 %., ptr @toggle, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %.sink.split, %.lr.ph
  %44 = load i32, ptr @mode, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [3 x i32], ptr @us_delay, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  tail call void @rc_usleep(i32 noundef %47) #3
  %48 = tail call i32 @rc_get_state() #3
  %.not2 = icmp eq i32 %48, 3
  br i1 %.not2, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %43, %33
  %49 = tail call i32 @rc_led_set(i32 noundef 0, i32 noundef 0) #3
  %50 = tail call i32 @rc_led_set(i32 noundef 1, i32 noundef 0) #3
  tail call void @rc_led_cleanup() #3
  tail call void @rc_button_cleanup() #3
  %51 = tail call i32 @rc_remove_pid_file() #3
  br label %52

52:                                               ; preds = %0, %._crit_edge, %30, %24, %16, %11, %6
  %.0 = phi i32 [ -1, %6 ], [ -1, %11 ], [ -1, %16 ], [ -1, %24 ], [ -1, %30 ], [ 0, %._crit_edge ], [ -1, %0 ]
  ret i32 %.0
}

declare i32 @rc_kill_existing_process(float noundef) local_unnamed_addr #1

declare i32 @rc_enable_signal_handler() local_unnamed_addr #1

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

declare i32 @rc_button_init(i32 noundef, i32 noundef, i8 noundef signext, i32 noundef) local_unnamed_addr #1

declare i32 @rc_button_set_callbacks(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @__on_pause_press() #0

; Function Attrs: nounwind uwtable
declare hidden void @__on_pause_release() #0

; Function Attrs: nounwind uwtable
declare hidden void @__on_mode_release() #0

declare i32 @rc_led_set(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @rc_make_pid_file() local_unnamed_addr #1

declare void @rc_set_state(i32 noundef) local_unnamed_addr #1

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

declare i32 @rc_get_state() local_unnamed_addr #1

declare void @rc_usleep(i32 noundef) local_unnamed_addr #1

declare void @rc_led_cleanup() local_unnamed_addr #1

declare void @rc_button_cleanup() local_unnamed_addr #1

declare i32 @rc_remove_pid_file() 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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