#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 */
double atof(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ piece(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, char *, char, double);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void group_sum(char delimiter) {
  char input_buffer[1024];
  char compare_buffer[1024];
  char old_compare_buffer[1024];
  char piece_buffer[1024];
  char value_buffer[1024];
  double sum = 0.0;
  int first_time = 1;
  *old_compare_buffer = '\0';
  while (get_line(input_buffer, stdin)) {
    piece(piece_buffer, delimiter, input_buffer, 0);
    if (!piece(value_buffer, delimiter, input_buffer, 1)) {
      fprintf(stderr, "Error: cannot find delimiter in (%s)\n", input_buffer);
      continue;
    }
    strcpy(compare_buffer, piece_buffer);
    if (first_time) {
      first_time = 0;
      sum = atof(value_buffer);
      strcpy(old_compare_buffer, compare_buffer);
      continue;
    }
    if (strcmp(compare_buffer, old_compare_buffer) == 0) {
      sum += atof(value_buffer);
    } else {
      printf("%s%c%.5lf\n", old_compare_buffer, delimiter, sum);
      sum = atof(value_buffer);
    }
    strcpy(old_compare_buffer, compare_buffer);
  }
  if (!first_time) {
    printf("%s%c%.5lf\n", old_compare_buffer, delimiter, sum);
  }
}


x86 assembly (clang, -O0):
<group_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1420,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1418(%rbp)
ff
movl   $0x1,-0x141c(%rbp)
movb   $0x0,-0xc10(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1050 <get_line@plt>
cmp    $0x0,%rax
je     1300 <group_sum+0x190>
lea    -0x1010(%rbp),%rdi
mov    -0x1(%rbp),%al
lea    -0x410(%rbp),%rdx
xor    %ecx,%ecx
movsbl %al,%esi
call   1090 <piece@plt>
lea    -0x1410(%rbp),%rdi
mov    -0x1(%rbp),%al
lea    -0x410(%rbp),%rdx
mov    $0x1,%ecx
movsbl %al,%esi
call   1090 <piece@plt>
cmp    $0x0,%eax
jne    121f <group_sum+0xaf>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdeb(%rip),%rsi
call   1080 <fprintf@plt>
jmp    119d <group_sum+0x2d>
lea    -0x810(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x141c(%rbp)
je     1275 <group_sum+0x105>
movl   $0x0,-0x141c(%rbp)
lea    -0x1410(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x1418(%rbp)
ff
lea    -0xc10(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    119d <group_sum+0x2d>
lea    -0x810(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12b3 <group_sum+0x143>
lea    -0x1410(%rbp),%rdi
call   1040 <atof@plt>
addsd  -0x1418(%rbp),%xmm0
ff
movsd  %xmm0,-0x1418(%rbp)
ff
jmp    12e8 <group_sum+0x178>
lea    -0xc10(%rbp),%rsi
mov    -0x1(%rbp),%al
movsd  -0x1418(%rbp),%xmm0
ff
lea    0xd5a(%rip),%rdi
movsbl %al,%edx
call   1060 <printf@plt>
lea    -0x1410(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x1418(%rbp)
ff
lea    -0xc10(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    119d <group_sum+0x2d>
cmpl   $0x0,-0x141c(%rbp)
jne    132e <group_sum+0x1be>
lea    -0xc10(%rbp),%rsi
mov    -0x1(%rbp),%al
movsd  -0x1418(%rbp),%xmm0
ff
lea    0xd00(%rip),%rdi
movsbl %al,%edx
call   1060 <printf@plt>
add    $0x1420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<group_sum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1418,%rsp
mov    %edi,%ebx
movb   $0x0,0x10(%rsp)
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0x810(%rsp),%rdi
call   1050 <get_line@plt>
test   %rax,%rax
je     1302 <group_sum+0x192>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
movsbl %bl,%ebp
lea    0x1010(%rsp),%r14
lea    0x810(%rsp),%rbx
lea    0xc10(%rsp),%r15
mov    0x2dfd(%rip),%r13
lea    0xe1e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1090 <piece@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1090 <piece@plt>
test   %eax,%eax
jne    123f <group_sum+0xcf>
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <get_line@plt>
test   %rax,%rax
jne    11f0 <group_sum+0x80>
jmp    12e2 <group_sum+0x172>
lea    0x410(%rsp),%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
testb  $0x1,0x4(%rsp)
je     1286 <group_sum+0x116>
lea    0x410(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1296 <group_sum+0x126>
lea    0xdb2(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %ebp,%edx
movsd  0x8(%rsp),%xmm0
call   1060 <printf@plt>
mov    %r15,%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x8(%rsp)
jmp    12ae <group_sum+0x13e>
mov    %r15,%rdi
call   1040 <atof@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0x10(%rsp),%rdi
lea    0x410(%rsp),%rsi
call   1030 <strcpy@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <get_line@plt>
mov    $0x1,%cl
mov    %ecx,0x4(%rsp)
test   %rax,%rax
jne    11f0 <group_sum+0x80>
jmp    12e9 <group_sum+0x179>
testb  $0x1,0x4(%rsp)
je     1302 <group_sum+0x192>
lea    0xd36(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %ebp,%edx
movsd  0x8(%rsp),%xmm0
call   1060 <printf@plt>
add    $0x1418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Error: cannot find delimiter in (%s)\0A\00"
@.str.1 = [11 x i8] c"%s%c%.5lf\0A\00"
define void @group_sum(i8 signext %0) {
%2 = alloca i8
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca double
%9 = alloca i32
store i8 %0, i8* %2
store double 0.000000e+00, double* %8
store i32 1, i32* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
store i8 0, i8* %10
br label %11
11: ; preds = %59, %36, %26, %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i64 @get_line(i8* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %63
16: ; preds = %11
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = load i8, i8* %2
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = call i32 @piece(i8* %17, i8 signext %18, i8* %19, i32 0)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = load i8, i8* %2
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = call i32 @piece(i8* %21, i8 signext %22, i8* %23, i32 1)
%25 = icmp ne i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %11
30: ; preds = %16
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i32, i32* %9
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %30
store i32 0, i32* %9
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = call double @atof(i8* %37)
store double %38, double* %8
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%41 = call i32 @strcpy(i8* %39, i8* %40)
br label %11
42: ; preds = %30
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%45 = call i64 @strcmp(i8* %43, i8* %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%49 = call double @atof(i8* %48)
%50 = load double, double* %8
%51 = fadd double %50, %49
store double %51, double* %8
br label %59
52: ; preds = %42
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%54 = load i8, i8* %2
%55 = load double, double* %8
%56 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %53, i8 signext %54, double %55)
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%58 = call double @atof(i8* %57)
store double %58, double* %8
br label %59
59: ; preds = %52, %47
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%62 = call i32 @strcpy(i8* %60, i8* %61)
br label %11
63: ; preds = %11
%64 = load i32, i32* %9
%65 = icmp ne i32 %64, 0
br i1 %65, label %71, label %66
66: ; preds = %63
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%68 = load i8, i8* %2
%69 = load double, double* %8
%70 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %67, i8 signext %68, double %69)
br label %71
71: ; preds = %66, %63
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Error: cannot find delimiter in (%s)\0A\00"
@.str.1 = [11 x i8] c"%s%c%.5lf\0A\00"
define void @group_sum(i8 signext %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8 0, i8* %9
%12 = load i32, i32* @stdin
%13 = call i64 @get_line(i8* %7, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %51, label %15
15: ; preds = %1, %32
%16 = phi i1 [ true, %32 ], [ false, %1 ]
%17 = phi double [ %33, %32 ], [ 0.000000e+00, %1 ]
br label %18
18: ; preds = %15, %22
%19 = call i32 @piece(i8* %10, i8 signext %0, i8* %7, i32 0)
%20 = call i32 @piece(i8* %11, i8 signext %0, i8* %7, i32 1)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %7)
%25 = load i32, i32* @stdin
%26 = call i64 @get_line(i8* %7, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %47, label %18
28: ; preds = %18
%29 = call i32 @strcpy(i8* %8, i8* %10)
br i1 %16, label %38, label %30
30: ; preds = %28
%31 = call double @atof(i8* %11)
br label %32
32: ; preds = %41, %44, %30
%33 = phi double [ %31, %30 ], [ %43, %41 ], [ %46, %44 ]
%34 = call i32 @strcpy(i8* %9, i8* %8)
%35 = load i32, i32* @stdin
%36 = call i64 @get_line(i8* %7, i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %48, label %15
38: ; preds = %28
%39 = call i64 @strcmp(i8* %8, i8* %9)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call double @atof(i8* %11)
%43 = fadd double %17, %42
br label %32
44: ; preds = %38
%45 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8 signext %0, double %17)
%46 = call double @atof(i8* %11)
br label %32
47: ; preds = %22
br i1 %16, label %48, label %51
48: ; preds = %32, %47
%49 = phi double [ %17, %47 ], [ %33, %32 ]
%50 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8 signext %0, double %49)
br label %51
51: ; preds = %1, %48, %47
ret void
}