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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, char *, long);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  char line[32767], prevkey[32767];
  char *key = NULL;
  long sum = 0;
  memset(prevkey, 0, sizeof(prevkey));
  while (fgets(line, sizeof(line), stdin) != NULL) {
    char *cp = line;
    int len = (int)strlen(line);
    long count;
    if (cp[len - 1] == '\n') {
      cp[len - 1] = '\0';
    }
    key = line;
    cp = strchr(line, ' ');
    if (cp == NULL) {
      continue;
    }
    *cp++ = '\0';
    count = 0;
    while (cp - line < len) {
      long val;
      char *endptr = NULL;
      val = strtol(cp, &endptr, 10);
      if (val == 0 && cp == endptr) {
        break;
      }
      count += val;
      cp = endptr;
    }
    if (strlen(prevkey) == 0) {
      memset(prevkey, sizeof(prevkey), 0);
      strncpy(prevkey, key, sizeof(prevkey) - 1);
      sum = count;
      continue;
    }
    if (strcmp(prevkey, key) != 0) {
      printf("%s %ld\n", prevkey, sum);
      memset(prevkey, sizeof(prevkey), 0);
      strncpy(prevkey, key, sizeof(prevkey) - 1);
      sum = count;
    } else {
      sum += count;
    }
  }
  if (strlen(prevkey) > 0) {
    printf("%s %ld\n", prevkey, sum);
  }
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x10018(%rbp)
movq   $0x0,-0x10020(%rbp)
lea    -0x10010(%rbp),%rdi
xor    %esi,%esi
mov    $0x7fff,%edx
call   1070 <memset@plt>
lea    -0x8010(%rbp),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    $0x7fff,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1426 <main+0x296>
lea    -0x8010(%rbp),%rax
mov    %rax,-0x10028(%rbp)
lea    -0x8010(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1002c(%rbp)
mov    -0x10028(%rbp),%rax
mov    -0x1002c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    124d <main+0xbd>
mov    -0x10028(%rbp),%rax
mov    -0x1002c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x8010(%rbp),%rax
mov    %rax,-0x10018(%rbp)
lea    -0x8010(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10028(%rbp)
cmpq   $0x0,-0x10028(%rbp)
jne    1286 <main+0xf6>
jmp    11d2 <main+0x42>
mov    -0x10028(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10028(%rbp)
movb   $0x0,(%rax)
movq   $0x0,-0x10038(%rbp)
mov    -0x10028(%rbp),%rax
lea    -0x8010(%rbp),%rcx
sub    %rcx,%rax
movslq -0x1002c(%rbp),%rcx
cmp    %rcx,%rax
jge    1343 <main+0x1b3>
movq   $0x0,-0x10048(%rbp)
mov    -0x10028(%rbp),%rdi
lea    -0x10048(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <strtol@plt>
mov    %rax,-0x10040(%rbp)
cmpq   $0x0,-0x10040(%rbp)
jne    131b <main+0x18b>
mov    -0x10028(%rbp),%rax
cmp    -0x10048(%rbp),%rax
jne    131b <main+0x18b>
jmp    1343 <main+0x1b3>
mov    -0x10040(%rbp),%rax
add    -0x10038(%rbp),%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10048(%rbp),%rax
mov    %rax,-0x10028(%rbp)
jmp    12a9 <main+0x119>
lea    -0x10010(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1397 <main+0x207>
lea    -0x10010(%rbp),%rdi
mov    $0x7fff,%esi
xor    %edx,%edx
call   1070 <memset@plt>
lea    -0x10010(%rbp),%rdi
mov    -0x10018(%rbp),%rsi
mov    $0x7ffe,%edx
call   1030 <strncpy@plt>
mov    -0x10038(%rbp),%rax
mov    %rax,-0x10020(%rbp)
jmp    11d2 <main+0x42>
lea    -0x10010(%rbp),%rdi
mov    -0x10018(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     140c <main+0x27c>
lea    -0x10010(%rbp),%rsi
mov    -0x10020(%rbp),%rdx
lea    0xc37(%rip),%rdi
call   1060 <printf@plt>
lea    -0x10010(%rbp),%rdi
mov    $0x7fff,%esi
xor    %edx,%edx
call   1070 <memset@plt>
lea    -0x10010(%rbp),%rdi
mov    -0x10018(%rbp),%rsi
mov    $0x7ffe,%edx
call   1030 <strncpy@plt>
mov    -0x10038(%rbp),%rax
mov    %rax,-0x10020(%rbp)
jmp    1421 <main+0x291>
mov    -0x10038(%rbp),%rax
add    -0x10020(%rbp),%rax
mov    %rax,-0x10020(%rbp)
jmp    11d2 <main+0x42>
lea    -0x10010(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    1456 <main+0x2c6>
lea    -0x10010(%rbp),%rsi
mov    -0x10020(%rbp),%rdx
lea    0xbaf(%rip),%rdi
call   1060 <printf@plt>
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
xor    %eax,%eax
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
lea    0x10(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x7fff,%edx
call   1070 <memset@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
lea    0x8010(%rsp),%r13
mov    %r13,%rdi
mov    $0x7fff,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     1321 <main+0x191>
xor    %ebp,%ebp
lea    0x8(%rsp),%r14
jmp    1215 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rbx
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0x7fff,%esi
call   1080 <fgets@plt>
mov    %rbx,%rbp
test   %rax,%rax
je     1321 <main+0x191>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
shl    $0x20,%r12
movabs $0xffffffff00000000,%rax
ff ff ff
add    %r12,%rax
sar    $0x20,%rax
cmpb   $0xa,0x8010(%rsp,%rax,1)
0a
jne    1247 <main+0xb7>
movb   $0x0,0x8010(%rsp,%rax,1)
mov    %r13,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11f0 <main+0x60>
mov    %rax,%rcx
add    $0x1,%rcx
movb   $0x0,(%rax)
sar    $0x20,%r12
xor    %edx,%edx
nopl   0x0(%rax)
mov    %rdx,%rbx
mov    %rcx,%rax
sub    %r13,%rax
cmp    %r12,%rax
jge    12ad <main+0x11d>
mov    %rcx,%r15
movq   $0x0,0x8(%rsp)
mov    %rcx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   10a0 <strtol@plt>
lea    (%rax,%rbx,1),%rdx
mov    0x8(%rsp),%rcx
test   %rax,%rax
jne    1270 <main+0xe0>
cmp    %rcx,%r15
jne    1270 <main+0xe0>
cmpb   $0x0,0x10(%rsp)
je     12f0 <main+0x160>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1319 <main+0x189>
lea    0xd30(%rip),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1060 <printf@plt>
mov    %r15,%rdi
mov    $0x7fff,%esi
xor    %edx,%edx
call   1070 <memset@plt>
mov    %r15,%rdi
jmp    1307 <main+0x177>
nop
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x7fff,%esi
xor    %edx,%edx
call   1070 <memset@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x7ffe,%edx
call   1030 <strncpy@plt>
jmp    11f3 <main+0x63>
add    %rbp,%rbx
jmp    11f3 <main+0x63>
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    1344 <main+0x1b4>
lea    0xcc9(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1060 <printf@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
xor    %eax,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [8 x i8] c"%s %ld\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32767 x i8]
%7 = alloca [32767 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i64 0, i64* %9
%15 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 32767)
br label %17
17: ; preds = %105, %79, %47, %2
%18 = getelementptr inbounds [32767 x i8], [32767 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32* @fgets(i8* %18, i32 32767, i32 %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %106
22: ; preds = %17
%23 = getelementptr inbounds [32767 x i8], [32767 x i8]* %6, i64 0, i64 0
store i8* %23, i8** %10
%24 = getelementptr inbounds [32767 x i8], [32767 x i8]* %6, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %11
%27 = load i8*, i8** %10
%28 = load i32, i32* %11
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %41
35: ; preds = %22
%36 = load i8*, i8** %10
%37 = load i32, i32* %11
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %35, %22
%42 = getelementptr inbounds [32767 x i8], [32767 x i8]* %6, i64 0, i64 0
store i8* %42, i8** %8
%43 = getelementptr inbounds [32767 x i8], [32767 x i8]* %6, i64 0, i64 0
%44 = call i8* @strchr(i8* %43, i8 signext 32)
store i8* %44, i8** %10
%45 = load i8*, i8** %10
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %41
br label %17
48: ; preds = %41
%49 = load i8*, i8** %10
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %10
store i8 0, i8* %49
store i64 0, i64* %12
br label %51
51: ; preds = %70, %48
%52 = load i8*, i8** %10
%53 = getelementptr inbounds [32767 x i8], [32767 x i8]* %6, i64 0, i64 0
%54 = ptrtoint i8* %52 to i64
%55 = ptrtoint i8* %53 to i64
%56 = sub i64 %54, %55
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = icmp slt i64 %56, %58
br i1 %59, label %60, label %75
60: ; preds = %51
store i8* null, i8** %14
%61 = load i8*, i8** %10
%62 = call i64 @strtol(i8* %61, i8** %14, i32 10)
store i64 %62, i64* %13
%63 = load i64, i64* %13
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %60
%66 = load i8*, i8** %10
%67 = load i8*, i8** %14
%68 = icmp eq i8* %66, %67
br i1 %68, label %69, label %70
69: ; preds = %65
br label %75
70: ; preds = %65, %60
%71 = load i64, i64* %13
%72 = load i64, i64* %12
%73 = add nsw i64 %72, %71
store i64 %73, i64* %12
%74 = load i8*, i8** %14
store i8* %74, i8** %10
br label %51
75: ; preds = %69, %51
%76 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%77 = call i64 @strlen(i8* %76)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %86
79: ; preds = %75
%80 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%81 = call i32 @memset(i8* %80, i32 32767, i32 0)
%82 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%83 = load i8*, i8** %8
%84 = call i32 @strncpy(i8* %82, i8* %83, i32 32766)
%85 = load i64, i64* %12
store i64 %85, i64* %9
br label %17
86: ; preds = %75
%87 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%88 = load i8*, i8** %8
%89 = call i64 @strcmp(i8* %87, i8* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %101
91: ; preds = %86
%92 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%93 = load i64, i64* %9
%94 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %92, i64 %93)
%95 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%96 = call i32 @memset(i8* %95, i32 32767, i32 0)
%97 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%98 = load i8*, i8** %8
%99 = call i32 @strncpy(i8* %97, i8* %98, i32 32766)
%100 = load i64, i64* %12
store i64 %100, i64* %9
br label %105
101: ; preds = %86
%102 = load i64, i64* %12
%103 = load i64, i64* %9
%104 = add nsw i64 %103, %102
store i64 %104, i64* %9
br label %105
105: ; preds = %101, %91
br label %17
106: ; preds = %17
%107 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%108 = call i64 @strlen(i8* %107)
%109 = icmp sgt i64 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %106
%111 = getelementptr inbounds [32767 x i8], [32767 x i8]* %7, i64 0, i64 0
%112 = load i64, i64* %9
%113 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %111, i64 %112)
br label %114
114: ; preds = %110, %106
%115 = load i32, i32* @stdout
%116 = call i32 @fflush(i32 %115)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [8 x i8] c"%s %ld\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32767 x i8]
%4 = alloca [32767 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [32767 x i8], [32767 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32767 x i8], [32767 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 32767)
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %6, i32 32767, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %64, label %12
12: ; preds = %2
%13 = ptrtoint [32767 x i8]* %3 to i64
%14 = bitcast i8** %5 to i8*
br label %15
15: ; preds = %12, %59
%16 = phi i64 [ 0, %12 ], [ %60, %59 ]
%17 = call i64 @strlen(i8* %6)
%18 = shl i64 %17, 32
%19 = add i64 %18, -4294967296
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds [32767 x i8], [32767 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 10
br i1 %23, label %24, label %25
24: ; preds = %15
store i8 0, i8* %21
br label %25
25: ; preds = %24, %15
%26 = call i8* @strchr(i8* %6, i8 signext 32)
%27 = icmp eq i8* %26, null
br i1 %27, label %59, label %28
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %26, i64 1
store i8 0, i8* %26
%30 = ashr exact i64 %18, 32
br label %31
31: ; preds = %37, %28
%32 = phi i8* [ %29, %28 ], [ %40, %37 ]
%33 = phi i64 [ 0, %28 ], [ %43, %37 ]
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %34, %13
%36 = icmp slt i64 %35, %30
br i1 %36, label %37, label %44
37: ; preds = %31
store i8* null, i8** %5
%38 = call i64 @strtol(i8* %32, i8** %5, i32 10)
%39 = icmp eq i64 %38, 0
%40 = load i8*, i8** %5
%41 = icmp eq i8* %32, %40
%42 = select i1 %39, i1 %41, i1 false
%43 = add nsw i64 %38, %33
br i1 %42, label %44, label %31
44: ; preds = %37, %31
%45 = load i8, i8* %7
%46 = icmp eq i8 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 @memset(i8* %7, i32 32767, i32 0)
%49 = call i32 @strncpy(i8* %7, i8* %6, i32 32766)
br label %59
50: ; preds = %44
%51 = call i64 @strcmp(i8* %7, i8* %6)
%52 = icmp eq i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %50
%54 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7, i64 %16)
%55 = call i32 @memset(i8* %7, i32 32767, i32 0)
%56 = call i32 @strncpy(i8* %7, i8* %6, i32 32766)
br label %59
57: ; preds = %50
%58 = add nsw i64 %33, %16
br label %59
59: ; preds = %53, %57, %25, %47
%60 = phi i64 [ %33, %47 ], [ %16, %25 ], [ %33, %53 ], [ %58, %57 ]
%61 = load i32, i32* @stdin
%62 = call i32* @fgets(i8* %6, i32 32767, i32 %61)
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %15
64: ; preds = %59, %2
%65 = phi i64 [ 0, %2 ], [ %60, %59 ]
%66 = call i64 @strlen(i8* %7)
%67 = icmp sgt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7, i64 %65)
br label %70
70: ; preds = %68, %64
%71 = load i32, i32* @stdout
%72 = call i32 @fflush(i32 %71)
ret i32 0
}