; 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_INIT = external dso_local global i8, align 1
@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
@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
@RCSGUIFACTORY_DISABLE = external hidden global i8, align 1
@RCSGUIFACTORY_REQUEST_PENDING = external hidden global i8, align 1
@__func__.RcsGuiFactory_requestGUI = external hidden unnamed_addr constant [25 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@RCSGUIFACTORY_CURRENT_GUI = external hidden global i32, align 4
@RCSGUIFACTORY_CALLBACK = external hidden global ptr, align 8
@RCSGUIFACTORY_ARG = external hidden global ptr, align 8

; 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

declare void @Timer_usleep(i64 noundef) #2

; 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 i32 @RcsGuiFactory_requestGUI(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  %9 = load i8, ptr @RCSGUIFACTORY_DISABLE, align 1, !tbaa !11, !range !13, !noundef !14
  %10 = trunc i8 %9 to i1
  %11 = zext i1 %10 to i32
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %78

14:                                               ; preds = %2
  %15 = load i8, ptr @RCSGUIFACTORY_INIT, align 1, !tbaa !11, !range !13, !noundef !14
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i32
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %14
  call void @RcsGuiFactory_init()
  br label %20

20:                                               ; preds = %19, %14
  br label %21

21:                                               ; preds = %50, %20
  %22 = load i8, ptr @RCSGUIFACTORY_REQUEST_PENDING, align 1, !tbaa !11, !range !13, !noundef !14
  %23 = trunc i8 %22 to i1
  br i1 %23, label %24, label %51

24:                                               ; preds = %21
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %6, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 100
  br i1 %28, label %29, label %50

29:                                               ; preds = %24
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !9
  call void (i32, ptr, ptr, i32, ptr, ...) %34(i32 noundef 1, ptr noundef @.str.1, ptr noundef @__func__.RcsGuiFactory_requestGUI, i32 noundef 214, ptr noundef @.str.6, i32 noundef %35)
  br label %36

36:                                               ; preds = %33, %30
  %37 = load i32, ptr @RcsLogLevel, align 4, !tbaa !9
  %38 = icmp sle i32 1, %37
  br i1 %38, label %39, label %47

39:                                               ; preds = %36
  %40 = load ptr, ptr @stderr, align 8, !tbaa !5
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str.4, ptr noundef @.str.1, ptr noundef @__func__.RcsGuiFactory_requestGUI, i32 noundef 214) #4
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str.6, i32 noundef %43) #4
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.5) #4
  br label %47

47:                                               ; preds = %39, %36
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49, %24
  call void @Timer_usleep(i64 noundef 10000)
  br label %21, !llvm.loop !15

51:                                               ; preds = %21
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %58

55:                                               ; preds = %52
  %56 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !9
  call void (i32, ptr, ptr, i32, ptr, ...) %56(i32 noundef 5, ptr noundef @.str.1, ptr noundef @__func__.RcsGuiFactory_requestGUI, i32 noundef 219, ptr noundef @.str.7, i32 noundef %57)
  br label %58

58:                                               ; preds = %55, %52
  %59 = load i32, ptr @RcsLogLevel, align 4, !tbaa !9
  %60 = icmp sle i32 5, %59
  br i1 %60, label %61, label %69

61:                                               ; preds = %58
  %62 = load ptr, ptr @stderr, align 8, !tbaa !5
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.4, ptr noundef @.str.1, ptr noundef @__func__.RcsGuiFactory_requestGUI, i32 noundef 219) #4
  %64 = load ptr, ptr @stderr, align 8, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef @.str.7, i32 noundef %65) #4
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.5) #4
  br label %69

69:                                               ; preds = %61, %58
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  %72 = call i32 @pthread_mutex_lock(ptr noundef @RCSGUIFACTORY_MUTEX) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %73 = load i32, ptr @RCSGUIFACTORY_CURRENT_GUI, align 4, !tbaa !9
  store i32 %73, ptr %8, align 4, !tbaa !9
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %74, ptr @RCSGUIFACTORY_CALLBACK, align 8, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %75, ptr @RCSGUIFACTORY_ARG, align 8, !tbaa !5
  store i8 1, ptr @RCSGUIFACTORY_REQUEST_PENDING, align 1, !tbaa !11
  %76 = call i32 @pthread_mutex_unlock(ptr noundef @RCSGUIFACTORY_MUTEX) #4
  %77 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %77, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %78

78:                                               ; preds = %71, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

