; LLVM IR from HRI-EU/Rcs :: src/RcsGui (Rcs_guiFactory)

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

@RCSGUIFACTORY_MUTEX = external hidden global %union.pthread_mutex_t, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@RCSGUIFACTORY_HANDLE = external hidden global [256 x ptr], align 16
@RCS_GLOBAL_RLOG_CB = external global ptr, align 8
@RcsLogLevel = external global i32, align 4
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.RcsGuiFactory_destroyGUI = external hidden unnamed_addr constant [25 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [36 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @RcsGuiFactory_destroyGUI(i32 noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = call i32 @pthread_mutex_lock(ptr noundef @RCSGUIFACTORY_MUTEX) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = call zeroext i1 @RcsGuiFactory_deleteGUI(i32 noundef %7)
  %9 = zext i1 %8 to i8
  store i8 %9, ptr %4, align 1, !tbaa !9
  %10 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc i8 %10 to i1
  br i1 %11, label %34, label %12

12:                                               ; preds = %1
  br label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !13
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !13
  %18 = load i32, ptr %3, align 4, !tbaa !5
  call void (i32, ptr, ptr, i32, ptr, ...) %17(i32 noundef 4, ptr noundef @.str.1, ptr noundef @__func__.RcsGuiFactory_destroyGUI, i32 noundef 335, ptr noundef @.str.10, i32 noundef %18)
  br label %19

19:                                               ; preds = %16, %13
  %20 = load i32, ptr @RcsLogLevel, align 4, !tbaa !5
  %21 = icmp sle i32 4, %20
  br i1 %21, label %22, label %30

22:                                               ; preds = %19
  %23 = load ptr, ptr @stderr, align 8, !tbaa !13
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.4, ptr noundef @.str.1, ptr noundef @__func__.RcsGuiFactory_destroyGUI, i32 noundef 335) #4
  %25 = load ptr, ptr @stderr, align 8, !tbaa !13
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.10, i32 noundef %26) #4
  %28 = load ptr, ptr @stderr, align 8, !tbaa !13
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.5) #4
  br label %30

30:                                               ; preds = %22, %19
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = call i32 @pthread_mutex_unlock(ptr noundef @RCSGUIFACTORY_MUTEX) #4
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %39

34:                                               ; preds = %1
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [256 x ptr], ptr @RCSGUIFACTORY_HANDLE, i64 0, i64 %36
  store ptr null, ptr %37, align 8, !tbaa !13
  %38 = call i32 @pthread_mutex_unlock(ptr noundef @RCSGUIFACTORY_MUTEX) #4
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %39

39:                                               ; preds = %34, %32
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  %40 = load i1, ptr %2, align 1
  ret i1 %40
}

declare zeroext i1 @RcsGuiFactory_deleteGUI(i32 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !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 }

@RCSGUIFACTORY_MUTEX = external hidden global %union.pthread_mutex_t, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@RCSGUIFACTORY_HANDLE = external hidden local_unnamed_addr global [256 x ptr], align 16
@RCS_GLOBAL_RLOG_CB = external local_unnamed_addr global ptr, align 8
@RcsLogLevel = external local_unnamed_addr global i32, align 4
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.RcsGuiFactory_destroyGUI = external hidden unnamed_addr constant [25 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [36 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @RcsGuiFactory_destroyGUI(i32 noundef %0) local_unnamed_addr #2 {
  %2 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull @RCSGUIFACTORY_MUTEX) #4
  %3 = tail call zeroext i1 @RcsGuiFactory_deleteGUI(i32 noundef %0) #4
  br i1 %3, label %17, label %4

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

6:                                                ; preds = %4
  tail call void (i32, ptr, ptr, i32, ptr, ...) %5(i32 noundef 4, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.RcsGuiFactory_destroyGUI, i32 noundef 335, ptr noundef nonnull @.str.10, i32 noundef %0) #4
  br label %7

7:                                                ; preds = %6, %4
  %8 = load i32, ptr @RcsLogLevel, align 4, !tbaa !9
  %9 = icmp sgt i32 %8, 3
  br i1 %9, label %10, label %20

10:                                               ; preds = %7
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.RcsGuiFactory_destroyGUI, i32 noundef 335) #5
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.10, i32 noundef %0) #5
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.5) #5
  br label %20

17:                                               ; preds = %1
  %18 = sext i32 %0 to i64
  %19 = getelementptr inbounds [256 x ptr], ptr @RCSGUIFACTORY_HANDLE, i64 0, i64 %18
  store ptr null, ptr %19, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %7, %10, %17
  %21 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull @RCSGUIFACTORY_MUTEX) #4
  ret i1 %3
}

declare zeroext i1 @RcsGuiFactory_deleteGUI(i32 noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { "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 = { cold 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,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass