; LLVM IR from ctlst-tech/catpilot :: bsp/boards/cube/startup (init)

; 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.board_settings_t = type { ptr, i64, ptr, ptr }

@files = external global [32 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [40 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: nounwind uwtable
define dso_local ptr @board_thread(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %4, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.board_settings_t, ptr %5, i32 0, i32 2
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.board_settings_t, ptr %8, i32 0, i32 3
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = call i32 @board_cli_init(ptr noundef %7, ptr noundef %10)
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  br label %44

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.board_settings_t, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.board_settings_t, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = call i32 @board_init(ptr noundef %17, ptr noundef %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %30

23:                                               ; preds = %14
  %24 = load ptr, ptr getelementptr inbounds ([32 x ptr], ptr @files, i64 0, i64 2), align 16, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %24, ptr noundef @.str.1)
  %26 = load ptr, ptr getelementptr inbounds ([32 x ptr], ptr @files, i64 0, i64 2), align 16, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %26, ptr noundef @.str.2)
  %28 = load ptr, ptr getelementptr inbounds ([32 x ptr], ptr @files, i64 0, i64 2), align 16, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %28, ptr noundef @.str.1)
  br label %44

30:                                               ; preds = %14
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.board_settings_t, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = call i32 %33()
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %43

36:                                               ; preds = %30
  %37 = load ptr, ptr getelementptr inbounds ([32 x ptr], ptr @files, i64 0, i64 2), align 16, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %37, ptr noundef @.str.1)
  %39 = load ptr, ptr getelementptr inbounds ([32 x ptr], ptr @files, i64 0, i64 2), align 16, !tbaa !5
  %40 = call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %39, ptr noundef @.str.3)
  %41 = load ptr, ptr getelementptr inbounds ([32 x ptr], ptr @files, i64 0, i64 2), align 16, !tbaa !5
  %42 = call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %41, ptr noundef @.str.1)
  br label %44

43:                                               ; preds = %30
  br label %44

44:                                               ; preds = %43, %36, %23, %13
  br label %45

45:                                               ; preds = %46, %44
  br label %46

46:                                               ; preds = %45
  %47 = call i32 @sleep(i32 noundef 1)
  br label %45
}

; Function Attrs: nounwind uwtable
declare hidden i32 @board_cli_init(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @board_init(ptr noundef, ptr noundef) #1

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

declare i32 @sleep(i32 noundef) #2

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 = { "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, !6, i64 16}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!10, !6, 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"

@files = external local_unnamed_addr global [32 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef ptr @board_thread(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = tail call i32 @board_cli_init(ptr noundef %3, ptr noundef %5)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.preheader

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !11
  %10 = tail call i32 @board_init(ptr noundef %8, ptr noundef %9)
  %.not6 = icmp eq i32 %10, 0
  br i1 %.not6, label %11, label %.sink.split

11:                                               ; preds = %7
  %12 = load ptr, ptr %0, align 8, !tbaa !12
  %13 = tail call i32 %12() #3
  %.not7 = icmp eq i32 %13, 0
  br i1 %.not7, label %.preheader, label %.sink.split

.sink.split:                                      ; preds = %11, %7
  %.str.3.sink = phi ptr [ @.str.2, %7 ], [ @.str.3, %11 ]
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 16), align 16, !tbaa !13
  %15 = tail call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %14, ptr noundef nonnull @.str.1) #3
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 16), align 16, !tbaa !13
  %17 = tail call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %16, ptr noundef nonnull %.str.3.sink) #3
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 16), align 16, !tbaa !13
  %19 = tail call i32 (ptr, ptr, ...) @fprintf_(ptr noundef %18, ptr noundef nonnull @.str.1) #3
  br label %.preheader

.preheader:                                       ; preds = %.sink.split, %11, %1
  br label %20

20:                                               ; preds = %.preheader, %20
  %21 = tail call i32 @sleep(i32 noundef 1) #3
  br label %20
}

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

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

declare i32 @fprintf_(ptr noundef, ptr noundef, ...) local_unnamed_addr #2

declare i32 @sleep(i32 noundef) local_unnamed_addr #2

attributes #0 = { noreturn 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 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 = { "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, !7, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}


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