; Function Attrs: nounwind uwtable
declare hidden void @RcsGuiFactory_init() #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 = { "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 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 #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}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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_INIT = external dso_local local_unnamed_addr global i8, align 1
@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
@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
@RCSGUIFACTORY_DISABLE = external hidden local_unnamed_addr global i8, align 1
@RCSGUIFACTORY_REQUEST_PENDING = external hidden local_unnamed_addr global i8, align 1
@__func__.RcsGuiFactory_requestGUI = external hidden unnamed_addr constant [25 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@RCSGUIFACTORY_CURRENT_GUI = external hidden local_unnamed_addr global i32, align 4
@RCSGUIFACTORY_CALLBACK = external hidden local_unnamed_addr global ptr, align 8
@RCSGUIFACTORY_ARG = external hidden local_unnamed_addr global ptr, align 8

; 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

declare void @Timer_usleep(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @RcsGuiFactory_requestGUI(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = load i8, ptr @RCSGUIFACTORY_DISABLE, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %46, label %5

5:                                                ; preds = %2
  %6 = load i8, ptr @RCSGUIFACTORY_INIT, align 1, !tbaa !5, !range !9, !noundef !10
  %7 = icmp eq i8 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  tail call void @RcsGuiFactory_init()
  br label %9

9:                                                ; preds = %8, %5
  %10 = load i8, ptr @RCSGUIFACTORY_REQUEST_PENDING, align 1, !tbaa !5, !range !9, !noundef !10
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9, %27
  %.0914 = phi i32 [ %12, %27 ], [ 0, %9 ]
  %12 = add nuw nsw i32 %.0914, 1
  %13 = icmp ugt i32 %.0914, 99
  br i1 %13, label %14, label %27

14:                                               ; preds = %.lr.ph
  %15 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !11
  %.not13 = icmp eq ptr %15, null
  br i1 %.not13, label %17, label %16

16:                                               ; preds = %14
  tail call void (i32, ptr, ptr, i32, ptr, ...) %15(i32 noundef 1, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.RcsGuiFactory_requestGUI, i32 noundef 214, ptr noundef nonnull @.str.6, i32 noundef %12) #4
  br label %17

17:                                               ; preds = %16, %14
  %18 = load i32, ptr @RcsLogLevel, align 4, !tbaa !13
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = load ptr, ptr @stderr, align 8, !tbaa !11
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.RcsGuiFactory_requestGUI, i32 noundef 214) #5
  %23 = load ptr, ptr @stderr, align 8, !tbaa !11
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.6, i32 noundef %12) #5
  %25 = load ptr, ptr @stderr, align 8, !tbaa !11
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.5) #5
  br label %27

27:                                               ; preds = %17, %20, %.lr.ph
  tail call void @Timer_usleep(i64 noundef 10000) #4
  %28 = load i8, ptr @RCSGUIFACTORY_REQUEST_PENDING, align 1, !tbaa !5, !range !9, !noundef !10
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %27, %9
  %.09.lcssa = phi i32 [ 0, %9 ], [ %12, %27 ]
  %30 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !11
  %.not = icmp eq ptr %30, null
  br i1 %.not, label %32, label %31

31:                                               ; preds = %._crit_edge
  tail call void (i32, ptr, ptr, i32, ptr, ...) %30(i32 noundef 5, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.RcsGuiFactory_requestGUI, i32 noundef 219, ptr noundef nonnull @.str.7, i32 noundef %.09.lcssa) #4
  br label %32

32:                                               ; preds = %31, %._crit_edge
  %33 = load i32, ptr @RcsLogLevel, align 4, !tbaa !13
  %34 = icmp sgt i32 %33, 4
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = load ptr, ptr @stderr, align 8, !tbaa !11
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.RcsGuiFactory_requestGUI, i32 noundef 219) #5
  %38 = load ptr, ptr @stderr, align 8, !tbaa !11
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.7, i32 noundef %.09.lcssa) #5
  %40 = load ptr, ptr @stderr, align 8, !tbaa !11
  %41 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.5) #5
  br label %42

42:                                               ; preds = %35, %32
  %43 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull @RCSGUIFACTORY_MUTEX) #4
  %44 = load i32, ptr @RCSGUIFACTORY_CURRENT_GUI, align 4, !tbaa !13
  store ptr %0, ptr @RCSGUIFACTORY_CALLBACK, align 8, !tbaa !11
  store ptr %1, ptr @RCSGUIFACTORY_ARG, align 8, !tbaa !11
  store i8 1, ptr @RCSGUIFACTORY_REQUEST_PENDING, align 1, !tbaa !5
  %45 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull @RCSGUIFACTORY_MUTEX) #4
  br label %46

46:                                               ; preds = %2, %42
  %.0 = phi i32 [ %44, %42 ], [ -1, %2 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @RcsGuiFactory_init() 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 = { "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 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 #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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass