; LLVM IR from BlueBrain/CoreNeuron :: coreneuron/utils/progressbar/progressbar.ll (Z18progressbar_updateP11progressbarmd)

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

%struct.progressbar = type { i64, i64, i64, i64, i64, i64, i64, ptr, double, %struct.anon }
%struct.anon = type { i8, i8, i8 }

; 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 @isatty(i32 noundef) #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16progressbar_drawPK11progressbar(ptr noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare double @difftime(i64 noundef, i64 noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z18progressbar_updateP11progressbarmd(ptr noundef %0, i64 noundef %1, double noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !11
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.progressbar, ptr %11, i32 0, i32 1
  store i64 %10, ptr %12, align 8, !tbaa !13
  %13 = load double, ptr %6, align 8, !tbaa !11
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.progressbar, ptr %14, i32 0, i32 8
  store double %13, ptr %15, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %16 = call i64 @time(ptr noundef null) #5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.progressbar, ptr %17, i32 0, i32 5
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = call double @difftime(i64 noundef %16, i64 noundef %19) #6
  %21 = fptosi double %20 to i32
  store i32 %21, ptr %7, align 4, !tbaa !18
  %22 = load i32, ptr %7, align 4, !tbaa !18
  %23 = sext i32 %22 to i64
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.progressbar, ptr %24, i32 0, i32 6
  %26 = load i64, ptr %25, align 8, !tbaa !20
  %27 = sub nsw i64 %23, %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.progressbar, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !21
  %31 = icmp slt i64 %27, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %3
  store i32 1, ptr %8, align 4
  br label %88

33:                                               ; preds = %3
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL16progressbar_drawPK11progressbar(ptr noundef %34)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.progressbar, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !22
  %38 = add i64 %37, 1
  store i64 %38, ptr %36, align 8, !tbaa !22
  %39 = load i32, ptr %7, align 4, !tbaa !18
  %40 = sext i32 %39 to i64
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.progressbar, ptr %41, i32 0, i32 6
  store i64 %40, ptr %42, align 8, !tbaa !20
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.progressbar, ptr %43, i32 0, i32 4
  %45 = load i64, ptr %44, align 8, !tbaa !22
  %46 = icmp uge i64 %45, 500
  br i1 %46, label %50, label %47

47:                                               ; preds = %33
  %48 = load i32, ptr %7, align 4, !tbaa !18
  %49 = icmp slt i32 %48, 15
  br i1 %49, label %50, label %51

50:                                               ; preds = %47, %33
  store i32 1, ptr %8, align 4
  br label %88

51:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call noundef i32 @_ZL29progressbar_remaining_secondsPK11progressbar(ptr noundef %52)
  store i32 %53, ptr %9, align 4, !tbaa !18
  %54 = load i32, ptr %9, align 4, !tbaa !18
  %55 = sext i32 %54 to i64
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.progressbar, ptr %56, i32 0, i32 4
  %58 = load i64, ptr %57, align 8, !tbaa !22
  %59 = sub i64 500, %58
  %60 = udiv i64 %55, %59
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.progressbar, ptr %61, i32 0, i32 3
  store i64 %60, ptr %62, align 8, !tbaa !21
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.progressbar, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !21
  %66 = icmp slt i64 %65, 5
  br i1 %66, label %67, label %87

67:                                               ; preds = %51
  %68 = call i32 @isatty(i32 noundef 1) #5
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %82

70:                                               ; preds = %67
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.progressbar, ptr %71, i32 0, i32 3
  %73 = load i64, ptr %72, align 8, !tbaa !21
  %74 = icmp slt i64 %73, 1
  br i1 %74, label %75, label %76

75:                                               ; preds = %70
  br label %80

76:                                               ; preds = %70
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.progressbar, ptr %77, i32 0, i32 3
  %79 = load i64, ptr %78, align 8, !tbaa !21
  br label %80

80:                                               ; preds = %76, %75
  %81 = phi i64 [ 1, %75 ], [ %79, %76 ]
  br label %83

82:                                               ; preds = %67
  br label %83

83:                                               ; preds = %82, %80
  %84 = phi i64 [ %81, %80 ], [ 5, %82 ]
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.progressbar, ptr %85, i32 0, i32 3
  store i64 %84, ptr %86, align 8, !tbaa !21
  br label %87

87:                                               ; preds = %83, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  store i32 0, ptr %8, align 4
  br label %88

88:                                               ; preds = %87, %50, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  %89 = load i32, ptr %8, align 4
  switch i32 %89, label %91 [
    i32 0, label %90
    i32 1, label %90
  ]

90:                                               ; preds = %88, %88
  ret void

91:                                               ; preds = %88
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL29progressbar_remaining_secondsPK11progressbar(ptr noundef) #4

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 = { mustprogress 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 = { nounwind willreturn memory(none) "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 = { mustprogress 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTS11progressbar", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !12, i64 64, !15, i64 72}
!15 = !{!"_ZTSN11progressbarUt_E", !7, i64 0, !7, i64 1, !7, i64 2}
!16 = !{!14, !12, i64 64}
!17 = !{!14, !10, i64 40}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!14, !10, i64 48}
!21 = !{!14, !10, i64 24}
!22 = !{!14, !10, i64 32}


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

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16progressbar_drawPK11progressbar(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare double @difftime(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z18progressbar_updateP11progressbarmd(ptr noundef %0, i64 noundef %1, double noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %1, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  store double %2, ptr %5, align 8, !tbaa !13
  %6 = tail call i64 @time(ptr noundef null) #5
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %9 = tail call double @difftime(i64 noundef %6, i64 noundef %8) #6
  %10 = fptosi double %9 to i32
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = sub nsw i64 %11, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i64, ptr %15, align 8, !tbaa !16
  %17 = icmp slt i64 %14, %16
  br i1 %17, label %37, label %18

18:                                               ; preds = %3
  tail call void @_ZL16progressbar_drawPK11progressbar(ptr noundef nonnull %0)
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load i64, ptr %19, align 8, !tbaa !17
  %21 = add i64 %20, 1
  store i64 %21, ptr %19, align 8, !tbaa !17
  store i64 %11, ptr %12, align 8, !tbaa !15
  %22 = icmp ugt i64 %21, 499
  %23 = icmp slt i32 %10, 15
  %or.cond = or i1 %23, %22
  br i1 %or.cond, label %37, label %24

24:                                               ; preds = %18
  %25 = tail call noundef i32 @_ZL29progressbar_remaining_secondsPK11progressbar(ptr noundef nonnull %0)
  %26 = sext i32 %25 to i64
  %27 = load i64, ptr %19, align 8, !tbaa !17
  %28 = sub i64 500, %27
  %29 = udiv i64 %26, %28
  store i64 %29, ptr %15, align 8, !tbaa !16
  %30 = icmp slt i64 %29, 5
  br i1 %30, label %31, label %37

31:                                               ; preds = %24
  %32 = tail call i32 @isatty(i32 noundef 1) #5
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %35, label %33

33:                                               ; preds = %31
  %34 = load i64, ptr %15, align 8, !tbaa !16
  %spec.select = tail call i64 @llvm.smax.i64(i64 %34, i64 1)
  br label %35

35:                                               ; preds = %33, %31
  %36 = phi i64 [ 5, %31 ], [ %spec.select, %33 ]
  store i64 %36, ptr %15, align 8, !tbaa !16
  br label %37

37:                                               ; preds = %24, %35, %18, %3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL29progressbar_remaining_secondsPK11progressbar(ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #4

attributes #0 = { 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 = { mustprogress 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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, !7, i64 8}
!6 = !{!"_ZTS11progressbar", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !11, i64 64, !12, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"_ZTSN11progressbarUt_E", !8, i64 0, !8, i64 1, !8, i64 2}
!13 = !{!6, !11, i64 64}
!14 = !{!6, !7, i64 40}
!15 = !{!6, !7, i64 48}
!16 = !{!6, !7, i64 24}
!17 = !{!6, !7, i64 32}


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