; LLVM IR from xhub/reshop :: external/gamsapi/apifiles/C/api (cfgmcc)

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

%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 }

@MutexIsInitialized = external hidden global i32, align 4
@objMutex = external hidden global %union.pthread_mutex_t, align 8
@cfgXCreate = external hidden global ptr, align 8
@.str.47 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [28 x i8], align 1
@objectCount = external hidden global i32, align 4
@__PRETTY_FUNCTION__.cfgCreateD = external hidden unnamed_addr constant [57 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
declare ptr @strcpy(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @GC_mutex_lock(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @GC_mutex_unlock(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @cfgGetReadyD(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

18:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %45

19:                                               ; preds = %4
  %20 = load ptr, ptr @cfgXCreate, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  br label %24

23:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.47, ptr noundef @.str.48, i32 noundef 906, ptr noundef @__PRETTY_FUNCTION__.cfgCreateD) #5
  unreachable

24:                                               ; preds = %22
  %25 = load ptr, ptr @cfgXCreate, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  call void %25(ptr noundef %26)
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %32

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = call ptr @strcpy(ptr noundef %30, ptr noundef @.str.49) #4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %45

32:                                               ; preds = %24
  %33 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %32
  %36 = call i32 @GC_mutex_lock(ptr noundef @objMutex)
  br label %37

37:                                               ; preds = %35, %32
  %38 = load i32, ptr @objectCount, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @objectCount, align 4, !tbaa !9
  %40 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %37
  %43 = call i32 @GC_mutex_unlock(ptr noundef @objMutex)
  br label %44

44:                                               ; preds = %42, %37
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %45

45:                                               ; preds = %44, %29, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %46 = load i32, ptr %5, align 4
  ret i32 %46
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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, !10, i64 0}
!10 = !{!"int", !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"

%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 }

@MutexIsInitialized = external hidden local_unnamed_addr global i32, align 4
@objMutex = external hidden global %union.pthread_mutex_t, align 8
@cfgXCreate = external hidden local_unnamed_addr global ptr, align 8
@.str.47 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [28 x i8], align 1
@objectCount = external hidden local_unnamed_addr global i32, align 4
@__PRETTY_FUNCTION__.cfgCreateD = external hidden unnamed_addr constant [57 x i8], align 1

; 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 #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @cfgCreateD(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = tail call i32 @cfgGetReadyD(ptr noundef %1, ptr noundef %2, i32 noundef %3)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %23, label %6

6:                                                ; preds = %4
  %7 = load ptr, ptr @cfgXCreate, align 8, !tbaa !5
  %.not8 = icmp eq ptr %7, null
  br i1 %.not8, label %8, label %9

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.47, ptr noundef nonnull @.str.48, i32 noundef 906, ptr noundef nonnull @__PRETTY_FUNCTION__.cfgCreateD) #3
  unreachable

9:                                                ; preds = %6
  tail call void %7(ptr noundef %0) #4
  %10 = icmp eq ptr %0, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  %12 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.49) #4
  br label %23

13:                                               ; preds = %9
  %14 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %.not9 = icmp eq i32 %14, 0
  br i1 %.not9, label %.thread, label %17

.thread:                                          ; preds = %13
  %15 = load i32, ptr @objectCount, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @objectCount, align 4, !tbaa !9
  br label %23

17:                                               ; preds = %13
  %18 = tail call i32 @GC_mutex_lock(ptr noundef nonnull @objMutex)
  %.pr = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %19 = load i32, ptr @objectCount, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @objectCount, align 4, !tbaa !9
  %.not10 = icmp eq i32 %.pr, 0
  br i1 %.not10, label %23, label %21

21:                                               ; preds = %17
  %22 = tail call i32 @GC_mutex_unlock(ptr noundef nonnull @objMutex)
  br label %23

23:                                               ; preds = %.thread, %17, %21, %4, %11
  %.0 = phi i32 [ 0, %11 ], [ 0, %4 ], [ 1, %21 ], [ 1, %17 ], [ 1, %.thread ]
  ret i32 %.0
}

attributes #0 = { 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 #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 = { noreturn 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 = { noreturn nounwind }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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