; LLVM IR from intrepidcs/icsneoapi :: src/OThread.ll (ZN7OThread5StartEPvii)

; 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.sched_param = type { i32 }
%union.pthread_attr_t = type { i64, [48 x i8] }
%class.OThread = type { ptr, i8, i64, %class.OCriticalSection, i8, ptr }
%class.OCriticalSection = type { ptr, %union.pthread_mutexattr_t, %union.pthread_mutex_t }
%union.pthread_mutexattr_t = type { i32 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN7OThread5StartEPvii(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca %struct.sched_param, align 4
  %16 = alloca i32, align 4
  %17 = alloca %union.pthread_attr_t, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %19 = load ptr, ptr %6, align 8
  %20 = getelementptr inbounds %class.OThread, ptr %19, i32 0, i32 1
  %21 = load i8, ptr %20, align 8, !tbaa !11, !range !16, !noundef !17
  %22 = trunc i8 %21 to i1
  br i1 %22, label %23, label %24

23:                                               ; preds = %4
  store i1 true, ptr %5, align 1
  br label %96

24:                                               ; preds = %4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.OThread, ptr %19, i32 0, i32 5
  store ptr %25, ptr %26, align 8, !tbaa !18
  %27 = getelementptr inbounds %class.OThread, ptr %19, i32 0, i32 4
  store i8 0, ptr %27, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr %17) #4
  %28 = call i32 @pthread_attr_init(ptr noundef %17) #4
  %29 = call i32 @pthread_attr_setschedpolicy(ptr noundef %17, i32 noundef 0) #4
  store i32 %29, ptr %16, align 4, !tbaa !9
  %30 = load i32, ptr %16, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  store i1 false, ptr %5, align 1
  store i32 1, ptr %18, align 4
  br label %95

33:                                               ; preds = %24
  %34 = call i32 @sched_get_priority_max(i32 noundef 0) #4
  store i32 %34, ptr %10, align 4, !tbaa !9
  %35 = call i32 @sched_get_priority_min(i32 noundef 0) #4
  store i32 %35, ptr %11, align 4, !tbaa !9
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = sub nsw i32 %36, %37
  store i32 %38, ptr %13, align 4, !tbaa !9
  %39 = load i32, ptr %13, align 4, !tbaa !9
  %40 = sdiv i32 %39, 2
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = add nsw i32 %40, %41
  store i32 %42, ptr %12, align 4, !tbaa !9
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = sdiv i32 %43, 4
  store i32 %44, ptr %14, align 4, !tbaa !9
  %45 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %45, label %63 [
    i32 1, label %46
    i32 -1, label %51
    i32 2, label %56
    i32 15, label %56
    i32 -15, label %59
    i32 0, label %62
  ]

46:                                               ; preds = %33
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = load i32, ptr %14, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  %50 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  store i32 %49, ptr %50, align 4, !tbaa !20
  br label %66

51:                                               ; preds = %33
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = add nsw i32 %52, %53
  %55 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  store i32 %54, ptr %55, align 4, !tbaa !20
  br label %66

56:                                               ; preds = %33, %33
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  store i32 %57, ptr %58, align 4, !tbaa !20
  br label %66

59:                                               ; preds = %33
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  store i32 %60, ptr %61, align 4, !tbaa !20
  br label %66

62:                                               ; preds = %33
  br label %63

63:                                               ; preds = %62, %33
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  store i32 %64, ptr %65, align 4, !tbaa !20
  br label %66

66:                                               ; preds = %63, %59, %56, %51, %46
  %67 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  %68 = load i32, ptr %67, align 4, !tbaa !20
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = icmp slt i32 %68, %69
  br i1 %70, label %71, label %74

71:                                               ; preds = %66
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  store i32 %72, ptr %73, align 4, !tbaa !20
  br label %74

74:                                               ; preds = %71, %66
  %75 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  %76 = load i32, ptr %75, align 4, !tbaa !20
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = icmp sgt i32 %76, %77
  br i1 %78, label %79, label %82

79:                                               ; preds = %74
  %80 = load i32, ptr %10, align 4, !tbaa !9
  %81 = getelementptr inbounds %struct.sched_param, ptr %15, i32 0, i32 0
  store i32 %80, ptr %81, align 4, !tbaa !20
  br label %82

82:                                               ; preds = %79, %74
  %83 = call i32 @pthread_attr_setschedparam(ptr noundef %17, ptr noundef %15) #4
  store i32 %83, ptr %16, align 4, !tbaa !9
  %84 = load i32, ptr %16, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %82
  store i1 false, ptr %5, align 1
  store i32 1, ptr %18, align 4
  br label %95

87:                                               ; preds = %82
  %88 = getelementptr inbounds %class.OThread, ptr %19, i32 0, i32 2
  %89 = call i32 @pthread_create(ptr noundef %88, ptr noundef null, ptr noundef @_ZL18CThreadRunFunctionPv, ptr noundef %19) #4
  store i32 %89, ptr %16, align 4, !tbaa !9
  %90 = load i32, ptr %16, align 4, !tbaa !9
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %93

92:                                               ; preds = %87
  store i1 false, ptr %5, align 1
  store i32 1, ptr %18, align 4
  br label %95

93:                                               ; preds = %87
  %94 = getelementptr inbounds %class.OThread, ptr %19, i32 0, i32 1
  store i8 1, ptr %94, align 8, !tbaa !11
  store i1 true, ptr %5, align 1
  store i32 1, ptr %18, align 4
  br label %95

95:                                               ; preds = %93, %92, %86, %32
  call void @llvm.lifetime.end.p0(i64 56, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %96

96:                                               ; preds = %95, %23
  %97 = load i1, ptr %5, align 1
  ret i1 %97
}

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

; Function Attrs: nounwind
declare i32 @pthread_attr_init(ptr noundef) #2

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

; Function Attrs: nounwind
declare i32 @sched_get_priority_max(i32 noundef) #2

; Function Attrs: nounwind
declare i32 @sched_get_priority_min(i32 noundef) #2

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

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

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL18CThreadRunFunctionPv(ptr noundef) #3

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

attributes #0 = { mustprogress 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 = { 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 = { mustprogress 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS7OThread", !13, i64 8, !14, i64 16, !15, i64 24, !13, i64 80, !6, i64 88}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS16OCriticalSection", !7, i64 8, !7, i64 16}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !6, i64 88}
!19 = !{!12, !13, i64 80}
!20 = !{!21, !10, i64 0}
!21 = !{!"_ZTS11sched_param", !10, 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.sched_param = type { i32 }
%union.pthread_attr_t = type { i64, [48 x i8] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN7OThread5StartEPvii(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = alloca %struct.sched_param, align 4
  %6 = alloca %union.pthread_attr_t, align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i8, ptr %7, align 8, !tbaa !5, !range !13, !noundef !14
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %43, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr %1, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  store i8 0, ptr %12, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %6) #4
  %13 = call i32 @pthread_attr_init(ptr noundef nonnull %6) #4
  %14 = call i32 @pthread_attr_setschedpolicy(ptr noundef nonnull %6, i32 noundef 0) #4
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %42

15:                                               ; preds = %10
  %16 = call i32 @sched_get_priority_max(i32 noundef 0) #4
  %17 = call i32 @sched_get_priority_min(i32 noundef 0) #4
  %18 = sub nsw i32 %16, %17
  %19 = sdiv i32 %18, 4
  switch i32 %2, label %25 [
    i32 1, label %20
    i32 -1, label %22
    i32 2, label %24
    i32 15, label %24
    i32 -15, label %.thread
  ]

20:                                               ; preds = %15
  %21 = sub nsw i32 %16, %19
  store i32 %21, ptr %5, align 4, !tbaa !17
  br label %28

22:                                               ; preds = %15
  %23 = add nsw i32 %19, %17
  store i32 %23, ptr %5, align 4, !tbaa !17
  br label %28

24:                                               ; preds = %15, %15
  store i32 %16, ptr %5, align 4, !tbaa !17
  br label %28

.thread:                                          ; preds = %15
  store i32 %17, ptr %5, align 4, !tbaa !17
  br label %32

25:                                               ; preds = %15
  %26 = sdiv i32 %18, 2
  %27 = add nsw i32 %26, %17
  store i32 %27, ptr %5, align 4, !tbaa !17
  br label %28

28:                                               ; preds = %25, %24, %22, %20
  %29 = phi i32 [ %27, %25 ], [ %16, %24 ], [ %23, %22 ], [ %21, %20 ]
  %30 = icmp slt i32 %29, %17
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store i32 %17, ptr %5, align 4, !tbaa !17
  br label %32

32:                                               ; preds = %.thread, %31, %28
  %33 = phi i32 [ %17, %31 ], [ %29, %28 ], [ %17, %.thread ]
  %34 = icmp sgt i32 %33, %16
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store i32 %16, ptr %5, align 4, !tbaa !17
  br label %36

36:                                               ; preds = %35, %32
  %37 = call i32 @pthread_attr_setschedparam(ptr noundef nonnull %6, ptr noundef nonnull %5) #4
  %.not24 = icmp eq i32 %37, 0
  br i1 %.not24, label %38, label %42

38:                                               ; preds = %36
  %39 = getelementptr inbounds i8, ptr %0, i64 16
  %40 = call i32 @pthread_create(ptr noundef nonnull %39, ptr noundef null, ptr noundef nonnull @_ZL18CThreadRunFunctionPv, ptr noundef nonnull %0) #4
  %.not25 = icmp eq i32 %40, 0
  br i1 %.not25, label %41, label %42

41:                                               ; preds = %38
  store i8 1, ptr %7, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %38, %36, %10, %41
  %.0 = phi i1 [ true, %41 ], [ false, %10 ], [ false, %36 ], [ false, %38 ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  br label %43

43:                                               ; preds = %4, %42
  %.1 = phi i1 [ %.0, %42 ], [ true, %4 ]
  ret i1 %.1
}

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

; Function Attrs: nounwind
declare i32 @pthread_attr_init(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @pthread_attr_setschedpolicy(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @sched_get_priority_max(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @sched_get_priority_min(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @pthread_attr_setschedparam(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL18CThreadRunFunctionPv(ptr noundef) #3

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 #4 = { 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 8}
!6 = !{!"_ZTS7OThread", !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 80, !12, i64 88}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_ZTS16OCriticalSection", !8, i64 8, !8, i64 16}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !12, i64 88}
!16 = !{!6, !7, i64 80}
!17 = !{!18, !19, i64 0}
!18 = !{!"_ZTS11sched_param", !19, i64 0}
!19 = !{!"int", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass