; LLVM IR from DroneBridge/DroneBridge :: InjectionTest (send_main)

; 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.db_socket_t = type { i32, %struct.sockaddr_ll }
%struct.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }

@keep_running = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @int_handler(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [16 x i8], align 16
  %7 = alloca %struct.db_socket_t, align 4
  %8 = alloca i8, align 1
  %9 = alloca [1024 x i8], align 16
  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
  %10 = call ptr @signal(i32 noundef 2, ptr noundef @int_handler) #5
  %11 = call ptr @signal(i32 noundef 15, ptr noundef @int_handler) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  %12 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds ptr, ptr %13, i64 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = call ptr @strcpy(ptr noundef %12, ptr noundef %15) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #5
  %17 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  call void @open_db_socket(ptr dead_on_unwind writable sret(%struct.db_socket_t) align 4 %7, ptr noundef %17, i8 noundef zeroext 16, i8 noundef signext 109, i32 noundef 11, i8 noundef zeroext 3, i8 noundef zeroext 10, i8 noundef zeroext 2)
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  store i8 0, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #5
  %18 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %18, i8 1, i64 1024, i1 false)
  br label %19

19:                                               ; preds = %22, %2
  %20 = load i32, ptr @keep_running, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %30

22:                                               ; preds = %19
  %23 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %24 = call zeroext i8 @update_seq_num(ptr noundef %8)
  %25 = call i32 @db_send_div(ptr noundef %7, ptr noundef %23, i8 noundef zeroext 10, i16 noundef zeroext 1024, i8 noundef zeroext %24, i32 noundef 0)
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %27 = load ptr, ptr @stdout, align 8, !tbaa !9
  %28 = call i32 @fflush(ptr noundef %27)
  %29 = call i32 @usleep(i32 noundef 1000000)
  br label %19, !llvm.loop !12

30:                                               ; preds = %19
  %31 = getelementptr inbounds %struct.db_socket_t, ptr %7, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = call i32 @close(i32 noundef %32)
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  %35 = load i32, ptr %3, align 4
  ret i32 %35
}

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

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #1

declare void @open_db_socket(ptr dead_on_unwind writable sret(%struct.db_socket_t) align 4, ptr noundef, i8 noundef zeroext, i8 noundef signext, i32 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #3

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

declare i32 @db_send_div(ptr noundef, ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext, i32 noundef) #3

declare zeroext i8 @update_seq_num(ptr noundef) #3

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

declare i32 @fflush(ptr noundef) #3

declare i32 @usleep(i32 noundef) #3

declare i32 @close(i32 noundef) #3

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

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 = { 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 nosync 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !6, i64 0, !16, i64 4}
!16 = !{!"sockaddr_ll", !17, i64 0, !17, i64 2, !6, i64 4, !17, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}
!17 = !{!"short", !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"

%struct.db_socket_t = type { i32, %struct.sockaddr_ll }
%struct.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }

@keep_running = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @int_handler(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [16 x i8], align 16
  %4 = alloca %struct.db_socket_t, align 4
  %5 = alloca i8, align 1
  %6 = alloca [1024 x i8], align 16
  %7 = tail call ptr @signal(i32 noundef 2, ptr noundef nonnull @int_handler) #7
  %8 = tail call ptr @signal(i32 noundef 15, ptr noundef nonnull @int_handler) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #7
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %10) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #7
  call void @open_db_socket(ptr dead_on_unwind nonnull writable sret(%struct.db_socket_t) align 4 %4, ptr noundef nonnull %3, i8 noundef zeroext 16, i8 noundef signext 109, i32 noundef 11, i8 noundef zeroext 3, i8 noundef zeroext 10, i8 noundef zeroext 2) #7
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #7
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %6) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1024) %6, i8 1, i64 1024, i1 false)
  %12 = load i32, ptr @keep_running, align 4, !tbaa !10
  %.not1 = icmp eq i32 %12, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %13 = call zeroext i8 @update_seq_num(ptr noundef nonnull %5) #7
  %14 = call i32 @db_send_div(ptr noundef nonnull %4, ptr noundef nonnull %6, i8 noundef zeroext 10, i16 noundef zeroext 1024, i8 noundef zeroext %13, i32 noundef 0) #7
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %16 = load ptr, ptr @stdout, align 8, !tbaa !5
  %17 = call i32 @fflush(ptr noundef %16)
  %18 = call i32 @usleep(i32 noundef 1000000) #7
  %19 = load i32, ptr @keep_running, align 4, !tbaa !10
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %2
  %20 = load i32, ptr %4, align 4, !tbaa !14
  %21 = call i32 @close(i32 noundef %20) #7
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #7
  ret i32 0
}

; Function Attrs: nounwind
declare ptr @signal(i32 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

declare void @open_db_socket(ptr dead_on_unwind writable sret(%struct.db_socket_t) align 4, ptr noundef, i8 noundef zeroext, i8 noundef signext, i32 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #4

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

declare i32 @db_send_div(ptr noundef, ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext, i32 noundef) local_unnamed_addr #4

declare zeroext i8 @update_seq_num(ptr noundef) local_unnamed_addr #4

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

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

declare i32 @usleep(i32 noundef) local_unnamed_addr #4

declare i32 @close(i32 noundef) local_unnamed_addr #4

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

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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !11, i64 0}
!15 = !{!"", !11, i64 0, !16, i64 4}
!16 = !{!"sockaddr_ll", !17, i64 0, !17, i64 2, !11, i64 4, !17, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}
!17 = !{!"short", !7, i64 0}


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