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

; 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
@.str.78 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [28 x i8], align 1
@objectCount = external hidden global i32, align 4
@dctXCreateD = external hidden global ptr, align 8
@.str.80 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__.dctCreateDD = external hidden unnamed_addr constant [58 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 @dctGetReadyD(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 @dctCreateDD(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 @dctGetReadyD(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 %46

19:                                               ; preds = %4
  %20 = load ptr, ptr @dctXCreateD, 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.80, ptr noundef @.str.78, i32 noundef 1168, ptr noundef @__PRETTY_FUNCTION__.dctCreateDD) #5
  unreachable

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

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

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

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

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

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

45:                                               ; preds = %43, %38
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %46

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

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
@.str.78 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [28 x i8], align 1
@objectCount = external hidden local_unnamed_addr global i32, align 4
@dctXCreateD = external hidden local_unnamed_addr global ptr, align 8
@.str.80 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__.dctCreateDD = external hidden unnamed_addr constant [58 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 @dctGetReadyD(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 @dctCreateDD(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = tail call i32 @dctGetReadyD(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 @dctXCreateD, align 8, !tbaa !5
  %.not9 = icmp eq ptr %7, null
  br i1 %.not9, label %8, label %9

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.80, ptr noundef nonnull @.str.78, i32 noundef 1168, ptr noundef nonnull @__PRETTY_FUNCTION__.dctCreateDD) #3
  unreachable

9:                                                ; preds = %6
  tail call void %7(ptr noundef %0, ptr noundef %1) #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.79) #4
  br label %23

13:                                               ; preds = %9
  %14 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %.not10 = icmp eq i32 %14, 0
  br i1 %.not10, 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
  %.not11 = icmp eq i32 %.pr, 0
  br i1 %.not11, 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