#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  fp = fopen("ice.in", "r");
  int numCases = 0;
  fscanf(fp, "%d", &numCases);
  int z;
  for (z = 1; z <= numCases; z++) {
    printf("Session #%d:\n", z);
    int iceCounter = 0;
    int numCups = 1;
    int numDispense = 0;
    fscanf(fp, "%d", &numDispense);
    int i = 0;
    for (i = 0; i < numDispense; i++) {
      int dispensed = 0;
      fscanf(fp, "%d", &dispensed);
      iceCounter += dispensed;
      if (iceCounter == 7) {
        printf("   Cup #%d: Perfect!\n", numCups);
        numCups++;
        iceCounter = 0;
      } else if (iceCounter > 7) {
        printf("   Cup #%d: %d cubes too many!\n", numCups, iceCounter - 7);
        numCups++;
        iceCounter = 0;
      }
    }
    if (iceCounter > 0) {
      printf("   Cup #%d: Need %d more cubes!\n", numCups, 7 - iceCounter);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12b4 <main+0x184>
mov    -0x18(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <fscanf@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1275 <main+0x145>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe1f(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x2c(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x7,-0x1c(%rbp)
jne    122c <main+0xfc>
mov    -0x20(%rbp),%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    1262 <main+0x132>
cmpl   $0x7,-0x1c(%rbp)
jle    125d <main+0x12d>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    $0x7,%edx
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    1262 <main+0x132>
jmp    1267 <main+0x137>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11cc <main+0x9c>
cmpl   $0x0,-0x1c(%rbp)
jle    1298 <main+0x168>
mov    -0x20(%rbp),%esi
mov    $0x7,%edx
sub    -0x1c(%rbp),%edx
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1178 <main+0x48>
xor    %eax,%eax
add    $0x30,%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    0xeab(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0x10(%rsp)
lea    0xe96(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmpl   $0x0,0x10(%rsp)
jle    1297 <main+0x157>
mov    $0x1,%ebp
lea    0xe72(%rip),%r12
jmp    11b9 <main+0x79>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%rbp),%eax
cmp    0x10(%rsp),%ebp
mov    %eax,%ebp
jge    1297 <main+0x157>
lea    0xe4c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0xc(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
lea    0xc(%rsp),%rdx
call   1050 <fscanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11a0 <main+0x60>
mov    $0x1,%r13d
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    1223 <main+0xe3>
cs nopw 0x0(%rax,%rax,1)
xor    %r14d,%r14d
lea    0xe10(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13d
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
jge    1270 <main+0x130>
movl   $0x0,0x14(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
lea    0x14(%rsp),%rdx
call   1050 <fscanf@plt>
add    0x14(%rsp),%r14d
cmp    $0x7,%r14d
je     1200 <main+0xc0>
jle    1218 <main+0xd8>
add    $0xfffffff9,%r14d
lea    0xddd(%rip),%rdi
mov    %r13d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13d
xor    %r14d,%r14d
jmp    1218 <main+0xd8>
nopl   0x0(%rax)
test   %r14d,%r14d
jle    11a0 <main+0x60>
mov    $0x7,%edx
sub    %r14d,%edx
lea    0xdc8(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <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 = [7 x i8] c"ice.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"Session #%d:\0A\00"
@.str.4 = [22 x i8] c" Cup #%d: Perfect!\0A\00"
@.str.5 = [32 x i8] c" Cup #%d: %d cubes too many!\0A\00"
@.str.6 = [33 x i8] c" Cup #%d: Need %d more cubes!\0A\00"
@.str.7 = [2 x i8] c"\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
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
store i32 0, i32* %3
%11 = load i32*, i32** %2
%12 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store i32 1, i32* %4
br label %13
13: ; preds = %64, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %67
17: ; preds = %13
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %18)
store i32 0, i32* %5
store i32 1, i32* %6
store i32 0, i32* %7
%20 = load i32*, i32** %2
%21 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
store i32 0, i32* %8
store i32 0, i32* %8
br label %22
22: ; preds = %51, %17
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %54
26: ; preds = %22
store i32 0, i32* %9
%27 = load i32*, i32** %2
%28 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%29 = load i32, i32* %9
%30 = load i32, i32* %5
%31 = add nsw i32 %30, %29
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 7
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
store i32 0, i32* %5
br label %50
39: ; preds = %26
%40 = load i32, i32* %5
%41 = icmp sgt i32 %40, 7
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i32, i32* %6
%44 = load i32, i32* %5
%45 = sub nsw i32 %44, 7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %43, i32 %45)
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
store i32 0, i32* %5
br label %49
49: ; preds = %42, %39
br label %50
50: ; preds = %49, %34
br label %51
51: ; preds = %50
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %22
54: ; preds = %22
%55 = load i32, i32* %5
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i32, i32* %6
%59 = load i32, i32* %5
%60 = sub nsw i32 7, %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %58, i32 %60)
br label %62
62: ; preds = %57, %54
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
store i32 %66, i32* %4
br label %13
67: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"ice.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"Session #%d:\0A\00"
@.str.4 = [22 x i8] c" Cup #%d: Perfect!\0A\00"
@.str.5 = [32 x i8] c" Cup #%d: %d cubes too many!\0A\00"
@.str.6 = [33 x i8] c" Cup #%d: Need %d more cubes!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %51, label %9
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
br label %12
12: ; preds = %9, %46
%13 = phi i32 [ 1, %9 ], [ %48, %46 ]
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %13)
store i32 0, i32* %2
%15 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %46
18: ; preds = %12, %35
%19 = phi i32 [ %38, %35 ], [ 0, %12 ]
%20 = phi i32 [ %37, %35 ], [ 1, %12 ]
%21 = phi i32 [ %36, %35 ], [ 0, %12 ]
store i32 0, i32* %3
%22 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %3
%24 = add nsw i32 %23, %21
%25 = icmp eq i32 %24, 7
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%28 = add nsw i32 %20, 1
br label %35
29: ; preds = %18
%30 = icmp sgt i32 %24, 7
br i1 %30, label %31, label %35
31: ; preds = %29
%32 = add nsw i32 %24, -7
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %20, i32 %32)
%34 = add nsw i32 %20, 1
br label %35
35: ; preds = %29, %31, %26
%36 = phi i32 [ 0, %26 ], [ 0, %31 ], [ %24, %29 ]
%37 = phi i32 [ %28, %26 ], [ %34, %31 ], [ %20, %29 ]
%38 = add nuw nsw i32 %19, 1
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %18, label %41
41: ; preds = %35
%42 = icmp sgt i32 %36, 0
br i1 %42, label %43, label %46
43: ; preds = %41
%44 = sub nuw nsw i32 7, %36
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %37, i32 %44)
br label %46
46: ; preds = %12, %43, %41
%47 = call i32 @putchar(i32 10)
%48 = add nuw nsw i32 %13, 1
%49 = load i32, i32* %1
%50 = icmp slt i32 %13, %49
br i1 %50, label %12, label %51
51: ; preds = %46, %0
ret i32 0
}