; LLVM IR from VastoLorde95/Competitive-Programming :: Codejam/2015/Prelim/Problem D (D)

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

@t = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 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
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %100, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = icmp sle i32 %5, %6
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %103

9:                                                ; preds = %4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x, ptr noundef @r, ptr noundef @c)
  %11 = load i32, ptr @x, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %14)
  br label %99

16:                                               ; preds = %9
  %17 = load i32, ptr @x, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %19, label %32

19:                                               ; preds = %16
  %20 = load i32, ptr @r, align 4, !tbaa !5
  %21 = load i32, ptr @c, align 4, !tbaa !5
  %22 = mul nsw i32 %20, %21
  %23 = srem i32 %22, 2
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %19
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %26)
  br label %31

28:                                               ; preds = %19
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %29)
  br label %31

31:                                               ; preds = %28, %25
  br label %98

32:                                               ; preds = %16
  %33 = load i32, ptr @x, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 3
  br i1 %34, label %35, label %72

35:                                               ; preds = %32
  %36 = load i32, ptr @r, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 2
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load i32, ptr @c, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 3
  br i1 %40, label %65, label %41

41:                                               ; preds = %38, %35
  %42 = load i32, ptr @r, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 3
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i32, ptr @c, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 2
  br i1 %46, label %65, label %47

47:                                               ; preds = %44, %41
  %48 = load i32, ptr @r, align 4, !tbaa !5
  %49 = icmp eq i32 %48, 3
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load i32, ptr @c, align 4, !tbaa !5
  %52 = icmp eq i32 %51, 3
  br i1 %52, label %65, label %53

53:                                               ; preds = %50, %47
  %54 = load i32, ptr @r, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 3
  br i1 %55, label %56, label %59

56:                                               ; preds = %53
  %57 = load i32, ptr @c, align 4, !tbaa !5
  %58 = icmp eq i32 %57, 4
  br i1 %58, label %65, label %59

59:                                               ; preds = %56, %53
  %60 = load i32, ptr @r, align 4, !tbaa !5
  %61 = icmp eq i32 %60, 4
  br i1 %61, label %62, label %68

62:                                               ; preds = %59
  %63 = load i32, ptr @c, align 4, !tbaa !5
  %64 = icmp eq i32 %63, 3
  br i1 %64, label %65, label %68

65:                                               ; preds = %62, %56, %50, %44, %38
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %66)
  br label %71

68:                                               ; preds = %62, %59
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %69)
  br label %71

71:                                               ; preds = %68, %65
  br label %97

72:                                               ; preds = %32
  %73 = load i32, ptr @r, align 4, !tbaa !5
  %74 = icmp eq i32 %73, 4
  br i1 %74, label %75, label %78

75:                                               ; preds = %72
  %76 = load i32, ptr @c, align 4, !tbaa !5
  %77 = icmp eq i32 %76, 3
  br i1 %77, label %90, label %78

78:                                               ; preds = %75, %72
  %79 = load i32, ptr @r, align 4, !tbaa !5
  %80 = icmp eq i32 %79, 3
  br i1 %80, label %81, label %84

81:                                               ; preds = %78
  %82 = load i32, ptr @c, align 4, !tbaa !5
  %83 = icmp eq i32 %82, 4
  br i1 %83, label %90, label %84

84:                                               ; preds = %81, %78
  %85 = load i32, ptr @r, align 4, !tbaa !5
  %86 = icmp eq i32 %85, 4
  br i1 %86, label %87, label %93

87:                                               ; preds = %84
  %88 = load i32, ptr @c, align 4, !tbaa !5
  %89 = icmp eq i32 %88, 4
  br i1 %89, label %90, label %93

90:                                               ; preds = %87, %81, %75
  %91 = load i32, ptr %2, align 4, !tbaa !5
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %91)
  br label %96

93:                                               ; preds = %87, %84
  %94 = load i32, ptr %2, align 4, !tbaa !5
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %94)
  br label %96

96:                                               ; preds = %93, %90
  br label %97

97:                                               ; preds = %96, %71
  br label %98

98:                                               ; preds = %97, %31
  br label %99

99:                                               ; preds = %98, %13
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %2, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !9

103:                                              ; preds = %8
  ret i32 0
}

declare i32 @__isoc99_scanf(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 @printf(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@t = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 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, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not29 = icmp slt i32 %2, 1
  br i1 %.not29, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %32, %0
  ret i32 0

.lr.ph:                                           ; preds = %0, %32
  %.030 = phi i32 [ %34, %32 ], [ 1, %0 ]
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x, ptr noundef nonnull @r, ptr noundef nonnull @c)
  %4 = load i32, ptr @x, align 4, !tbaa !5
  switch i32 %4, label %23 [
    i32 1, label %32
    i32 2, label %5
    i32 3, label %11
  ]

5:                                                ; preds = %.lr.ph
  %6 = load i32, ptr @r, align 4, !tbaa !5
  %7 = load i32, ptr @c, align 4, !tbaa !5
  %8 = mul nsw i32 %7, %6
  %9 = and i32 %8, 1
  %10 = icmp eq i32 %9, 0
  %.str.2..str.3 = select i1 %10, ptr @.str.2, ptr @.str.3
  br label %32

11:                                               ; preds = %.lr.ph
  %12 = load i32, ptr @r, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 2
  %14 = load i32, ptr @c, align 4
  %15 = icmp eq i32 %14, 3
  %or.cond = select i1 %13, i1 %15, i1 false
  br i1 %or.cond, label %32, label %16

16:                                               ; preds = %11
  %17 = icmp eq i32 %12, 3
  %18 = and i32 %14, -2
  %19 = icmp eq i32 %18, 2
  %20 = icmp eq i32 %14, 4
  %21 = or i1 %20, %19
  %or.cond26 = select i1 %17, i1 %21, i1 false
  %22 = icmp eq i32 %12, 4
  %or.cond9 = select i1 %22, i1 %15, i1 false
  %or.cond27 = select i1 %or.cond26, i1 true, i1 %or.cond9
  %spec.select = select i1 %or.cond27, ptr @.str.2, ptr @.str.3
  br label %32

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr @r, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 4
  %26 = load i32, ptr @c, align 4
  %27 = icmp eq i32 %26, 3
  %or.cond11 = select i1 %25, i1 %27, i1 false
  br i1 %or.cond11, label %32, label %28

28:                                               ; preds = %23
  %29 = icmp eq i32 %26, 4
  %30 = add i32 %24, -3
  %31 = icmp ult i32 %30, 2
  %or.cond28 = select i1 %31, i1 %29, i1 false
  %spec.select31 = select i1 %or.cond28, ptr @.str.2, ptr @.str.3
  br label %32

32:                                               ; preds = %28, %16, %23, %11, %5, %.lr.ph
  %.str.2.sink = phi ptr [ @.str.2, %.lr.ph ], [ %.str.2..str.3, %5 ], [ @.str.2, %11 ], [ @.str.2, %23 ], [ %spec.select, %16 ], [ %spec.select31, %28 ]
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink, i32 noundef %.030)
  %34 = add nuw nsw i32 %.030, 1
  %35 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.030, %35
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass