; LLVM IR from ctlst-tech/catpilot :: os/freertos/services/service (service)

; 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.service_t = type { [16 x i8], ptr, ptr, i32, i32 }

@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@_service = external hidden global [10 x %struct.service_t], align 16
@num = external hidden global i32, align 4
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @service(ptr noundef) #0

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

declare void @log_module(i8 noundef zeroext, ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @service_start(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %20, label %16

16:                                               ; preds = %5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #6
  %19 = icmp ugt i64 %18, 16
  br i1 %19, label %20, label %22

20:                                               ; preds = %16, %5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %21, ptr noundef @.str.2)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %81

22:                                               ; preds = %16
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %26, ptr noundef @.str.3)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %81

27:                                               ; preds = %22
  %28 = load i32, ptr @num, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.service_t, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [16 x i8], ptr %31, i64 0, i64 0
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call ptr @strncpy(ptr noundef %32, ptr noundef %33, i64 noundef 16) #5
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i32, ptr @num, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.service_t, ptr %38, i32 0, i32 2
  store ptr %35, ptr %39, align 8, !tbaa !11
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = udiv i32 %40, 1
  %42 = load i32, ptr @num, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.service_t, ptr %44, i32 0, i32 3
  store i32 %41, ptr %45, align 8, !tbaa !13
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = load i32, ptr @num, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.service_t, ptr %49, i32 0, i32 4
  store i32 %46, ptr %50, align 4, !tbaa !14
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load i32, ptr @num, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.service_t, ptr %54, i32 0, i32 1
  store ptr %51, ptr %55, align 8, !tbaa !15
  %56 = load i32, ptr @num, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.service_t, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds [16 x i8], ptr %59, i64 0, i64 0
  %61 = load i32, ptr @num, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %62
  %64 = load i32, ptr @num, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.service_t, ptr %66, i32 0, i32 4
  %68 = load i32, ptr %67, align 4, !tbaa !14
  %69 = zext i32 %68 to i64
  %70 = call i64 @xTaskCreate(ptr noundef @service, ptr noundef %60, i16 noundef zeroext 384, ptr noundef %63, i64 noundef %69, ptr noundef null)
  %71 = icmp ne i64 %70, 1
  br i1 %71, label %72, label %74

72:                                               ; preds = %27
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %73, ptr noundef @.str.4)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %81

74:                                               ; preds = %27
  %75 = load i32, ptr @num, align 4, !tbaa !9
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %76
  store ptr %77, ptr %12, align 8, !tbaa !5
  %78 = load i32, ptr @num, align 4, !tbaa !9
  %79 = add i32 %78, 1
  store i32 %79, ptr @num, align 4, !tbaa !9
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %80, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %81

81:                                               ; preds = %74, %72, %25, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %82 = load ptr, ptr %6, align 8
  ret ptr %82
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

declare i64 @xTaskCreate(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef, i64 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 = { "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 willreturn memory(read) "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 }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!12, !6, i64 24}
!12 = !{!"", !7, i64 0, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!13 = !{!12, !10, i64 32}
!14 = !{!12, !10, i64 36}
!15 = !{!12, !6, i64 16}


; 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.service_t = type { [16 x i8], ptr, ptr, i32, i32 }

@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@_service = external hidden global [10 x %struct.service_t], align 16
@num = external hidden local_unnamed_addr global i32, align 4
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @service(ptr noundef) #0

declare void @log_module(i8 noundef zeroext, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @service_start(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %0, null
  br i1 %6, label %10, label %7

7:                                                ; preds = %5
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %9 = icmp ugt i64 %8, 16
  br i1 %9, label %10, label %11

10:                                               ; preds = %7, %5
  tail call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %0, ptr noundef nonnull @.str.2) #5
  br label %31

11:                                               ; preds = %7
  %12 = icmp eq ptr %2, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %11
  tail call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef nonnull %0, ptr noundef nonnull @.str.3) #5
  br label %31

14:                                               ; preds = %11
  %15 = load i32, ptr @num, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %16
  %18 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %17, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 16) #5
  %19 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %16, i32 2
  store ptr %2, ptr %19, align 8, !tbaa !9
  %20 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %16, i32 3
  store i32 %3, ptr %20, align 8, !tbaa !12
  %21 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %16, i32 4
  store i32 %4, ptr %21, align 4, !tbaa !13
  %22 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %16, i32 1
  store ptr %1, ptr %22, align 8, !tbaa !14
  %23 = zext i32 %4 to i64
  %24 = tail call i64 @xTaskCreate(ptr noundef nonnull @service, ptr noundef nonnull %17, i16 noundef zeroext 384, ptr noundef nonnull %17, i64 noundef %23, ptr noundef null) #5
  %.not = icmp eq i64 %24, 1
  br i1 %.not, label %26, label %25

25:                                               ; preds = %14
  tail call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef nonnull %0, ptr noundef nonnull @.str.4) #5
  br label %31

26:                                               ; preds = %14
  %27 = load i32, ptr @num, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [10 x %struct.service_t], ptr @_service, i64 0, i64 %28
  %30 = add i32 %27, 1
  store i32 %30, ptr @num, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %26, %25, %13, %10
  %.0 = phi ptr [ null, %10 ], [ null, %13 ], [ null, %25 ], [ %29, %26 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

declare i64 @xTaskCreate(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 = { nounwind willreturn memory(read) }
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, !11, i64 24}
!10 = !{!"", !7, i64 0, !11, i64 16, !11, i64 24, !6, i64 32, !6, i64 36}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 32}
!13 = !{!10, !6, i64 36}
!14 = !{!10, !11, i64 16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass