; LLVM IR from petecoup/argon :: src/codec (ppm_codec)

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

@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_eof(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @ar_peek(ptr noundef) #0

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

declare i32 @fgetc(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @scan_comment(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @scan_past_whitespace(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  br label %4

4:                                                ; preds = %46, %1
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call zeroext i1 @is_eof(ptr noundef %5)
  br i1 %6, label %31, label %7

7:                                                ; preds = %4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call signext i8 @ar_peek(ptr noundef %8)
  store i8 %9, ptr %3, align 1, !tbaa !9
  %10 = sext i8 %9 to i32
  %11 = icmp ne i32 %10, -1
  br i1 %11, label %12, label %29

12:                                               ; preds = %7
  %13 = call ptr @__ctype_b_loc() #5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = load i8, ptr %3, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i16, ptr %14, i64 %17
  %19 = load i16, ptr %18, align 2, !tbaa !10
  %20 = zext i16 %19 to i32
  %21 = and i32 %20, 8192
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %27, label %23

23:                                               ; preds = %12
  %24 = load i8, ptr %3, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = icmp eq i32 %25, 35
  br label %27

27:                                               ; preds = %23, %12
  %28 = phi i1 [ true, %12 ], [ %26, %23 ]
  br label %29

29:                                               ; preds = %27, %7
  %30 = phi i1 [ false, %7 ], [ %28, %27 ]
  br label %31

31:                                               ; preds = %29, %4
  %32 = phi i1 [ false, %4 ], [ %30, %29 ]
  br i1 %32, label %33, label %47

33:                                               ; preds = %31
  %34 = load i8, ptr %3, align 1, !tbaa !9
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 %35, 35
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @scan_comment(ptr noundef %38)
  br label %46

39:                                               ; preds = %33
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = call i32 @fgetc(ptr noundef %40)
  %42 = trunc i32 %41 to i8
  store i8 %42, ptr %3, align 1, !tbaa !9
  %43 = load i8, ptr %3, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %44)
  br label %46

46:                                               ; preds = %39, %37
  br label %4, !llvm.loop !12

47:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  ret void
}

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { nounwind }
attributes #5 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_eof(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @ar_peek(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @scan_comment(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @scan_past_whitespace(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i1 @is_eof(ptr noundef %0)
  br i1 %2, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %20
  %3 = tail call signext i8 @ar_peek(ptr noundef %0)
  %.not = icmp eq i8 %3, -1
  br i1 %.not, label %.critedge, label %4

4:                                                ; preds = %.lr.ph
  %5 = tail call ptr @__ctype_b_loc() #3
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = sext i8 %3 to i64
  %8 = getelementptr inbounds i16, ptr %6, i64 %7
  %9 = load i16, ptr %8, align 2, !tbaa !9
  %10 = and i16 %9, 8192
  %11 = icmp ne i16 %10, 0
  %12 = icmp eq i8 %3, 35
  %13 = or i1 %12, %11
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %4
  br i1 %12, label %15, label %16

15:                                               ; preds = %14
  tail call void @scan_comment(ptr noundef %0)
  br label %20

16:                                               ; preds = %14
  %17 = tail call i32 @fgetc(ptr noundef %0)
  %sext = shl i32 %17, 24
  %18 = ashr exact i32 %sext, 24
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %18)
  br label %20

20:                                               ; preds = %16, %15
  %21 = tail call zeroext i1 @is_eof(ptr noundef %0)
  br i1 %21, label %.critedge, label %.lr.ph, !llvm.loop !11

.critedge:                                        ; preds = %4, %.lr.ph, %20, %1
  ret void
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #2

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 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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