; LLVM IR from DroneBridge/DroneBridge :: control (sumd_test)

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

%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@serial_data_buffer = external dso_local global [1024 x i8], align 16
@__const.main.my_channel_data = external hidden unnamed_addr constant [12 x i16], align 16
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [140 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @generate_sumd(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [12 x i16], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.termios, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.main.my_channel_data, i64 24, i1 false)
  %13 = getelementptr inbounds [12 x i16], ptr %6, i64 0, i64 0
  call void @generate_sumd(ptr noundef %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 -1, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  br label %14

14:                                               ; preds = %22, %2
  %15 = call i32 (ptr, i32, ...) @open(ptr noundef @.str, i32 noundef 1052929)
  store i32 %15, ptr %7, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %21

18:                                               ; preds = %14
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %20 = call i32 @sleep(i32 noundef 1)
  br label %21

21:                                               ; preds = %18, %14
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %14, label %25, !llvm.loop !11

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 60, ptr %9) #6
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = call i32 @tcgetattr(i32 noundef %26, ptr noundef %9) #6
  %28 = call i32 @cfsetospeed(ptr noundef %9, i32 noundef 4098) #6
  %29 = getelementptr inbounds %struct.termios, ptr %9, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = and i32 %30, -1404
  store i32 %31, ptr %29, align 4, !tbaa !13
  %32 = getelementptr inbounds %struct.termios, ptr %9, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = and i32 %33, -126
  store i32 %34, ptr %32, align 4, !tbaa !15
  %35 = getelementptr inbounds %struct.termios, ptr %9, i32 0, i32 3
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = and i32 %36, -32844
  store i32 %37, ptr %35, align 4, !tbaa !16
  %38 = getelementptr inbounds %struct.termios, ptr %9, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !17
  %40 = and i32 %39, -305
  store i32 %40, ptr %38, align 4, !tbaa !17
  %41 = getelementptr inbounds %struct.termios, ptr %9, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !17
  %43 = or i32 %42, 48
  store i32 %43, ptr %41, align 4, !tbaa !17
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = call i32 @tcflush(i32 noundef %44, i32 noundef 0) #6
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = call i32 @tcsetattr(i32 noundef %46, i32 noundef 0, ptr noundef %9) #6
  %48 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %48, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %69, %25
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 200
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %72

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = call i64 @write(i32 noundef %54, ptr noundef @serial_data_buffer, i64 noundef 29)
  %56 = trunc i64 %55 to i32
  store i32 %56, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %57 = call ptr @__errno_location() #7
  %58 = load i32, ptr %57, align 4, !tbaa !5
  store i32 %58, ptr %12, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = call i32 @tcdrain(i32 noundef %59)
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = icmp slt i32 %61, 29
  br i1 %62, label %63, label %67

63:                                               ; preds = %53
  %64 = load i32, ptr %12, align 4, !tbaa !5
  %65 = call ptr @strerror(i32 noundef %64) #6
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %65)
  br label %67

67:                                               ; preds = %63, %53
  call void @print_buffer(ptr noundef @serial_data_buffer, i32 noundef 29)
  %68 = call i32 @usleep(i32 noundef 10000)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %69

69:                                               ; preds = %67
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %10, align 4, !tbaa !5
  br label %49, !llvm.loop !18

72:                                               ; preds = %52
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = call i32 @close(i32 noundef %73)
  call void @llvm.lifetime.end.p0(i64 60, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #6
  %75 = load i32, ptr %3, align 4
  ret i32 %75
}

; 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) #2

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

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

declare i32 @sleep(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @tcgetattr(i32 noundef, ptr noundef) #4

; Function Attrs: nounwind
declare i32 @cfsetospeed(ptr noundef, i32 noundef) #4

; Function Attrs: nounwind
declare i32 @tcflush(i32 noundef, i32 noundef) #4

; Function Attrs: nounwind
declare i32 @tcsetattr(i32 noundef, i32 noundef, ptr noundef) #4

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #5

declare i32 @tcdrain(i32 noundef) #3

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #4

declare void @print_buffer(ptr noundef, i32 noundef) #3

declare i32 @usleep(i32 noundef) #3

declare i32 @close(i32 noundef) #3

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

!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"}
!13 = !{!14, !6, i64 0}
!14 = !{!"termios", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !7, i64 17, !6, i64 52, !6, i64 56}
!15 = !{!14, !6, i64 4}
!16 = !{!14, !6, i64 12}
!17 = !{!14, !6, i64 8}
!18 = distinct !{!18, !12}


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

%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@serial_data_buffer = external dso_local global [1024 x i8], align 16
@__const.main.my_channel_data = external hidden unnamed_addr constant [12 x i16], align 16
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [140 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @generate_sumd(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = alloca [12 x i16], align 16
  %4 = alloca %struct.termios, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %3, ptr noundef nonnull align 16 dereferenceable(24) @__const.main.my_channel_data, i64 24, i1 false)
  call void @generate_sumd(ptr noundef nonnull %3)
  %5 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull @.str, i32 noundef 1052929) #8
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %8 = call i32 @sleep(i32 noundef 1) #8
  %9 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull @.str, i32 noundef 1052929) #8
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %.lr.ph, label %.critedge, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph, %2
  %.lcssa = phi i32 [ %5, %2 ], [ %9, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 60, ptr nonnull %4) #8
  %11 = call i32 @tcgetattr(i32 noundef %.lcssa, ptr noundef nonnull %4) #8
  %12 = call i32 @cfsetospeed(ptr noundef nonnull %4, i32 noundef 4098) #8
  %13 = load <2 x i32>, ptr %4, align 8, !tbaa !7
  %14 = and <2 x i32> %13, <i32 -1404, i32 -126>
  store <2 x i32> %14, ptr %4, align 8, !tbaa !7
  %15 = getelementptr inbounds i8, ptr %4, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = and i32 %16, -32844
  store i32 %17, ptr %15, align 4, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = and i32 %19, -305
  %21 = or disjoint i32 %20, 48
  store i32 %21, ptr %18, align 8, !tbaa !13
  %22 = call i32 @tcflush(i32 noundef %.lcssa, i32 noundef 0) #8
  %23 = call i32 @tcsetattr(i32 noundef %.lcssa, i32 noundef 0, ptr noundef nonnull %4) #8
  br label %26

24:                                               ; preds = %36
  %25 = call i32 @close(i32 noundef %.lcssa) #8
  call void @llvm.lifetime.end.p0(i64 60, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #8
  ret i32 0

26:                                               ; preds = %.critedge, %36
  %.015 = phi i32 [ 0, %.critedge ], [ %38, %36 ]
  %27 = call i64 @write(i32 noundef %.lcssa, ptr noundef nonnull @serial_data_buffer, i64 noundef 29) #8
  %28 = trunc i64 %27 to i32
  %29 = tail call ptr @__errno_location() #9
  %30 = load i32, ptr %29, align 4, !tbaa !7
  %31 = call i32 @tcdrain(i32 noundef %.lcssa) #8
  %32 = icmp slt i32 %28, 29
  br i1 %32, label %33, label %36

33:                                               ; preds = %26
  %34 = call ptr @strerror(i32 noundef %30) #8
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %34)
  br label %36

36:                                               ; preds = %33, %26
  call void @print_buffer(ptr noundef nonnull @serial_data_buffer, i32 noundef 29) #8
  %37 = call i32 @usleep(i32 noundef 10000) #8
  %38 = add nuw nsw i32 %.015, 1
  %exitcond.not = icmp eq i32 %38, 200
  br i1 %exitcond.not, label %24, label %26, !llvm.loop !14
}

; 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) #2

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

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

declare i32 @sleep(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind
declare i32 @tcgetattr(i32 noundef, ptr noundef) local_unnamed_addr #6

; Function Attrs: nounwind
declare i32 @cfsetospeed(ptr noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: nounwind
declare i32 @tcflush(i32 noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: nounwind
declare i32 @tcsetattr(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #7

declare i32 @tcdrain(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #6

declare void @print_buffer(ptr noundef, i32 noundef) local_unnamed_addr #5

declare i32 @usleep(i32 noundef) local_unnamed_addr #5

declare i32 @close(i32 noundef) local_unnamed_addr #5

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !8, i64 12}
!12 = !{!"termios", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !9, i64 16, !9, i64 17, !8, i64 52, !8, i64 56}
!13 = !{!12, !8, i64 8}
!14 = distinct !{!14, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass