#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__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int i, red, yellow, green, rolls, total = 0;
  int *avg_array;
  scanf("%d", &rolls);
  avg_array = (int *)malloc(rolls * sizeof(int));
  for (i = 0; i < rolls; i++) {
    scanf("%d %d %d", &red, &yellow, &green);
    if ((green > 6) || (yellow > 6) || (red > 6)) {
      printf("Invalid input\n");
      return 1;
    };
    *(avg_array + i) = (green * 100) + (yellow * 10) + (red * 1);
  };
  for (i = 0; i < rolls; i++) {
    double curr_avg = 0;
    total += *(avg_array + i);
    curr_avg = (double)total / (i + 1);
    printf("you rolled: %d, current average: %.1lf\n", avg_array[i], curr_avg);
  };
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb9(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11fb <main+0xcb>
lea    0xe7b(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x6,-0x14(%rbp)
jg     11b6 <main+0x86>
cmpl   $0x6,-0x10(%rbp)
jg     11b6 <main+0x86>
cmpl   $0x6,-0xc(%rbp)
jle    11d0 <main+0xa0>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x142>
imul   $0x64,-0x14(%rbp),%edx
imul   $0xa,-0x10(%rbp),%eax
add    %eax,%edx
mov    -0xc(%rbp),%eax
shl    $0x0,%eax
add    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1172 <main+0x42>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    126b <main+0x13b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
movsd  -0x30(%rbp),%xmm0
lea    0xdc2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1202 <main+0xd2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xeb1(%rip),%rdi
xor    %r12d,%r12d
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
cmpl   $0x0,0x8(%rsp)
jle    1244 <main+0x104>
mov    %rax,%r14
lea    0xe7b(%rip),%rbx
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x6,%eax
jg     1232 <main+0xf2>
mov    0x10(%rsp),%edx
cmp    $0x6,%edx
jg     1232 <main+0xf2>
mov    0x14(%rsp),%ecx
cmp    $0x7,%ecx
jge    1232 <main+0xf2>
imul   $0x64,%eax,%eax
lea    (%rdx,%rdx,4),%edx
lea    (%rax,%rdx,2),%eax
add    %ecx,%eax
mov    %eax,(%r14,%rbp,4)
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
cmp    %rax,%rbp
jl     11a0 <main+0x60>
xor    %r12d,%r12d
test   %eax,%eax
jle    1244 <main+0x104>
lea    0xe10(%rip),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r14,%rbp,4),%esi
add    %esi,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
add    $0x1,%rbp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x8(%rsp),%rax
cmp    %rax,%rbp
jl     1200 <main+0xc0>
jmp    1244 <main+0x104>
lea    0xdf8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [15 x i8] c"Invalid input\0A\00"
@.str.3 = [40 x i8] c"you rolled: %d, current average: %.1lf\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 double
store i32 0, i32* %1
store i32 0, i32* %7
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %8
store i32 0, i32* %2
br label %17
17: ; preds = %46, %0
%18 = load i32, i32* %2
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %49
21: ; preds = %17
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 6
br i1 %24, label %31, label %25
25: ; preds = %21
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 6
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i32, i32* %3
%30 = icmp sgt i32 %29, 6
br i1 %30, label %31, label %33
31: ; preds = %28, %25, %21
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %79
33: ; preds = %28
%34 = load i32, i32* %5
%35 = mul nsw i32 %34, 100
%36 = load i32, i32* %4
%37 = mul nsw i32 %36, 10
%38 = add nsw i32 %35, %37
%39 = load i32, i32* %3
%40 = mul nsw i32 %39, 1
%41 = add nsw i32 %38, %40
%42 = load i32*, i32** %8
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %41, i32* %45
br label %46
46: ; preds = %33
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %17
49: ; preds = %17
store i32 0, i32* %2
br label %50
50: ; preds = %75, %49
%51 = load i32, i32* %2
%52 = load i32, i32* %6
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %78
54: ; preds = %50
store double 0.000000e+00, double* %9
%55 = load i32*, i32** %8
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %58
%60 = load i32, i32* %7
%61 = add nsw i32 %60, %59
store i32 %61, i32* %7
%62 = load i32, i32* %7
%63 = sitofp i32 %62 to double
%64 = load i32, i32* %2
%65 = add nsw i32 %64, 1
%66 = sitofp i32 %65 to double
%67 = fdiv double %63, %66
store double %67, double* %9
%68 = load i32*, i32** %8
%69 = load i32, i32* %2
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
%72 = load i32, i32* %71
%73 = load double, double* %9
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %72, double %73)
br label %75
75: ; preds = %54
%76 = load i32, i32* %2
%77 = add nsw i32 %76, 1
store i32 %77, i32* %2
br label %50
78: ; preds = %50
store i32 0, i32* %1
br label %79
79: ; preds = %78, %31
%80 = load i32, i32* %1
ret i32 %80
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.3 = [40 x i8] c"you rolled: %d, current average: %.1lf\0A\00"
@str = [14 x i8] c"Invalid input\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 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %4
%11 = shl i32 %10, 2
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %18, label %56
16: ; preds = %31
%17 = icmp sgt i32 %38, 0
br i1 %17, label %41, label %56
18: ; preds = %0, %31
%19 = phi i64 [ %37, %31 ], [ 0, %0 ]
%20 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 6
%23 = load i32, i32* %2
%24 = icmp sgt i32 %23, 6
%25 = select i1 %22, i1 true, i1 %24
%26 = load i32, i32* %1
%27 = icmp sgt i32 %26, 6
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %56
31: ; preds = %18
%32 = mul nsw i32 %21, 100
%33 = mul nsw i32 %23, 10
%34 = add nsw i32 %33, %32
%35 = add nsw i32 %34, %26
%36 = getelementptr inbounds i32, i32* %13, i64 %19
store i32 %35, i32* %36
%37 = add nuw nsw i64 %19, 1
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %18, label %16
41: ; preds = %16, %41
%42 = phi i64 [ %48, %41 ], [ 0, %16 ]
%43 = phi i32 [ %46, %41 ], [ 0, %16 ]
%44 = getelementptr inbounds i32, i32* %13, i64 %42
%45 = load i32, i32* %44
%46 = add nsw i32 %45, %43
%47 = sitofp i32 %46 to double
%48 = add nuw nsw i64 %42, 1
%49 = trunc i64 %48 to i32
%50 = sitofp i32 %49 to double
%51 = fdiv double %47, %50
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %45, double %51)
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %48, %54
br i1 %55, label %41, label %56
56: ; preds = %41, %0, %16, %29
%57 = phi i32 [ 1, %29 ], [ 0, %16 ], [ 0, %0 ], [ 0, %41 ]
ret i32 %57
}