; LLVM IR from DionysiosB/CodeForces :: 0100-0199 (139A-PetrAndBook)

; 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 [4 x i8], align 1
@.str.1 = 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
  %3 = alloca i32, align 4
  %4 = alloca [7 x i32], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 7, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 28, ptr %4) #4
  call void @llvm.memset.p0.i64(ptr align 16 %4, i8 0, i64 28, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %26, %0
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 7
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %29

14:                                               ; preds = %10
  %15 = getelementptr inbounds [7 x i32], ptr %4, i64 0, i64 0
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %18)
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [7 x i32], ptr %4, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = add nsw i32 %24, %23
  store i32 %25, ptr %5, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %14
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %6, align 4, !tbaa !5
  br label %10, !llvm.loop !9

29:                                               ; preds = %13
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = srem i32 %31, %30
  store i32 %32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %29
  %36 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %36, ptr %3, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %35, %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %55, %37
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = icmp sle i32 %39, 7
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  store i32 5, ptr %8, align 4
  br label %58

42:                                               ; preds = %38
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = icmp sle i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %46)
  store i32 5, ptr %8, align 4
  br label %58

48:                                               ; preds = %42
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [7 x i32], ptr %4, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sub nsw i32 %53, %52
  store i32 %54, ptr %3, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %48
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %7, align 4, !tbaa !5
  br label %38, !llvm.loop !11

58:                                               ; preds = %45, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %59

59:                                               ; preds = %58
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 28, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %60 = load i32, ptr %1, align 4
  ret i32 %60
}

; 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

declare i32 @printf(ptr noundef, ...) #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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 [4 x i8], align 1
@.str.1 = 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 = alloca i32, align 4
  %2 = alloca [7 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(28) %2, i8 0, i64 28, i1 false)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %5 = load i32, ptr %2, align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6)
  %8 = load i32, ptr %6, align 4, !tbaa !5
  %9 = add nsw i32 %8, %5
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %10)
  %12 = load i32, ptr %10, align 8, !tbaa !5
  %13 = add nsw i32 %12, %9
  %14 = getelementptr inbounds i8, ptr %2, i64 12
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %14)
  %16 = load i32, ptr %14, align 4, !tbaa !5
  %17 = add nsw i32 %16, %13
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %18)
  %20 = load i32, ptr %18, align 16, !tbaa !5
  %21 = add nsw i32 %20, %17
  %22 = getelementptr inbounds i8, ptr %2, i64 20
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %22)
  %24 = load i32, ptr %22, align 4, !tbaa !5
  %25 = add nsw i32 %24, %21
  %26 = getelementptr inbounds i8, ptr %2, i64 24
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %26)
  %28 = load i32, ptr %26, align 8, !tbaa !5
  %29 = add nsw i32 %28, %25
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = srem i32 %30, %29
  %32 = icmp eq i32 %31, 0
  %spec.select = select i1 %32, i32 %29, i32 %31
  store i32 %spec.select, ptr %1, align 4, !tbaa !5
  %33 = icmp slt i32 %spec.select, 1
  br i1 %33, label %34, label %36

34:                                               ; preds = %60, %56, %52, %48, %44, %40, %36, %0
  %.018.lcssa.wide = phi i32 [ 0, %0 ], [ 1, %36 ], [ 2, %40 ], [ 3, %44 ], [ 4, %48 ], [ 5, %52 ], [ 6, %56 ], [ 7, %60 ]
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.018.lcssa.wide)
  br label %.loopexit

36:                                               ; preds = %0
  %37 = load i32, ptr %2, align 16, !tbaa !5
  %38 = sub nsw i32 %spec.select, %37
  store i32 %38, ptr %1, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 1
  br i1 %39, label %34, label %40

40:                                               ; preds = %36
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sub nsw i32 %38, %41
  store i32 %42, ptr %1, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 1
  br i1 %43, label %34, label %44

44:                                               ; preds = %40
  %45 = load i32, ptr %10, align 8, !tbaa !5
  %46 = sub nsw i32 %42, %45
  store i32 %46, ptr %1, align 4, !tbaa !5
  %47 = icmp slt i32 %46, 1
  br i1 %47, label %34, label %48

48:                                               ; preds = %44
  %49 = load i32, ptr %14, align 4, !tbaa !5
  %50 = sub nsw i32 %46, %49
  store i32 %50, ptr %1, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 1
  br i1 %51, label %34, label %52

52:                                               ; preds = %48
  %53 = load i32, ptr %18, align 16, !tbaa !5
  %54 = sub nsw i32 %50, %53
  store i32 %54, ptr %1, align 4, !tbaa !5
  %55 = icmp slt i32 %54, 1
  br i1 %55, label %34, label %56

56:                                               ; preds = %52
  %57 = load i32, ptr %22, align 4, !tbaa !5
  %58 = sub nsw i32 %54, %57
  store i32 %58, ptr %1, align 4, !tbaa !5
  %59 = icmp slt i32 %58, 1
  br i1 %59, label %34, label %60

60:                                               ; preds = %56
  %61 = sub nsw i32 %58, %28
  store i32 %61, ptr %1, align 4, !tbaa !5
  %62 = icmp slt i32 %61, 1
  br i1 %62, label %34, label %.loopexit

.loopexit:                                        ; preds = %60, %34
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %2) #4
  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 noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass