#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 phyDay, emoDay, intDay, startDay, peakDay;
  int nCase = 0;
  while (1) {
    scanf("%d %d %d %d", &phyDay, &emoDay, &intDay, &startDay);
    if (phyDay == -1)
      break;
    peakDay = phyDay * 5544 + emoDay * 14421 + intDay * 1288 + 21252 - startDay;
    if (peakDay > 21252)
      peakDay %= 21252;
    nCase++;
    printf("Case %d: the next triple peak occurs in %d days.\n", nCase,
           peakDay);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <scanf@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    1161 <main+0x41>
jmp    11c0 <main+0xa0>
imul   $0x15a8,-0x8(%rbp),%eax
imul   $0x3855,-0xc(%rbp),%ecx
add    %ecx,%eax
imul   $0x508,-0x10(%rbp),%ecx
add    %ecx,%eax
add    $0x5304,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x5304,-0x18(%rbp)
jle    11a0 <main+0x80>
mov    -0x18(%rbp),%eax
mov    $0x5304,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
cmp    $0xffffffff,%eax
je     11fb <main+0xdb>
mov    $0x1,%ebx
lea    0xe99(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x14(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r14
jmp    11ae <main+0x8e>
nopl   (%rax)
lea    0xe85(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
add    $0x1,%ebx
cmp    $0xffffffff,%eax
je     11fb <main+0xdb>
imul   $0x15a8,%eax,%eax
imul   $0x3855,0x14(%rsp),%ecx
add    %eax,%ecx
imul   $0x508,0x10(%rsp),%edx
add    %ecx,%edx
sub    0xc(%rsp),%edx
add    $0x5304,%edx
cmp    $0x5305,%edx
jl     1180 <main+0x60>
movslq %edx,%rax
imul   $0x31571165,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
imul   $0x5304,%eax,%eax
sub    %eax,%edx
jmp    1180 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 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 i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %7
br label %8
8: ; preds = %0, %30
%9 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5)
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %8
br label %36
13: ; preds = %8
%14 = load i32, i32* %2
%15 = mul nsw i32 %14, 5544
%16 = load i32, i32* %3
%17 = mul nsw i32 %16, 14421
%18 = add nsw i32 %15, %17
%19 = load i32, i32* %4
%20 = mul nsw i32 %19, 1288
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 21252
%23 = load i32, i32* %5
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 21252
br i1 %26, label %27, label %30
27: ; preds = %13
%28 = load i32, i32* %6
%29 = srem i32 %28, 21252
store i32 %29, i32* %6
br label %30
30: ; preds = %27, %13
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
br label %8
36: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [12 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*
%9 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, -1
br i1 %11, label %33, label %12
12: ; preds = %0, %12
%13 = phi i32 [ %31, %12 ], [ %10, %0 ]
%14 = phi i32 [ %28, %12 ], [ 0, %0 ]
%15 = mul nsw i32 %13, 5544
%16 = load i32, i32* %2
%17 = mul nsw i32 %16, 14421
%18 = load i32, i32* %3
%19 = mul nsw i32 %18, 1288
%20 = load i32, i32* %4
%21 = add i32 %15, 21252
%22 = add i32 %21, %17
%23 = add i32 %22, %19
%24 = sub i32 %23, %20
%25 = icmp sgt i32 %24, 21252
%26 = srem i32 %24, 21252
%27 = select i1 %25, i32 %26, i32 %24
%28 = add nuw nsw i32 %14, 1
%29 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %27)
%30 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4)
%31 = load i32, i32* %1
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %12
33: ; preds = %12, %0
ret i32 0
}