; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK61/Problem B (B)

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %7

7:                                                ; preds = %53, %0
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @t, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %54

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %13 = load i64, ptr @n, align 8, !tbaa !9
  %14 = add nsw i64 %13, 1
  store i64 %14, ptr %2, align 8, !tbaa !9
  %15 = load i64, ptr @n, align 8, !tbaa !9
  %16 = icmp eq i64 %15, 1
  br i1 %16, label %17, label %19

17:                                               ; preds = %11
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef 2)
  br label %53

19:                                               ; preds = %11
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = load i64, ptr @n, align 8, !tbaa !9
  %22 = and i64 %20, %21
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %52

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 -1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %41, %26
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 30
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %44

31:                                               ; preds = %27
  %32 = load i64, ptr @n, align 8, !tbaa !9
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = shl i64 1, %34
  %36 = and i64 %32, %35
  %37 = icmp sgt i64 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %31
  %39 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %39, ptr %3, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %38, %31
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !11

44:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = zext i32 %45 to i64
  %47 = shl i64 1, %46
  store i64 %47, ptr %5, align 8, !tbaa !9
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = add nsw i64 %48, -1
  store i64 %49, ptr %5, align 8, !tbaa !9
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %52

52:                                               ; preds = %44, %24
  br label %53

53:                                               ; preds = %52, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %7, !llvm.loop !13

54:                                               ; preds = %7
  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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 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
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not14 = icmp eq i32 %2, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %77
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %5 = load i64, ptr @n, align 8, !tbaa !9
  %6 = icmp eq i64 %5, 1
  br i1 %6, label %7, label %9

7:                                                ; preds = %.lr.ph
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 2)
  br label %77

9:                                                ; preds = %.lr.ph
  %10 = add nsw i64 %5, 1
  %11 = and i64 %10, %5
  %.not10 = icmp eq i64 %11, 0
  br i1 %.not10, label %.preheader.preheader, label %75

.preheader.preheader:                             ; preds = %9
  %12 = and i64 %5, 1
  %spec.select = add nuw nsw i64 %12, 4294967295
  %13 = and i64 %5, 2
  %.not11.1 = icmp eq i64 %13, 0
  %14 = and i64 %spec.select, 4294967295
  %15 = and i64 %5, 4
  %.not11.2 = icmp eq i64 %15, 0
  %16 = shl nsw i64 -1, %14
  %17 = and i64 %5, 8
  %.not11.3 = icmp eq i64 %17, 0
  %18 = xor i64 %16, -1
  %19 = and i64 %5, 16
  %.not11.4 = icmp eq i64 %19, 0
  %20 = select i1 %.not11.1, i64 %18, i64 1
  %21 = and i64 %5, 32
  %.not11.5 = icmp eq i64 %21, 0
  %22 = select i1 %.not11.2, i64 %20, i64 3
  %23 = and i64 %5, 64
  %.not11.6 = icmp eq i64 %23, 0
  %24 = select i1 %.not11.3, i64 %22, i64 7
  %25 = and i64 %5, 128
  %.not11.7 = icmp eq i64 %25, 0
  %26 = select i1 %.not11.4, i64 %24, i64 15
  %27 = and i64 %5, 256
  %.not11.8 = icmp eq i64 %27, 0
  %28 = select i1 %.not11.5, i64 %26, i64 31
  %29 = and i64 %5, 512
  %.not11.9 = icmp eq i64 %29, 0
  %30 = select i1 %.not11.6, i64 %28, i64 63
  %31 = and i64 %5, 1024
  %.not11.10 = icmp eq i64 %31, 0
  %32 = select i1 %.not11.7, i64 %30, i64 127
  %33 = and i64 %5, 2048
  %.not11.11 = icmp eq i64 %33, 0
  %34 = select i1 %.not11.8, i64 %32, i64 255
  %35 = and i64 %5, 4096
  %.not11.12 = icmp eq i64 %35, 0
  %36 = select i1 %.not11.9, i64 %34, i64 511
  %37 = and i64 %5, 8192
  %.not11.13 = icmp eq i64 %37, 0
  %38 = select i1 %.not11.10, i64 %36, i64 1023
  %39 = and i64 %5, 16384
  %.not11.14 = icmp eq i64 %39, 0
  %40 = select i1 %.not11.11, i64 %38, i64 2047
  %41 = and i64 %5, 32768
  %.not11.15 = icmp eq i64 %41, 0
  %42 = select i1 %.not11.12, i64 %40, i64 4095
  %43 = and i64 %5, 65536
  %.not11.16 = icmp eq i64 %43, 0
  %44 = select i1 %.not11.13, i64 %42, i64 8191
  %45 = and i64 %5, 131072
  %.not11.17 = icmp eq i64 %45, 0
  %46 = select i1 %.not11.14, i64 %44, i64 16383
  %47 = and i64 %5, 262144
  %.not11.18 = icmp eq i64 %47, 0
  %48 = select i1 %.not11.15, i64 %46, i64 32767
  %49 = and i64 %5, 524288
  %.not11.19 = icmp eq i64 %49, 0
  %50 = select i1 %.not11.16, i64 %48, i64 65535
  %51 = and i64 %5, 1048576
  %.not11.20 = icmp eq i64 %51, 0
  %52 = select i1 %.not11.17, i64 %50, i64 131071
  %53 = and i64 %5, 2097152
  %.not11.21 = icmp eq i64 %53, 0
  %54 = select i1 %.not11.18, i64 %52, i64 262143
  %55 = and i64 %5, 4194304
  %.not11.22 = icmp eq i64 %55, 0
  %56 = select i1 %.not11.19, i64 %54, i64 524287
  %57 = and i64 %5, 8388608
  %.not11.23 = icmp eq i64 %57, 0
  %58 = select i1 %.not11.20, i64 %56, i64 1048575
  %59 = and i64 %5, 16777216
  %.not11.24 = icmp eq i64 %59, 0
  %60 = select i1 %.not11.21, i64 %58, i64 2097151
  %61 = and i64 %5, 33554432
  %.not11.25 = icmp eq i64 %61, 0
  %62 = select i1 %.not11.22, i64 %60, i64 4194303
  %63 = and i64 %5, 67108864
  %.not11.26 = icmp eq i64 %63, 0
  %64 = select i1 %.not11.23, i64 %62, i64 8388607
  %65 = and i64 %5, 134217728
  %.not11.27 = icmp eq i64 %65, 0
  %66 = select i1 %.not11.24, i64 %64, i64 16777215
  %67 = and i64 %5, 268435456
  %.not11.28 = icmp eq i64 %67, 0
  %68 = select i1 %.not11.25, i64 %66, i64 33554431
  %69 = and i64 %5, 536870912
  %.not11.29 = icmp eq i64 %69, 0
  %70 = select i1 %.not11.26, i64 %68, i64 67108863
  %71 = select i1 %.not11.27, i64 %70, i64 134217727
  %72 = select i1 %.not11.28, i64 %71, i64 268435455
  %73 = select i1 %.not11.29, i64 %72, i64 536870911
  %74 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %73)
  br label %77

75:                                               ; preds = %9
  %76 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %77

77:                                               ; preds = %75, %.preheader.preheader, %7
  %78 = load i32, ptr @t, align 4, !tbaa !5
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %78, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %77, %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 @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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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