#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 *, long);
int /*<<< orphan*/ scanf(char *, ...);
int main(int argc, char *argv[]) {
  int n, f, loop, inner_loop;
  long farmSize, animalsCount, environmentFriendliness, partialResult;
  scanf("%d", &n);
  for (loop = 0; loop < n; loop++) {
    partialResult = 0;
    scanf("%d", &f);
    for (inner_loop = 0; inner_loop < f; inner_loop++) {
      scanf("%ld %ld %ld", &farmSize, &animalsCount, &environmentFriendliness);
      partialResult += farmSize * environmentFriendliness;
    }
    printf("%ld\n", partialResult);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11df <main+0xbf>
movq   $0x0,-0x40(%rbp)
lea    0xe96(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c1 <main+0xa1>
lea    0xe74(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%rax
imul   -0x38(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117c <main+0x5c>
mov    -0x40(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <main+0x2f>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11de <main+0xbe>
lea    0x18(%rsp),%r13
lea    0x20(%rsp),%r12
lea    0x10(%rsp),%rbp
xor    %ebx,%ebx
jmp    117f <main+0x5f>
nop
xor    %r15d,%r15d
lea    0xea5(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    0xc(%rsp),%ebx
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
jge    11de <main+0xbe>
lea    0xe7a(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
mov    %ebx,0xc(%rsp)
jle    1160 <main+0x40>
xor    %r15d,%r15d
xor    %r14d,%r14d
lea    0xe59(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rax
imul   0x18(%rsp),%rax
add    %rax,%r15
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
jl     11b0 <main+0x90>
jmp    1163 <main+0x43>
xor    %eax,%eax
add    $0x28,%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 = [12 x i8] c"%ld %ld %ld\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %8
br label %15
15: ; preds = %38, %2
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %41
19: ; preds = %15
store i64 0, i64* %13
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 0, i32* %9
br label %21
21: ; preds = %32, %19
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64* %10, i64* %11, i64* %12)
%27 = load i64, i64* %10
%28 = load i64, i64* %12
%29 = mul nsw i64 %27, %28
%30 = load i64, i64* %13
%31 = add nsw i64 %30, %29
store i64 %31, i64* %13
br label %32
32: ; preds = %25
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %21
35: ; preds = %21
%36 = load i64, i64* %13
%37 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %36)
br label %38
38: ; preds = %35
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %15
41: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [12 x i8] c"%ld %ld %ld\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i64* %5 to i8*
%11 = bitcast i64* %6 to i8*
%12 = bitcast i64* %7 to i8*
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %2, %32
%17 = phi i32 [ %35, %32 ], [ 0, %2 ]
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %16, %21
%22 = phi i64 [ %28, %21 ], [ 0, %16 ]
%23 = phi i32 [ %29, %21 ], [ 0, %16 ]
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64* %5, i64* %6, i64* %7)
%25 = load i64, i64* %5
%26 = load i64, i64* %7
%27 = mul nsw i64 %26, %25
%28 = add nsw i64 %27, %22
%29 = add nuw nsw i32 %23, 1
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %21, label %32
32: ; preds = %21, %16
%33 = phi i64 [ 0, %16 ], [ %28, %21 ]
%34 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %33)
%35 = add nuw nsw i32 %17, 1
%36 = load i32, i32* %3
%37 = icmp slt i32 %35, %36
br i1 %37, label %16, label %38
38: ; preds = %32, %2
ret i32 0
}