; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 36. C Programs (calendar)

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

@__const.main.day = external hidden unnamed_addr constant [12 x i32], align 16
@__const.main.name = external hidden unnamed_addr constant [12 x [4 x i8]], align 16
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @gotoxy(i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @printmonth(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [12 x i32], align 16
  %5 = alloca [12 x [4 x i8]], align 16
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.main.day, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 48, ptr %5) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.main.name, i64 48, i1 false)
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.6, ptr noundef %2)
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = srem i32 %9, 400
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %0
  %13 = getelementptr inbounds [12 x i32], ptr %4, i64 0, i64 1
  store i32 29, ptr %13, align 4, !tbaa !5
  br label %28

14:                                               ; preds = %0
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = srem i32 %15, 100
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %14
  %19 = getelementptr inbounds [12 x i32], ptr %4, i64 0, i64 1
  store i32 28, ptr %19, align 4, !tbaa !5
  br label %27

20:                                               ; preds = %14
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = srem i32 %21, 4
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = getelementptr inbounds [12 x i32], ptr %4, i64 0, i64 1
  store i32 29, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %24, %20
  br label %27

27:                                               ; preds = %26, %18
  br label %28

28:                                               ; preds = %27, %12
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = add nsw i32 %31, %32
  %34 = srem i32 %33, 7
  store i32 %34, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sdiv i32 %35, 4
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sdiv i32 %37, 100
  %39 = sub nsw i32 %36, %38
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sdiv i32 %40, 400
  %42 = add nsw i32 %39, %41
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %3, align 4, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = srem i32 %45, 7
  store i32 %46, ptr %3, align 4, !tbaa !5
  call void @gotoxy(i32 noundef 0, i32 noundef 3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %71, %28
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = icmp slt i32 %48, 12
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %74

51:                                               ; preds = %47
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [12 x [4 x i8]], ptr %5, i64 0, i64 %53
  %55 = getelementptr inbounds [4 x i8], ptr %54, i64 0, i64 0
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %55)
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [12 x i32], ptr %4, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = load i32, ptr %3, align 4, !tbaa !5
  call void @printmonth(i32 noundef %60, i32 noundef %61)
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [12 x i32], ptr %4, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = add nsw i32 %62, %66
  %68 = sub nsw i32 %67, 1
  %69 = srem i32 %68, 7
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %3, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %51
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %6, align 4, !tbaa !5
  br label %47, !llvm.loop !9

74:                                               ; preds = %50
  call void @gotoxy(i32 noundef 0, i32 noundef 15)
  call void @llvm.lifetime.end.p0(i64 48, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 48, 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
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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/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"

@__const.main.day = external hidden unnamed_addr constant [12 x i32], align 16
@__const.main.name = external hidden unnamed_addr constant [12 x [4 x i8]], align 16
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @gotoxy(i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @printmonth(i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca [12 x [4 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %.sroa.0.0.copyload = load i32, ptr @__const.main.day, align 16
  %.sroa.4.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 4), align 4
  %.sroa.8.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 8), align 8
  %.sroa.9.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 12), align 4
  %.sroa.10.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 16), align 16
  %.sroa.11.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 20), align 4
  %.sroa.12.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 24), align 8
  %.sroa.13.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 28), align 4
  %.sroa.14.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 32), align 16
  %.sroa.15.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 36), align 4
  %.sroa.16.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 40), align 8
  %.sroa.17.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.day, i64 44), align 4
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) %2, ptr noundef nonnull align 16 dereferenceable(48) @__const.main.name, i64 48, i1 false)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.6, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = srem i32 %5, 400
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %14, label %8

8:                                                ; preds = %0
  %9 = srem i32 %5, 100
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %14, label %11

11:                                               ; preds = %8
  %12 = and i32 %5, 3
  %13 = icmp eq i32 %12, 0
  %spec.select = select i1 %13, i32 29, i32 %.sroa.4.0.copyload
  br label %14

14:                                               ; preds = %11, %8, %0
  %.sroa.4.0 = phi i32 [ 29, %0 ], [ 28, %8 ], [ %spec.select, %11 ]
  %15 = add nsw i32 %5, -1
  store i32 %15, ptr %1, align 4, !tbaa !5
  %16 = add nsw i32 %5, 1
  %17 = srem i32 %16, 7
  %18 = sdiv i32 %15, 4
  %.neg = sdiv i32 %15, -100
  %19 = add nsw i32 %.neg, %18
  %20 = sdiv i32 %15, 400
  %21 = add nsw i32 %19, %20
  %22 = add nsw i32 %21, %17
  %23 = srem i32 %22, 7
  call void @gotoxy(i32 noundef 0, i32 noundef 3)
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %2)
  call void @printmonth(i32 noundef %.sroa.0.0.copyload, i32 noundef %23)
  %25 = add nsw i32 %23, -1
  %26 = add i32 %25, %.sroa.0.0.copyload
  %27 = srem i32 %26, 7
  %28 = add nsw i32 %27, 1
  %29 = getelementptr inbounds i8, ptr %2, i64 4
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %29)
  call void @printmonth(i32 noundef %.sroa.4.0, i32 noundef %28)
  %31 = add i32 %27, %.sroa.4.0
  %32 = srem i32 %31, 7
  %33 = add nsw i32 %32, 1
  %34 = getelementptr inbounds i8, ptr %2, i64 8
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %34)
  call void @printmonth(i32 noundef %.sroa.8.0.copyload, i32 noundef %33)
  %36 = add i32 %32, %.sroa.8.0.copyload
  %37 = srem i32 %36, 7
  %38 = add nsw i32 %37, 1
  %39 = getelementptr inbounds i8, ptr %2, i64 12
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %39)
  call void @printmonth(i32 noundef %.sroa.9.0.copyload, i32 noundef %38)
  %41 = add i32 %37, %.sroa.9.0.copyload
  %42 = srem i32 %41, 7
  %43 = add nsw i32 %42, 1
  %44 = getelementptr inbounds i8, ptr %2, i64 16
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %44)
  call void @printmonth(i32 noundef %.sroa.10.0.copyload, i32 noundef %43)
  %46 = add i32 %42, %.sroa.10.0.copyload
  %47 = srem i32 %46, 7
  %48 = add nsw i32 %47, 1
  %49 = getelementptr inbounds i8, ptr %2, i64 20
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %49)
  call void @printmonth(i32 noundef %.sroa.11.0.copyload, i32 noundef %48)
  %51 = add i32 %47, %.sroa.11.0.copyload
  %52 = srem i32 %51, 7
  %53 = add nsw i32 %52, 1
  %54 = getelementptr inbounds i8, ptr %2, i64 24
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %54)
  call void @printmonth(i32 noundef %.sroa.12.0.copyload, i32 noundef %53)
  %56 = add i32 %52, %.sroa.12.0.copyload
  %57 = srem i32 %56, 7
  %58 = add nsw i32 %57, 1
  %59 = getelementptr inbounds i8, ptr %2, i64 28
  %60 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %59)
  call void @printmonth(i32 noundef %.sroa.13.0.copyload, i32 noundef %58)
  %61 = add i32 %57, %.sroa.13.0.copyload
  %62 = srem i32 %61, 7
  %63 = add nsw i32 %62, 1
  %64 = getelementptr inbounds i8, ptr %2, i64 32
  %65 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %64)
  call void @printmonth(i32 noundef %.sroa.14.0.copyload, i32 noundef %63)
  %66 = add i32 %62, %.sroa.14.0.copyload
  %67 = srem i32 %66, 7
  %68 = add nsw i32 %67, 1
  %69 = getelementptr inbounds i8, ptr %2, i64 36
  %70 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %69)
  call void @printmonth(i32 noundef %.sroa.15.0.copyload, i32 noundef %68)
  %71 = add i32 %67, %.sroa.15.0.copyload
  %72 = srem i32 %71, 7
  %73 = add nsw i32 %72, 1
  %74 = getelementptr inbounds i8, ptr %2, i64 40
  %75 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %74)
  call void @printmonth(i32 noundef %.sroa.16.0.copyload, i32 noundef %73)
  %76 = add i32 %72, %.sroa.16.0.copyload
  %77 = srem i32 %76, 7
  %78 = add nsw i32 %77, 1
  %79 = getelementptr inbounds i8, ptr %2, i64 44
  %80 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull %79)
  call void @printmonth(i32 noundef %.sroa.17.0.copyload, i32 noundef %78)
  call void @gotoxy(i32 noundef 0, i32 noundef 15)
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

attributes #0 = { 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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}


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