; LLVM IR from tangjz/acm-icpc :: usaco/Training/Chapter 1 Getting started (ride)

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

@a = external dso_local global [7 x i8], align 1
@b = external dso_local global [7 x i8], align 1
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %6)
  %8 = load ptr, ptr @stdout, align 8, !tbaa !5
  %9 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !9
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef @a, ptr noundef @b)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %30, %0
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [7 x i8], ptr @a, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %33

18:                                               ; preds = %11
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [7 x i8], ptr @a, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = sub nsw i32 %23, 65
  %25 = add nsw i32 %24, 1
  %26 = load i32, ptr %2, align 4, !tbaa !9
  %27 = mul nsw i32 %26, %25
  store i32 %27, ptr %2, align 4, !tbaa !9
  %28 = load i32, ptr %2, align 4, !tbaa !9
  %29 = srem i32 %28, 47
  store i32 %29, ptr %2, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %18
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %4, align 4, !tbaa !9
  br label %11, !llvm.loop !12

33:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %53, %33
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [7 x i8], ptr @b, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = icmp ne i8 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %56

41:                                               ; preds = %34
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [7 x i8], ptr @b, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = sub nsw i32 %46, 65
  %48 = add nsw i32 %47, 1
  %49 = load i32, ptr %3, align 4, !tbaa !9
  %50 = mul nsw i32 %49, %48
  store i32 %50, ptr %3, align 4, !tbaa !9
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = srem i32 %51, 47
  store i32 %52, ptr %3, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %41
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !9
  br label %34, !llvm.loop !14

56:                                               ; preds = %40
  %57 = load i32, ptr %2, align 4, !tbaa !9
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = icmp eq i32 %57, %58
  %60 = zext i1 %59 to i64
  %61 = select i1 %59, ptr @.str.5, ptr @.str.6
  %62 = call i32 @puts(ptr noundef %61)
  %63 = load ptr, ptr @stdin, align 8, !tbaa !5
  %64 = call i32 @fclose(ptr noundef %63)
  %65 = load ptr, ptr @stdout, align 8, !tbaa !5
  %66 = call i32 @fclose(ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #1

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

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

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

declare i32 @puts(ptr noundef) #1

declare i32 @fclose(ptr noundef) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@a = external dso_local global [7 x i8], align 1
@b = external dso_local global [7 x i8], align 1
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = load ptr, ptr @stdin, align 8, !tbaa !5
  %2 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %1)
  %3 = load ptr, ptr @stdout, align 8, !tbaa !5
  %4 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %3)
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %6 = load i8, ptr @a, align 1, !tbaa !9
  %.not18 = icmp eq i8 %6, 0
  br i1 %.not18, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %0
  %.014.lcssa = phi i32 [ 1, %0 ], [ %12, %.lr.ph ]
  %7 = load i8, ptr @b, align 1, !tbaa !9
  %.not1721 = icmp eq i8 %7, 0
  br i1 %.not1721, label %._crit_edge, label %.lr.ph24

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %8 = phi i8 [ %14, %.lr.ph ], [ %6, %0 ]
  %.01419 = phi i32 [ %12, %.lr.ph ], [ 1, %0 ]
  %9 = sext i8 %8 to i32
  %10 = add nsw i32 %9, -64
  %11 = mul nsw i32 %10, %.01419
  %12 = srem i32 %11, 47
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = getelementptr inbounds [7 x i8], ptr @a, i64 0, i64 %indvars.iv.next
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %.not = icmp eq i8 %14, 0
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph24, %.preheader
  %.013.lcssa = phi i32 [ 1, %.preheader ], [ %26, %.lr.ph24 ]
  %15 = icmp eq i32 %.014.lcssa, %.013.lcssa
  %16 = select i1 %15, ptr @.str.5, ptr @.str.6
  %17 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %16)
  %18 = load ptr, ptr @stdin, align 8, !tbaa !5
  %19 = tail call i32 @fclose(ptr noundef %18)
  %20 = load ptr, ptr @stdout, align 8, !tbaa !5
  %21 = tail call i32 @fclose(ptr noundef %20)
  ret i32 0

.lr.ph24:                                         ; preds = %.preheader, %.lr.ph24
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.lr.ph24 ], [ 0, %.preheader ]
  %22 = phi i8 [ %28, %.lr.ph24 ], [ %7, %.preheader ]
  %.01322 = phi i32 [ %26, %.lr.ph24 ], [ 1, %.preheader ]
  %23 = sext i8 %22 to i32
  %24 = add nsw i32 %23, -64
  %25 = mul nsw i32 %24, %.01322
  %26 = srem i32 %25, 47
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %27 = getelementptr inbounds [7 x i8], ptr @b, i64 0, i64 %indvars.iv.next28
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %.not17 = icmp eq i8 %28, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph24, !llvm.loop !12
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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

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 = { 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" }

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


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