#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int fread(int *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, char *args[]) {
  int M = 50000;
  if (argc > 1)
    sscanf(args[1], "%d", &M);
  uint32_t sum = 0;
  uint8_t in;
  int nr = fread(&in, 1, 1, stdin);
  int cnt = 0;
  while (nr > 0) {
    sum += in;
    nr = fread(&in, 1, 1, stdin);
    cnt++;
    if (cnt >= M) {
      printf("%d\n", sum);
      cnt -= M;
      sum = 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc350,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    116f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
movl   $0x0,-0x18(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%ecx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1203 <main+0xd3>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%ecx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11fe <main+0xce>
mov    -0x18(%rbp),%esi
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1199 <main+0x69>
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
push   %rax
movl   $0xc350,(%rsp)
cmp    $0x2,%edi
jl     115a <main+0x2a>
mov    0x8(%rsi),%rdi
lea    0xeae(%rip),%rsi
mov    %rsp,%rdx
call   1050 <sscanf@plt>
mov    0x2e87(%rip),%r12
mov    (%r12),%ecx
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
test   %eax,%eax
jle    11cb <main+0x9b>
xor    %ebx,%ebx
lea    0x4(%rsp),%r15
lea    0xe78(%rip),%r14
xor    %ebp,%ebp
jmp    1195 <main+0x65>
nop
test   %r13d,%r13d
jle    11cb <main+0x9b>
add    0x4(%rsp),%ebp
mov    (%r12),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,%r13d
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     1190 <main+0x60>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
sub    (%rsp),%ebx
xor    %ebp,%ebp
jmp    1190 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%d\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 50000, i32* %6
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %18
18: ; preds = %13, %2
store i32 0, i32* %7
%19 = load i32, i32* @stdin
%20 = call i32 @fread(i32* %8, i32 1, i32 1, i32 %19)
store i32 %20, i32* %9
store i32 0, i32* %10
br label %21
21: ; preds = %41, %18
%22 = load i32, i32* %9
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %21
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = add nsw i32 %26, %25
store i32 %27, i32* %7
%28 = load i32, i32* @stdin
%29 = call i32 @fread(i32* %8, i32 1, i32 1, i32 %28)
store i32 %29, i32* %9
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = load i32, i32* %6
%34 = icmp sge i32 %32, %33
br i1 %34, label %35, label %41
35: ; preds = %24
%36 = load i32, i32* %7
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %10
%40 = sub nsw i32 %39, %38
store i32 %40, i32* %10
store i32 0, i32* %7
br label %41
41: ; preds = %35, %24
br label %21
42: ; preds = %21
%43 = load i32, i32* %3
ret i32 %43
}

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