#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ scanf(char *, int *, int *, int *, int *);
int main() {
  int periods[] = {23, 28, 33};
  int prod = 23 * 28 * 33;
  int basis[] = {5544, 14421, 1288};
  int rems[3];
  int d = 0;
  int cnt = 0;
  int ans = 0;
  while ((EOF != scanf("%d %d %d %d", rems, rems + 1, rems + 2, &d)) &&
         (d >= 0)) {
    ans = rems[0] * basis[0] + rems[1] * basis[1] + rems[2] * basis[2];
    ans = (prod + ans - d - 1) % prod + 1;
    printf("Case %d: the next triple peak occurs in %d days.\n", ++cnt, ans);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x5304,-0x14(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb9(%rip),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
lea    -0x2c(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
add    $0x4,%rdx
lea    -0x2c(%rbp),%rcx
add    $0x8,%rcx
lea    0xe7c(%rip),%rdi
lea    -0x30(%rbp),%r8
call   1040 <scanf@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x39(%rbp)
je     11c4 <main+0xa4>
cmpl   $0x0,-0x30(%rbp)
setge  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11d4 <main+0xb4>
jmp    1223 <main+0x103>
mov    -0x2c(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    -0x28(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    %ecx,%eax
mov    -0x24(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    -0x38(%rbp),%eax
sub    -0x30(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x14(%rbp)
add    $0x1,%edx
mov    %edx,-0x38(%rbp)
mov    -0x34(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
mov    -0x38(%rbp),%edx
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
jmp    1173 <main+0x53>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
mov    0x2ea1(%rip),%rax
mov    (%rax),%rbx
lea    0xeaf(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%r8
call   1040 <scanf@plt>
cmp    %rax,%rbx
je     1225 <main+0x105>
mov    0x8(%rsp),%eax
test   %eax,%eax
js     1225 <main+0x105>
mov    $0x1,%ebp
lea    0xe8b(%rip),%r12
lea    0xe78(%rip),%r13
lea    0xc(%rsp),%rbx
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
imul   $0x15a8,0xc(%rsp),%ecx
sub    %eax,%ecx
imul   $0x3855,0x10(%rsp),%eax
add    %ecx,%eax
imul   $0x508,0x14(%rsp),%ecx
add    %ecx,%eax
add    $0x5303,%eax
movslq %eax,%rdx
imul   $0x31571165,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
imul   $0x5304,%eax,%eax
sub    %eax,%edx
add    $0x1,%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%r15
mov    %r13,%rdi
mov    %rbx,%rsi
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
mov    %r14,%r8
call   1040 <scanf@plt>
cmp    %rax,%r15
je     1225 <main+0x105>
add    $0x1,%ebp
mov    0x8(%rsp),%eax
test   %eax,%eax
jns    11a0 <main+0x80>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.periods = [3 x i32] [i32 23, i32 28, i32 33]
@__const.main.basis = [3 x i32] [i32 5544, i32 14421, i32 1288]
@EOF = global i64 0
@.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 [3 x i32]
%3 = alloca i32
%4 = alloca [3 x i32]
%5 = alloca [3 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [3 x i32]* %2 to i8*
store i32 21252, i32* %3
%10 = bitcast [3 x i32]* %4 to i8*
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %25, %0
%12 = load i64, i64* @EOF
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%17 = getelementptr inbounds i32, i32* %16, i64 2
%18 = call i64 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %13, i32* %15, i32* %17, i32* %6)
%19 = icmp ne i64 %12, %18
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i32, i32* %6
%22 = icmp sge i32 %21, 0
br label %23
23: ; preds = %20, %11
%24 = phi i1 [ false, %11 ], [ %22, %20 ]
br i1 %24, label %25, label %56
25: ; preds = %23
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%29 = load i32, i32* %28
%30 = mul nsw i32 %27, %29
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%34 = load i32, i32* %33
%35 = mul nsw i32 %32, %34
%36 = add nsw i32 %30, %35
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%38 = load i32, i32* %37
%39 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%40 = load i32, i32* %39
%41 = mul nsw i32 %38, %40
%42 = add nsw i32 %36, %41
store i32 %42, i32* %8
%43 = load i32, i32* %3
%44 = load i32, i32* %8
%45 = add nsw i32 %43, %44
%46 = load i32, i32* %6
%47 = sub nsw i32 %45, %46
%48 = sub nsw i32 %47, 1
%49 = load i32, i32* %3
%50 = srem i32 %48, %49
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
%54 = load i32, i32* %8
%55 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %53, i32 %54)
br label %11
56: ; preds = %23
ret i32 0
}

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