; 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
@exceptMutex = external hidden global %union.pthread_mutex_t, align 8
@.str.48 = external hidden unnamed_addr constant [86 x i8], align 1
@ScreenIndicator = external hidden global i32, align 4
@ExceptionIndicator = external hidden global i32, align 4
@ExitIndicator = external hidden global i32, align 4
@ErrorCallBack = external hidden global ptr, align 8
@APIErrorCount = external hidden global i32, align 4
@.str.53 = external hidden unnamed_addr constant [4 x i8], align 1
@stdout = external global ptr, align 8
@.str.54 = external hidden unnamed_addr constant [20 x i8], align 1
@__PRETTY_FUNCTION__.cfgErrorHandling = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @cfgErrorHandling(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load i32, ptr @APIErrorCount, align 4, !tbaa !9
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @APIErrorCount, align 4, !tbaa !9
  %5 = load i32, ptr @ScreenIndicator, align 4, !tbaa !9
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %12

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.53, ptr noundef %8)
  %10 = load ptr, ptr @stdout, align 8, !tbaa !5
  %11 = call i32 @fflush(ptr noundef %10)
  br label %12

12:                                               ; preds = %7, %1
  %13 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  %16 = call i32 @GC_mutex_lock(ptr noundef @exceptMutex)
  br label %17

17:                                               ; preds = %15, %12
  %18 = load ptr, ptr @ErrorCallBack, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %33

20:                                               ; preds = %17
  %21 = load ptr, ptr @ErrorCallBack, align 8, !tbaa !5
  %22 = load i32, ptr @APIErrorCount, align 4, !tbaa !9
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call i32 %21(i32 noundef %22, ptr noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %32

26:                                               ; preds = %20
  %27 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = call i32 @GC_mutex_unlock(ptr noundef @exceptMutex)
  br label %31

31:                                               ; preds = %29, %26
  call void @exit(i32 noundef 123) #3
  unreachable

32:                                               ; preds = %20
  br label %33

33:                                               ; preds = %32, %17
  %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_unlock(ptr noundef @exceptMutex)
  br label %38

38:                                               ; preds = %36, %33
  %39 = load i32, ptr @ExceptionIndicator, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  br label %43

42:                                               ; preds = %38
  call void @__assert_fail(ptr noundef @.str.54, ptr noundef @.str.48, i32 noundef 1059, ptr noundef @__PRETTY_FUNCTION__.cfgErrorHandling) #3
  unreachable

43:                                               ; preds = %41
  %44 = load i32, ptr @ExitIndicator, align 4, !tbaa !9
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  call void @exit(i32 noundef 123) #3
  unreachable

47:                                               ; preds = %43
  ret void
}

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

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

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

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

declare i32 @fflush(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

attributes #0 = { 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 = { 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 #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 = { 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
@exceptMutex = external hidden global %union.pthread_mutex_t, align 8
@.str.48 = external hidden unnamed_addr constant [86 x i8], align 1
@ScreenIndicator = external hidden local_unnamed_addr global i32, align 4
@ExceptionIndicator = external hidden local_unnamed_addr global i32, align 4
@ExitIndicator = external hidden local_unnamed_addr global i32, align 4
@ErrorCallBack = external hidden local_unnamed_addr global ptr, align 8
@APIErrorCount = external hidden local_unnamed_addr global i32, align 4
@.str.53 = external hidden unnamed_addr constant [4 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.54 = external hidden unnamed_addr constant [20 x i8], align 1
@__PRETTY_FUNCTION__.cfgErrorHandling = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @cfgErrorHandling(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @APIErrorCount, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @APIErrorCount, align 4, !tbaa !5
  %4 = load i32, ptr @ScreenIndicator, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %9, label %5

5:                                                ; preds = %1
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.53, ptr noundef %0)
  %7 = load ptr, ptr @stdout, align 8, !tbaa !9
  %8 = tail call i32 @fflush(ptr noundef %7)
  br label %9

9:                                                ; preds = %5, %1
  %10 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !5
  %.not2 = icmp eq i32 %10, 0
  br i1 %.not2, label %13, label %11

11:                                               ; preds = %9
  %12 = tail call i32 @GC_mutex_lock(ptr noundef nonnull @exceptMutex)
  br label %13

13:                                               ; preds = %11, %9
  %14 = load ptr, ptr @ErrorCallBack, align 8, !tbaa !9
  %.not3 = icmp eq ptr %14, null
  br i1 %.not3, label %._crit_edge, label %15

._crit_edge:                                      ; preds = %13
  %.pre = load i32, ptr @MutexIsInitialized, align 4, !tbaa !5
  br label %22

15:                                               ; preds = %13
  %16 = load i32, ptr @APIErrorCount, align 4, !tbaa !5
  %17 = tail call i32 %14(i32 noundef %16, ptr noundef %0) #3
  %.not4 = icmp eq i32 %17, 0
  %.pre9 = load i32, ptr @MutexIsInitialized, align 4, !tbaa !5
  br i1 %.not4, label %22, label %18

18:                                               ; preds = %15
  %.not8 = icmp eq i32 %.pre9, 0
  br i1 %.not8, label %21, label %19

19:                                               ; preds = %18
  %20 = tail call i32 @GC_mutex_unlock(ptr noundef nonnull @exceptMutex)
  br label %21

21:                                               ; preds = %19, %18
  tail call void @exit(i32 noundef 123) #4
  unreachable

22:                                               ; preds = %._crit_edge, %15
  %23 = phi i32 [ %.pre, %._crit_edge ], [ %.pre9, %15 ]
  %.not5 = icmp eq i32 %23, 0
  br i1 %.not5, label %26, label %24

24:                                               ; preds = %22
  %25 = tail call i32 @GC_mutex_unlock(ptr noundef nonnull @exceptMutex)
  br label %26

26:                                               ; preds = %24, %22
  %27 = load i32, ptr @ExceptionIndicator, align 4, !tbaa !5
  %.not6 = icmp eq i32 %27, 0
  br i1 %.not6, label %29, label %28

28:                                               ; preds = %26
  tail call void @__assert_fail(ptr noundef nonnull @.str.54, ptr noundef nonnull @.str.48, i32 noundef 1059, ptr noundef nonnull @__PRETTY_FUNCTION__.cfgErrorHandling) #4
  unreachable

29:                                               ; preds = %26
  %30 = load i32, ptr @ExitIndicator, align 4, !tbaa !5
  %.not7 = icmp eq i32 %30, 0
  br i1 %.not7, label %32, label %31

31:                                               ; preds = %29
  tail call void @exit(i32 noundef 123) #4
  unreachable

32:                                               ; preds = %29
  ret void
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 = { 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 #2 = { nofree 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 = { nounwind }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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