#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, int *, int *, int *, int *);
int main() {
  int p, e, i, d;
  int a[28] = {0,  11, 22, 5,  16, 27, 10, 21, 4,  15, 26, 9,  20, 3,
               14, 25, 8,  19, 2,  13, 24, 7,  18, 1,  12, 23, 6,  17};
  int b[23] = {0,  17, 11, 5, 22, 16, 10, 4, 21, 15, 9, 3,
               20, 14, 8,  2, 19, 13, 7,  1, 18, 12, 6};
  int date, count = 0;
  int remain;
  while (1) {
    scanf("%d%d%d%d", &p, &e, &i, &d);
    if (p == -1 && e == -1 && i == -1 && d == -1) {
      break;
    }
    count++;
    date = d;
    remain = (d - i) % 33;
    if (remain < 0) {
      remain += 33;
    }
    d = d + 33 - remain;
    remain = (d - e) % 28;
    if (remain < 0) {
      remain += 28;
    }
    d = d + 33 * a[remain];
    remain = (d - p) % 23;
    if (remain < 0) {
      remain += 23;
    }
    d = d + 33 * 28 * b[remain];
    if (d >= 21617) {
      d = 21252;
    } else {
      d = d - date;
    }
    printf("Case %d: the next triple peak occurs in %d days.\n", count, d);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x70,%edx
call   1040 <memcpy@plt>
lea    -0xf0(%rbp),%rdi
lea    0xf08(%rip),%rsi
mov    $0x5c,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0xf8(%rbp)
lea    0xf49(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1050 <scanf@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c5 <main+0x95>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c5 <main+0x95>
cmpl   $0xffffffff,-0x10(%rbp)
jne    11c5 <main+0x95>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c5 <main+0x95>
jmp    12ec <main+0x1bc>
mov    -0xf8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xf4(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    $0x21,%ecx
cltd
idiv   %ecx
mov    %edx,-0xfc(%rbp)
cmpl   $0x0,-0xfc(%rbp)
jge    120d <main+0xdd>
mov    -0xfc(%rbp),%eax
add    $0x21,%eax
mov    %eax,-0xfc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x21,%eax
sub    -0xfc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x1c,%ecx
cltd
idiv   %ecx
mov    %edx,-0xfc(%rbp)
cmpl   $0x0,-0xfc(%rbp)
jge    124c <main+0x11c>
mov    -0xfc(%rbp),%eax
add    $0x1c,%eax
mov    %eax,-0xfc(%rbp)
mov    -0x14(%rbp),%eax
movslq -0xfc(%rbp),%rcx
imul   $0x21,-0x90(%rbp,%rcx,4),%ecx
21
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    $0x17,%ecx
cltd
idiv   %ecx
mov    %edx,-0xfc(%rbp)
cmpl   $0x0,-0xfc(%rbp)
jge    1293 <main+0x163>
mov    -0xfc(%rbp),%eax
add    $0x17,%eax
mov    %eax,-0xfc(%rbp)
mov    -0x14(%rbp),%eax
movslq -0xfc(%rbp),%rcx
imul   $0x39c,-0xf0(%rbp,%rcx,4),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x5471,-0x14(%rbp)
jl     12c6 <main+0x196>
movl   $0x5304,-0x14(%rbp)
jmp    12d2 <main+0x1a2>
mov    -0x14(%rbp),%eax
sub    -0xf4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xf8(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
jmp    117c <main+0x4c>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebx
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%r15
lea    0xf8c(%rip),%r14
jmp    1238 <main+0x118>
xchg   %ax,%ax
mov    %eax,%edi
sub    %esi,%edi
movslq %edi,%rsi
imul   $0x3e0f83e1,%rsi,%rdi
mov    %rdi,%rbp
shr    $0x3f,%rbp
shr    $0x20,%rdi
sar    $0x3,%edi
add    %ebp,%edi
mov    %edi,%ebp
shl    $0x5,%ebp
add    %edi,%ebp
mov    %esi,%edi
sub    %ebp,%edi
neg    %ebp
test   %edi,%edi
lea    0x21(%rsi,%rbp,1),%esi
cmovns %edi,%esi
neg    %esi
add    %eax,%esi
add    $0x21,%esi
mov    %esi,%edi
sub    %edx,%edi
movslq %edi,%rdx
imul   $0xffffffff92492493,%rdx,%rdi
shr    $0x20,%rdi
add    %edx,%edi
mov    %edi,%ebp
shr    $0x1f,%ebp
sar    $0x4,%edi
add    %ebp,%edi
lea    (%rdi,%rdi,8),%ebp
lea    0x0(%rbp,%rbp,2),%ebp
add    %edi,%ebp
mov    %edx,%edi
sub    %ebp,%edi
neg    %ebp
test   %edi,%edi
lea    0x1c(%rdx,%rbp,1),%edx
cmovns %edi,%edx
lea    0xe38(%rip),%rdi
mov    (%rdi,%rdx,4),%edi
mov    %edi,%edx
shl    $0x5,%edx
add    %edi,%edx
add    %esi,%edx
mov    %edx,%esi
sub    %ecx,%esi
movslq %esi,%rcx
imul   $0xffffffffb21642c9,%rcx,%rsi
shr    $0x20,%rsi
add    %ecx,%esi
mov    %esi,%edi
shr    $0x1f,%edi
sar    $0x4,%esi
add    %edi,%esi
lea    (%rsi,%rsi,2),%edi
shl    $0x3,%edi
sub    %edi,%esi
lea    (%rcx,%rsi,1),%edi
add    $0x17,%edi
add    %esi,%ecx
cmovns %ecx,%edi
lea    0xe64(%rip),%rcx
imul   $0x39c,(%rcx,%rdi,4),%ecx
add    %edx,%ecx
mov    %ecx,%edx
sub    %eax,%edx
cmp    $0x5471,%ecx
mov    $0x5304,%eax
cmovge %eax,%edx
mov    %edx,0x8(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
lea    0xe8d(%rip),%rdi
lea    0x14(%rsp),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %r15,%r8
call   1040 <scanf@plt>
mov    0x14(%rsp),%ecx
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%eax
cmp    $0xffffffff,%ecx
jne    1150 <main+0x30>
cmp    $0xffffffff,%edx
jne    1150 <main+0x30>
cmp    $0xffffffff,%esi
jne    1150 <main+0x30>
cmp    $0xffffffff,%eax
jne    1150 <main+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.a = [28 x i32] [i32 0, i32 11, i32 22, i32 5, i32 16, i32 27, i32 10, i32 21, i32 4, i32 15, i32 26, i32 9, i32 20, i32 3, i32 14, i32 25, i32 8, i32 19, i32 2, i32 13, i32 24, i32 7, i32 18, i32 1, i32 12, i32 23, i32 6, i32 17]
@__const.main.b = [23 x i32] [i32 0, i32 17, i32 11, i32 5, i32 22, i32 16, i32 10, i32 4, i32 21, i32 15, i32 9, i32 3, i32 20, i32 14, i32 8, i32 2, i32 19, i32 13, i32 7, i32 1, i32 18, i32 12, i32 6]
@.str = [9 x i8] c"%d%d%d%d\00"
@.str.1 = [50 x i8] c"Case %d: the next triple peak occurs in %d days.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [28 x i32]
%7 = alloca [23 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = bitcast [28 x i32]* %6 to i8*
%12 = bitcast [23 x i32]* %7 to i8*
store i32 0, i32* %9
br label %13
13: ; preds = %0, %86
%14 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5)
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %23
br label %90
27: ; preds = %23, %20, %17, %13
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
%30 = load i32, i32* %5
store i32 %30, i32* %8
%31 = load i32, i32* %5
%32 = load i32, i32* %4
%33 = sub nsw i32 %31, %32
%34 = srem i32 %33, 33
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %27
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 33
store i32 %39, i32* %10
br label %40
40: ; preds = %37, %27
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 33
%43 = load i32, i32* %10
%44 = sub nsw i32 %42, %43
store i32 %44, i32* %5
%45 = load i32, i32* %5
%46 = load i32, i32* %3
%47 = sub nsw i32 %45, %46
%48 = srem i32 %47, 28
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %40
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 28
store i32 %53, i32* %10
br label %54
54: ; preds = %51, %40
%55 = load i32, i32* %5
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [28 x i32], [28 x i32]* %6, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = mul nsw i32 33, %59
%61 = add nsw i32 %55, %60
store i32 %61, i32* %5
%62 = load i32, i32* %5
%63 = load i32, i32* %2
%64 = sub nsw i32 %62, %63
%65 = srem i32 %64, 23
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %54
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 23
store i32 %70, i32* %10
br label %71
71: ; preds = %68, %54
%72 = load i32, i32* %5
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [23 x i32], [23 x i32]* %7, i64 0, i64 %74
%76 = load i32, i32* %75
%77 = mul nsw i32 924, %76
%78 = add nsw i32 %72, %77
store i32 %78, i32* %5
%79 = load i32, i32* %5
%80 = icmp sge i32 %79, 21617
br i1 %80, label %81, label %82
81: ; preds = %71
store i32 21252, i32* %5
br label %86
82: ; preds = %71
%83 = load i32, i32* %5
%84 = load i32, i32* %8
%85 = sub nsw i32 %83, %84
store i32 %85, i32* %5
br label %86
86: ; preds = %82, %81
%87 = load i32, i32* %9
%88 = load i32, i32* %5
%89 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %87, i32 %88)
br label %13
90: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [28 x i32] [i32 0, i32 11, i32 22, i32 5, i32 16, i32 27, i32 10, i32 21, i32 4, i32 15, i32 26, i32 9, i32 20, i32 3, i32 14, i32 25, i32 8, i32 19, i32 2, i32 13, i32 24, i32 7, i32 18, i32 1, i32 12, i32 23, i32 6, i32 17]
@__const.main.b = [23 x i32] [i32 0, i32 17, i32 11, i32 5, i32 22, i32 16, i32 10, i32 4, i32 21, i32 15, i32 9, i32 3, i32 20, i32 14, i32 8, i32 2, i32 19, i32 13, i32 7, i32 1, i32 18, i32 12, i32 6]
@.str = [9 x i8] c"%d%d%d%d\00"
@.str.1 = [50 x i8] c"Case %d: the next triple peak occurs in %d days.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
br label %9
9: ; preds = %23, %0
%10 = phi i32 [ 0, %0 ], [ %24, %23 ]
%11 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4)
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, -1
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, -1
%16 = select i1 %13, i1 %15, i1 false
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, -1
%19 = select i1 %16, i1 %18, i1 false
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, -1
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %56, label %23
23: ; preds = %9
%24 = add nuw nsw i32 %10, 1
%25 = sub nsw i32 %20, %17
%26 = srem i32 %25, 33
%27 = icmp slt i32 %26, 0
%28 = add nsw i32 %26, 33
%29 = select i1 %27, i32 %28, i32 %26
%30 = add nsw i32 %20, 33
%31 = sub nsw i32 %30, %29
%32 = sub nsw i32 %31, %14
%33 = srem i32 %32, 28
%34 = icmp slt i32 %33, 0
%35 = add nsw i32 %33, 28
%36 = select i1 %34, i32 %35, i32 %33
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [28 x i32], [28 x i32]* @__const.main.a, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = mul nsw i32 %39, 33
%41 = add nsw i32 %40, %31
%42 = sub nsw i32 %41, %12
%43 = srem i32 %42, 23
%44 = icmp slt i32 %43, 0
%45 = add nsw i32 %43, 23
%46 = select i1 %44, i32 %45, i32 %43
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds [23 x i32], [23 x i32]* @__const.main.b, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = mul nsw i32 %49, 924
%51 = add nsw i32 %50, %41
%52 = icmp sgt i32 %51, 21616
%53 = sub nsw i32 %51, %20
%54 = select i1 %52, i32 21252, i32 %53
store i32 %54, i32* %4
%55 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %54)
br label %9
56: ; preds = %9
ret i32 0
}