; LLVM IR from m-boutaleb/LZS :: src (completion_bar_service)

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

@stdout = external global ptr, align 8
@read_byte_update_c_bar.comp_bar_pos = external hidden global i64, align 8
@completion_bar = external hidden global i16, align 2
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @read_byte_update_c_bar(ptr noundef %0) #0 {
  %2 = alloca i16, align 2
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr @stdout, align 8, !tbaa !5
  %7 = call i32 @setvbuf(ptr noundef %6, ptr noundef null, i32 noundef 2, i64 noundef 0) #4
  %8 = call i64 (...) @get_input_file_size()
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store i16 0, ptr %2, align 2
  br label %45

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #4
  %12 = load i64, ptr @read_byte_update_c_bar.comp_bar_pos, align 8, !tbaa !9
  %13 = mul i64 %12, 47
  %14 = call i64 (...) @get_input_file_size()
  %15 = udiv i64 %13, %14
  %16 = trunc i64 %15 to i16
  store i16 %16, ptr %4, align 2, !tbaa !11
  %17 = load i64, ptr @read_byte_update_c_bar.comp_bar_pos, align 8, !tbaa !9
  %18 = add i64 %17, 1
  store i64 %18, ptr @read_byte_update_c_bar.comp_bar_pos, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  %19 = load i16, ptr %4, align 2, !tbaa !11
  %20 = zext i16 %19 to i32
  %21 = load i16, ptr @completion_bar, align 2, !tbaa !11
  %22 = zext i16 %21 to i32
  %23 = icmp sgt i32 %20, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %11
  %25 = load i16, ptr %4, align 2, !tbaa !11
  %26 = zext i16 %25 to i32
  %27 = load i16, ptr @completion_bar, align 2, !tbaa !11
  %28 = zext i16 %27 to i32
  %29 = sub nsw i32 %26, %28
  br label %31

30:                                               ; preds = %11
  br label %31

31:                                               ; preds = %30, %24
  %32 = phi i32 [ %29, %24 ], [ 0, %30 ]
  %33 = trunc i32 %32 to i16
  store i16 %33, ptr %5, align 2, !tbaa !11
  %34 = load i16, ptr %4, align 2, !tbaa !11
  store i16 %34, ptr @completion_bar, align 2, !tbaa !11
  br label %35

35:                                               ; preds = %39, %31
  %36 = load i16, ptr %5, align 2, !tbaa !11
  %37 = add i16 %36, -1
  store i16 %37, ptr %5, align 2, !tbaa !11
  %38 = icmp ne i16 %36, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %35
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %35, !llvm.loop !13

41:                                               ; preds = %35
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call zeroext i8 @read_byte(ptr noundef %42)
  %44 = zext i8 %43 to i16
  store i16 %44, ptr %2, align 2
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #4
  br label %45

45:                                               ; preds = %41, %10
  %46 = load i16, ptr %2, align 2
  ret i16 %46
}

; Function Attrs: nounwind
declare i32 @setvbuf(ptr noundef, ptr noundef, i32 noundef, i64 noundef) #1

declare i64 @get_input_file_size(...) #2

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

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

declare zeroext i8 @read_byte(ptr noundef) #2

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@stdout = external local_unnamed_addr global ptr, align 8
@read_byte_update_c_bar.comp_bar_pos = external hidden local_unnamed_addr global i64, align 8
@completion_bar = external hidden local_unnamed_addr global i16, align 2
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i16 0, 256) i16 @read_byte_update_c_bar(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @stdout, align 8, !tbaa !5
  %3 = tail call i32 @setvbuf(ptr noundef %2, ptr noundef null, i32 noundef 2, i64 noundef 0) #4
  %4 = tail call i64 (...) @get_input_file_size() #4
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %23, label %5

5:                                                ; preds = %1
  %6 = load i64, ptr @read_byte_update_c_bar.comp_bar_pos, align 8, !tbaa !9
  %7 = mul i64 %6, 47
  %8 = tail call i64 (...) @get_input_file_size() #4
  %9 = udiv i64 %7, %8
  %10 = trunc i64 %9 to i16
  %11 = load i64, ptr @read_byte_update_c_bar.comp_bar_pos, align 8, !tbaa !9
  %12 = add i64 %11, 1
  store i64 %12, ptr @read_byte_update_c_bar.comp_bar_pos, align 8, !tbaa !9
  %13 = trunc i64 %9 to i32
  %14 = and i32 %13, 65535
  %15 = load i16, ptr @completion_bar, align 2
  %16 = zext i16 %15 to i32
  store i16 %10, ptr @completion_bar, align 2, !tbaa !11
  %.not67.not = icmp ugt i32 %14, %16
  br i1 %.not67.not, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %17 = tail call i32 @llvm.usub.sat.i32(i32 %14, i32 %16)
  %18 = trunc nuw i32 %17 to i16
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.08 = phi i16 [ %19, %.lr.ph ], [ %18, %.lr.ph.preheader ]
  %19 = add i16 %.08, -1
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %.not6 = icmp eq i16 %19, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %5
  %21 = tail call zeroext i8 @read_byte(ptr noundef %0) #4
  %22 = zext i8 %21 to i16
  br label %23

23:                                               ; preds = %1, %._crit_edge
  %.05 = phi i16 [ %22, %._crit_edge ], [ 0, %1 ]
  ret i16 %.05
}

; Function Attrs: nofree nounwind
declare noundef i32 @setvbuf(ptr nocapture noundef, ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

declare i64 @get_input_file_size(...) local_unnamed_addr #2

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

declare zeroext i8 @read_byte(ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.usub.sat.i32(i32, i32) #3

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 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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