; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (539)

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

@ans = external dso_local global [5 x ptr], align 16
@str = external dso_local global [102 x i8], align 16
@.str.5 = external hidden unnamed_addr constant [3 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  br label %3

3:                                                ; preds = %52, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef @str)
  %5 = icmp ne i32 %4, -1
  br i1 %5, label %6, label %53

6:                                                ; preds = %3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %14, %6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [102 x i8], ptr @str, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %7
  br label %14

14:                                               ; preds = %13
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !10

17:                                               ; preds = %7
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %40, label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [102 x i8], ptr @str, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp sle i32 %27, 50
  br i1 %28, label %29, label %40

29:                                               ; preds = %22
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [102 x i8], ptr @str, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = sub nsw i32 %34, 48
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [5 x ptr], ptr @ans, i64 0, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = call i32 @puts(ptr noundef %38)
  br label %52

40:                                               ; preds = %22, %17
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [102 x i8], ptr @str, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = and i32 %45, 1
  %47 = sub nsw i32 4, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [5 x ptr], ptr @ans, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !12
  %51 = call i32 @puts(ptr noundef %50)
  br label %52

52:                                               ; preds = %40, %29
  br label %3, !llvm.loop !14

53:                                               ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

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

declare i32 @puts(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 }

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


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

@ans = external dso_local local_unnamed_addr global [5 x ptr], align 16
@str = external dso_local global [102 x i8], align 16
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull @str)
  %.not11 = icmp eq i32 %1, -1
  br i1 %.not11, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %0, %.preheader.backedge
  %indvars.iv = phi i64 [ %indvars.iv.be, %.preheader.backedge ], [ 0, %0 ]
  %2 = getelementptr inbounds [102 x i8], ptr @str, i64 0, i64 %indvars.iv
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %.not9 = icmp eq i8 %3, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not9, label %4, label %.preheader.backedge

.preheader.backedge:                              ; preds = %.preheader, %19
  %indvars.iv.be = phi i64 [ %indvars.iv.next, %.preheader ], [ 0, %19 ]
  br label %.preheader, !llvm.loop !8

4:                                                ; preds = %.preheader
  %5 = trunc nuw nsw i64 %indvars.iv to i32
  %6 = add nsw i32 %5, -1
  %.not10 = icmp eq i32 %6, 0
  br i1 %.not10, label %7, label %13

7:                                                ; preds = %4
  %8 = load i8, ptr @str, align 16, !tbaa !5
  %9 = icmp slt i8 %8, 51
  br i1 %9, label %10, label %13

10:                                               ; preds = %7
  %11 = sext i8 %8 to i64
  %12 = add nsw i64 %11, -48
  br label %19

13:                                               ; preds = %7, %4
  %14 = sext i32 %6 to i64
  %15 = getelementptr inbounds [102 x i8], ptr @str, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = and i8 %16, 1
  %narrow = sub nuw nsw i8 4, %17
  %18 = zext nneg i8 %narrow to i64
  br label %19

19:                                               ; preds = %13, %10
  %.sink = phi i64 [ %18, %13 ], [ %12, %10 ]
  %20 = getelementptr inbounds [5 x ptr], ptr @ans, i64 0, i64 %.sink
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  %22 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %21)
  %23 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull @str)
  %.not = icmp eq i32 %23, -1
  br i1 %.not, label %._crit_edge, label %.preheader.backedge

._crit_edge:                                      ; preds = %19, %0
  ret i32 0
}

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

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

attributes #0 = { mustprogress nofree 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}


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