; 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
@__PRETTY_FUNCTION__.cfgCreate = external hidden unnamed_addr constant [42 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [28 x i8], align 1
@objectCount = external hidden global i32, align 4

; 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 dso_local i32 @cfgGetReady(ptr noundef, i32 noundef) #2

; 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
define dso_local i32 @cfgCreate(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = call i32 @cfgGetReady(ptr noundef %10, i32 noundef %11)
  store i32 %12, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %42

16:                                               ; preds = %3
  %17 = load ptr, ptr @cfgXCreate, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  br label %21

20:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str.47, ptr noundef @.str.48, i32 noundef 887, ptr noundef @__PRETTY_FUNCTION__.cfgCreate) #5
  unreachable

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

26:                                               ; preds = %21
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call ptr @strcpy(ptr noundef %27, ptr noundef @.str.49) #4
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %42

29:                                               ; preds = %21
  %30 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = call i32 @GC_mutex_lock(ptr noundef @objMutex)
  br label %34

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

39:                                               ; preds = %34
  %40 = call i32 @GC_mutex_unlock(ptr noundef @objMutex)
  br label %41

41:                                               ; preds = %39, %34
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %42

42:                                               ; preds = %41, %26, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %43 = load i32, ptr %4, align 4
  ret i32 %43
}

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

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
@__PRETTY_FUNCTION__.cfgCreate = external hidden unnamed_addr constant [42 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

; 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 dso_local i32 @cfgGetReady(ptr noundef, i32 noundef) local_unnamed_addr #1

; 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
define dso_local range(i32 0, 2) i32 @cfgCreate(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @cfgGetReady(ptr noundef %1, i32 noundef %2)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %22, label %5

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

7:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.47, ptr noundef nonnull @.str.48, i32 noundef 887, ptr noundef nonnull @__PRETTY_FUNCTION__.cfgCreate) #3
  unreachable

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

10:                                               ; preds = %8
  %11 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.49) #4
  br label %22

12:                                               ; preds = %8
  %13 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %.not8 = icmp eq i32 %13, 0
  br i1 %.not8, label %.thread, label %16

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

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

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

22:                                               ; preds = %.thread, %16, %20, %3, %10
  %.0 = phi i32 [ 0, %10 ], [ 0, %3 ], [ 1, %20 ], [ 1, %16 ], [ 1, %.thread ]
  ret i32 %.0
}

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

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