; LLVM IR from fwip/fastqz :: fapacks (main)

; 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 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 3
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @exit(i32 noundef 1) #5
  unreachable

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds ptr, ptr %18, i64 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = call noalias ptr @fopen(ptr noundef %20, ptr noundef @.str.1)
  store ptr %21, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 1, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 2, ptr %9, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %114, %17
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %117

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = call noalias ptr @fopen(ptr noundef %38, ptr noundef @.str.3)
  store ptr %39, ptr %11, align 8, !tbaa !9
  %40 = load ptr, ptr %11, align 8, !tbaa !9
  %41 = icmp ne ptr %40, null
  br i1 %41, label %43, label %42

42:                                               ; preds = %27
  store i32 4, ptr %10, align 4
  br label %111

43:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #6
  store i8 1, ptr %12, align 1, !tbaa !11
  br label %44

44:                                               ; preds = %103, %43
  %45 = load ptr, ptr %11, align 8, !tbaa !9
  %46 = call i32 @getc(ptr noundef %45)
  store i32 %46, ptr %8, align 4, !tbaa !5
  %47 = icmp ne i32 %46, -1
  br i1 %47, label %48, label %104

48:                                               ; preds = %44
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = icmp eq i32 %49, 62
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i8 0, ptr %12, align 1, !tbaa !11
  br label %57

52:                                               ; preds = %48
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = icmp eq i32 %53, 10
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  store i8 1, ptr %12, align 1, !tbaa !11
  br label %56

56:                                               ; preds = %55, %52
  br label %57

57:                                               ; preds = %56, %51
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = call i32 @islower(i32 noundef %58) #7
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %64

61:                                               ; preds = %57
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = call i32 @toupper(i32 noundef %62) #7
  store i32 %63, ptr %8, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %61, %57
  %65 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %66 = trunc i8 %65 to i1
  br i1 %66, label %67, label %103

67:                                               ; preds = %64
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = icmp eq i32 %68, 65
  br i1 %69, label %70, label %73

70:                                               ; preds = %67
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = mul nsw i32 %71, 4
  store i32 %72, ptr %7, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %70, %67
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = icmp eq i32 %74, 67
  br i1 %75, label %76, label %80

76:                                               ; preds = %73
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = mul nsw i32 %77, 4
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %7, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %76, %73
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = icmp eq i32 %81, 71
  br i1 %82, label %83, label %87

83:                                               ; preds = %80
  %84 = load i32, ptr %7, align 4, !tbaa !5
  %85 = mul nsw i32 %84, 4
  %86 = add nsw i32 %85, 2
  store i32 %86, ptr %7, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %83, %80
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = icmp eq i32 %88, 84
  br i1 %89, label %90, label %94

90:                                               ; preds = %87
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = mul nsw i32 %91, 4
  %93 = add nsw i32 %92, 3
  store i32 %93, ptr %7, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %90, %87
  %95 = load i32, ptr %7, align 4, !tbaa !5
  %96 = icmp sge i32 %95, 256
  br i1 %96, label %97, label %102

97:                                               ; preds = %94
  %98 = load i32, ptr %7, align 4, !tbaa !5
  %99 = and i32 %98, 255
  %100 = load ptr, ptr %6, align 8, !tbaa !9
  %101 = call i32 @putc(i32 noundef %99, ptr noundef %100)
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %102

102:                                              ; preds = %97, %94
  br label %103

103:                                              ; preds = %102, %64
  br label %44, !llvm.loop !15

104:                                              ; preds = %44
  %105 = load ptr, ptr %11, align 8, !tbaa !9
  %106 = icmp ne ptr %105, null
  br i1 %106, label %107, label %110

107:                                              ; preds = %104
  %108 = load ptr, ptr %11, align 8, !tbaa !9
  %109 = call i32 @fclose(ptr noundef %108)
  br label %110

110:                                              ; preds = %107, %104
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #6
  store i32 0, ptr %10, align 4
  br label %111

111:                                              ; preds = %110, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  %112 = load i32, ptr %10, align 4
  switch i32 %112, label %121 [
    i32 0, label %113
    i32 4, label %114
  ]

113:                                              ; preds = %111
  br label %114

114:                                              ; preds = %113, %111
  %115 = load i32, ptr %9, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %9, align 4, !tbaa !5
  br label %22, !llvm.loop !17

117:                                              ; preds = %26
  %118 = load ptr, ptr %6, align 8, !tbaa !9
  %119 = call i32 @fclose(ptr noundef %118)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %120 = load i32, ptr %3, align 4
  ret i32 %120

121:                                              ; preds = %111
  unreachable
}

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare i32 @getc(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @islower(i32 noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare i32 @toupper(i32 noundef) #4

declare i32 @putc(i32 noundef, ptr noundef) #1

declare i32 @fclose(ptr noundef) #1

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

attributes #0 = { mustprogress norecurse 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 = { noreturn 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(read) "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 = { noreturn nounwind }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"}
!17 = distinct !{!17, !16}


; 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 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 3
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  tail call void @exit(i32 noundef 1) #4
  unreachable

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call noalias ptr @fopen(ptr noundef %8, ptr noundef nonnull @.str.1)
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %12

10:                                               ; preds = %43
  %11 = tail call i32 @fclose(ptr noundef %9)
  ret i32 0

12:                                               ; preds = %6, %43
  %indvars.iv = phi i64 [ 2, %6 ], [ %indvars.iv.next, %43 ]
  %.03239 = phi i32 [ 1, %6 ], [ %.7, %43 ]
  %13 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %14)
  %16 = load ptr, ptr %13, align 8, !tbaa !5
  %17 = tail call noalias ptr @fopen(ptr noundef %16, ptr noundef nonnull @.str.3)
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %43, label %.preheader.outer

.preheader.outer:                                 ; preds = %12, %.preheader.outer.backedge
  %.133.ph = phi i32 [ %.133.ph.be, %.preheader.outer.backedge ], [ %.03239, %12 ]
  %.0.ph = phi i1 [ %.1, %.preheader.outer.backedge ], [ true, %12 ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.outer, %24
  %.0 = phi i1 [ %.1, %24 ], [ %.0.ph, %.preheader.outer ]
  %18 = tail call i32 @getc(ptr noundef nonnull %17)
  switch i32 %18, label %.fold.split [
    i32 -1, label %41
    i32 62, label %20
    i32 10, label %19
  ]

19:                                               ; preds = %.preheader
  br label %20

.fold.split:                                      ; preds = %.preheader
  br label %20

20:                                               ; preds = %.preheader, %.fold.split, %19
  %.1 = phi i1 [ true, %19 ], [ false, %.preheader ], [ %.0, %.fold.split ]
  %21 = tail call i32 @islower(i32 noundef %18) #5
  %.not38 = icmp eq i32 %21, 0
  br i1 %.not38, label %24, label %22

22:                                               ; preds = %20
  %23 = tail call i32 @toupper(i32 noundef %18) #5
  br label %24

24:                                               ; preds = %22, %20
  %.031 = phi i32 [ %23, %22 ], [ %18, %20 ]
  br i1 %.1, label %25, label %.preheader, !llvm.loop !9

25:                                               ; preds = %24
  %26 = icmp eq i32 %.031, 65
  %27 = shl nsw i32 %.133.ph, 2
  %spec.select = select i1 %26, i32 %27, i32 %.133.ph
  %28 = icmp eq i32 %.031, 67
  %29 = shl nsw i32 %spec.select, 2
  %30 = or disjoint i32 %29, 1
  %.3 = select i1 %28, i32 %30, i32 %spec.select
  %31 = icmp eq i32 %.031, 71
  %32 = shl nsw i32 %.3, 2
  %33 = or disjoint i32 %32, 2
  %.4 = select i1 %31, i32 %33, i32 %.3
  %34 = icmp eq i32 %.031, 84
  %35 = shl nsw i32 %.4, 2
  %36 = or disjoint i32 %35, 3
  %.5 = select i1 %34, i32 %36, i32 %.4
  %37 = icmp sgt i32 %.5, 255
  br i1 %37, label %38, label %.preheader.outer.backedge

38:                                               ; preds = %25
  %39 = and i32 %.5, 255
  %40 = tail call i32 @putc(i32 noundef %39, ptr noundef %9)
  br label %.preheader.outer.backedge

.preheader.outer.backedge:                        ; preds = %38, %25
  %.133.ph.be = phi i32 [ %.5, %25 ], [ 1, %38 ]
  br label %.preheader.outer, !llvm.loop !9

41:                                               ; preds = %.preheader
  %42 = tail call i32 @fclose(ptr noundef nonnull %17)
  br label %43

43:                                               ; preds = %12, %41
  %.7 = phi i32 [ %.133.ph, %41 ], [ %.03239, %12 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %10, label %12, !llvm.loop !11
}

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @islower(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @toupper(i32 noundef) local_unnamed_addr #3

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

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

attributes #0 = { mustprogress norecurse 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 = { noreturn 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 #3 = { mustprogress nofree nounwind willreturn memory(read) "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 = { noreturn nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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