; LLVM IR from HANDS-FREE/OpenRE :: 3_OS/STM32F1/GUI/STemWin/Demo (GUIDEMO)

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

@_hDialogControl = external hidden global i64, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @GUIDEMO_CheckCancel() #1

declare void @GUI_Delay(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @GUIDEMO_Delay(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load i64, ptr @_hDialogControl, align 8, !tbaa !9
  %8 = call i64 @WM_GetDialogItem(i64 noundef %7, i32 noundef 528)
  store i64 %8, ptr %3, align 8, !tbaa !9
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 100
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  call void @_ShowProgress()
  br label %12

12:                                               ; preds = %11, %1
  %13 = load i64, ptr %3, align 8, !tbaa !9
  call void @PROGBAR_SetValue(i64 noundef %13, i32 noundef 0)
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  call void @PROGBAR_SetMinMax(i64 noundef %14, i32 noundef 0, i32 noundef %15)
  %16 = call i32 @GUI_GetTime()
  %17 = sext i32 %16 to i64
  store i64 %17, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %40, %12
  %19 = call i32 @GUIDEMO_GetTime()
  %20 = sext i32 %19 to i64
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = sub i64 %20, %21
  store i64 %22, ptr %6, align 8, !tbaa !9
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp sgt i32 %23, 100
  br i1 %24, label %25, label %29

25:                                               ; preds = %18
  %26 = load i64, ptr %3, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = trunc i64 %27 to i32
  call void @PROGBAR_SetValue(i64 noundef %26, i32 noundef %28)
  br label %29

29:                                               ; preds = %25, %18
  call void @GUI_Delay(i32 noundef 5)
  %30 = call i32 @GUIDEMO_CheckCancel()
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %29
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = icmp ult i64 %32, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %31
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  %39 = xor i1 %38, true
  br label %40

40:                                               ; preds = %36, %31
  %41 = phi i1 [ false, %31 ], [ %39, %36 ]
  br i1 %41, label %18, label %42, !llvm.loop !11

42:                                               ; preds = %40
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = icmp sgt i32 %43, 100
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  call void @_HideProgress()
  br label %46

46:                                               ; preds = %45, %42
  %47 = call i32 @GUI_Exec()
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare i64 @WM_GetDialogItem(i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @_ShowProgress() #1

declare void @PROGBAR_SetValue(i64 noundef, i32 noundef) #2

declare void @PROGBAR_SetMinMax(i64 noundef, i32 noundef, i32 noundef) #2

declare i32 @GUI_GetTime() #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @GUIDEMO_GetTime() #1

; Function Attrs: nounwind uwtable
declare hidden void @_HideProgress() #1

declare i32 @GUI_Exec() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 }

!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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@_hDialogControl = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @GUIDEMO_CheckCancel() local_unnamed_addr #0

declare void @GUI_Delay(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @GUIDEMO_Delay(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @_hDialogControl, align 8, !tbaa !5
  %3 = tail call i64 @WM_GetDialogItem(i64 noundef %2, i32 noundef 528) #2
  %4 = icmp sgt i32 %0, 100
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  tail call void @_ShowProgress()
  br label %6

6:                                                ; preds = %5, %1
  tail call void @PROGBAR_SetValue(i64 noundef %3, i32 noundef 0) #2
  tail call void @PROGBAR_SetMinMax(i64 noundef %3, i32 noundef 0, i32 noundef %0) #2
  %7 = tail call i32 @GUI_GetTime() #2
  %8 = sext i32 %7 to i64
  %9 = sext i32 %0 to i64
  br i1 %4, label %.split.us, label %.split

.split.us:                                        ; preds = %6, %.split.us
  %10 = tail call i32 @GUIDEMO_GetTime()
  %11 = sext i32 %10 to i64
  %12 = sub nsw i64 %11, %8
  %13 = trunc i64 %12 to i32
  tail call void @PROGBAR_SetValue(i64 noundef %3, i32 noundef %13) #2
  tail call void @GUI_Delay(i32 noundef 5) #2
  %14 = tail call i32 @GUIDEMO_CheckCancel()
  %15 = icmp ult i64 %12, %9
  %.not.us = icmp eq i32 %14, 0
  %16 = select i1 %15, i1 %.not.us, i1 false
  br i1 %16, label %.split.us, label %.split13.us, !llvm.loop !9

.split:                                           ; preds = %6, %.split
  %17 = tail call i32 @GUIDEMO_GetTime()
  %18 = sext i32 %17 to i64
  %19 = sub nsw i64 %18, %8
  tail call void @GUI_Delay(i32 noundef 5) #2
  %20 = tail call i32 @GUIDEMO_CheckCancel()
  %21 = icmp ult i64 %19, %9
  %.not = icmp eq i32 %20, 0
  %22 = select i1 %21, i1 %.not, i1 false
  br i1 %22, label %.split, label %.split13.us, !llvm.loop !9

.split13.us:                                      ; preds = %.split, %.split.us
  br i1 %4, label %23, label %24

23:                                               ; preds = %.split13.us
  tail call void @_HideProgress()
  br label %24

24:                                               ; preds = %23, %.split13.us
  %25 = tail call i32 @GUI_Exec() #2
  ret void
}

declare i64 @WM_GetDialogItem(i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @_ShowProgress() local_unnamed_addr #0

declare void @PROGBAR_SetValue(i64 noundef, i32 noundef) local_unnamed_addr #1

declare void @PROGBAR_SetMinMax(i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @GUI_GetTime() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @GUIDEMO_GetTime() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @_HideProgress() local_unnamed_addr #0

declare i32 @GUI_Exec() 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 = { "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 }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass