; LLVM IR from DionysiosB/CodeForces :: 0001-0099 (36A-ExtraTerrestrialIntelligence)

; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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
@.str.4 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %11 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %11, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %12, ptr noundef @.str.2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 -1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 -1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  store i8 1, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %65, %0
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %8, align 4
  br label %68

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  store i8 48, ptr %9, align 1, !tbaa !13
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %20, ptr noundef @.str.3, ptr noundef %9)
  %22 = load i8, ptr %9, align 1, !tbaa !13
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 49
  br i1 %24, label %25, label %61

25:                                               ; preds = %19
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %25
  %29 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %29, ptr %4, align 4, !tbaa !9
  br label %56

30:                                               ; preds = %25
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %30
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = sub nsw i32 %34, %35
  store i32 %36, ptr %5, align 4, !tbaa !9
  %37 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %37, ptr %4, align 4, !tbaa !9
  br label %55

38:                                               ; preds = %30
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sub nsw i32 %39, %40
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %38
  %45 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %45, ptr %4, align 4, !tbaa !9
  br label %54

46:                                               ; preds = %38
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = icmp ne i32 %49, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %46
  store i8 0, ptr %6, align 1, !tbaa !11
  store i32 2, ptr %8, align 4
  br label %62

53:                                               ; preds = %46
  br label %54

54:                                               ; preds = %53, %44
  br label %55

55:                                               ; preds = %54, %33
  br label %56

56:                                               ; preds = %55, %28
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %57, i32 noundef %58, i32 noundef %59)
  br label %61

61:                                               ; preds = %56, %19
  store i32 0, ptr %8, align 4
  br label %62

62:                                               ; preds = %61, %52
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  %63 = load i32, ptr %8, align 4
  switch i32 %63, label %68 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !14

68:                                               ; preds = %62, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = call i32 @fclose(ptr noundef %70)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %72 = call noalias ptr @fopen(ptr noundef @.str.5, ptr noundef @.str.6)
  store ptr %72, ptr %10, align 8, !tbaa !5
  %73 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %74 = trunc i8 %73 to i1
  br i1 %74, label %75, label %78

75:                                               ; preds = %69
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %76, ptr noundef @.str.7) #4
  br label %81

78:                                               ; preds = %69
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %79, ptr noundef @.str.8) #4
  br label %81

81:                                               ; preds = %78, %75
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = call i32 @fclose(ptr noundef %82)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

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

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

declare i32 @__isoc99_fscanf(ptr noundef, 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

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #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 = { 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 "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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}


; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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
@.str.4 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  %4 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %3, ptr noundef nonnull @.str.2, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %.not44 = icmp sgt i32 %5, 0
  br i1 %.not44, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %0, %19
  %.02647 = phi i32 [ %20, %19 ], [ 0, %0 ]
  %.02846 = phi i32 [ %.3.ph, %19 ], [ -1, %0 ]
  %.03145 = phi i32 [ %.334.ph, %19 ], [ -1, %0 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #4
  store i8 48, ptr %2, align 1, !tbaa !9
  %6 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %3, ptr noundef nonnull @.str.3, ptr noundef nonnull %2)
  %7 = load i8, ptr %2, align 1, !tbaa !9
  %8 = icmp eq i8 %7, 49
  br i1 %8, label %9, label %19

9:                                                ; preds = %.lr.ph
  %10 = icmp slt i32 %.03145, 0
  br i1 %10, label %16, label %11

11:                                               ; preds = %9
  %12 = icmp slt i32 %.02846, 0
  %13 = sub nsw i32 %.02647, %.03145
  br i1 %12, label %16, label %14

14:                                               ; preds = %11
  %15 = icmp eq i32 %13, %.02846
  br i1 %15, label %16, label %18

16:                                               ; preds = %11, %14, %9
  %.129 = phi i32 [ %.02846, %9 ], [ %.02846, %14 ], [ %13, %11 ]
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %.02647, i32 noundef %.02647, i32 noundef %.129)
  br label %19

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #4
  br label %.loopexit

19:                                               ; preds = %16, %.lr.ph
  %.334.ph = phi i32 [ %.03145, %.lr.ph ], [ %.02647, %16 ]
  %.3.ph = phi i32 [ %.02846, %.lr.ph ], [ %.129, %16 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #4
  %20 = add nuw nsw i32 %.02647, 1
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %.not = icmp slt i32 %20, %21
  br i1 %.not, label %.lr.ph, label %.loopexit, !llvm.loop !10

.loopexit:                                        ; preds = %19, %0, %18
  %.not43 = phi ptr [ @.str.8, %18 ], [ @.str.7, %0 ], [ @.str.7, %19 ]
  %22 = call i32 @fclose(ptr noundef %3)
  %23 = call noalias ptr @fopen(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6)
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull %.not43) #4
  %25 = call i32 @fclose(ptr noundef %23)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) local_unnamed_addr #3

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { "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 }

!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"}


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