#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 atoi(char *);
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  int i, c, b;
  char *string = NULL, *string2 = NULL;
  int strsize, buffered = 0;
  if (argc == 2 && atoi(argv[1]) == 1)
    buffered = 1;
  i = 0;
  while (c = fgetc(stdin)) {
    if (string != NULL)
      strsize = strlen(string) + 2;
    else
      strsize = 2;
    string2 = malloc(strsize);
    strncpy(string2, string, strsize - 2);
    string = malloc(strsize);
    snprintf(string, strsize, "%s%c", string2, c);
    i++;
    if (c == '\n') {
      if (i == 2)
        if (b == 'q')
          break;
      if (i > 1)
        fprintf(stdout, "%sTotal: %d\n", string, i - 1);
      i = 0;
      if (buffered == 0) {
        string = NULL;
        free(string);
      } else {
        printf("All Total: %d\n", strlen(string));
      }
    }
    b = c;
  }
  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)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11e4 <main+0x54>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
cmp    $0x1,%eax
jne    11e4 <main+0x54>
movl   $0x1,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1080 <fgetc@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1319 <main+0x189>
cmpq   $0x0,-0x28(%rbp)
je     1224 <main+0x94>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    122b <main+0x9b>
movl   $0x2,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
sub    $0x2,%edx
call   1040 <strncpy@plt>
mov    -0x34(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8d
lea    0xd94(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x18(%rbp)
jne    130e <main+0x17e>
cmpl   $0x2,-0x14(%rbp)
jne    12a2 <main+0x112>
cmpl   $0x71,-0x1c(%rbp)
jne    129d <main+0x10d>
jmp    1319 <main+0x189>
jmp    12a2 <main+0x112>
cmpl   $0x1,-0x14(%rbp)
jle    12cb <main+0x13b>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
lea    0xd3f(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    12f2 <main+0x162>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1309 <main+0x179>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
lea    0xd0e(%rip),%rdi
call   1060 <printf@plt>
jmp    130e <main+0x17e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11eb <main+0x5b>
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
push   %rax
movb   $0x1,0x3(%rsp)
cmp    $0x2,%edi
jne    11b6 <main+0x26>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
cmp    $0x1,%eax
setne  0x3(%rsp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1080 <fgetc@plt>
test   %eax,%eax
je     12d9 <main+0x149>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1211 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe23(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
xor    %ebp,%ebp
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1080 <fgetc@plt>
mov    %ebp,%r12d
test   %eax,%eax
je     12d9 <main+0x149>
mov    %r13d,%ecx
mov    %eax,%r13d
test   %rbx,%rbx
mov    %ecx,0x4(%rsp)
je     1240 <main+0xb0>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
add    $0x2,%r15d
jmp    1246 <main+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x2,%r15d
mov    %r15d,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
lea    -0x2(%r15),%edx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strncpy@plt>
mov    %r15d,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15d,%esi
lea    0xd88(%rip),%rdx
mov    %r14,%rcx
mov    %r13d,%r8d
call   1070 <snprintf@plt>
lea    0x1(%r12),%ebp
cmp    $0xa,%r13d
jne    11f8 <main+0x68>
cmp    $0x2,%ebp
jne    129e <main+0x10e>
cmpl   $0x71,0x4(%rsp)
je     12d9 <main+0x149>
test   %r12d,%r12d
jle    12be <main+0x12e>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
call   1090 <fprintf@plt>
cmpb   $0x0,0x3(%rsp)
je     11e0 <main+0x50>
xor    %ebp,%ebp
xor    %edi,%edi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    11f8 <main+0x68>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"%s%c\00"
@stdout = global i32 0
@.str.1 = [13 x i8] c"%sTotal: %d\0A\00"
@.str.2 = [15 x i8] c"All Total: %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 i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %9
store i8* null, i8** %10
store i32 0, i32* %12
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 1, i32* %12
br label %22
22: ; preds = %21, %15, %2
store i32 0, i32* %6
br label %23
23: ; preds = %82, %22
%24 = load i32, i32* @stdin
%25 = call i32 @fgetc(i32 %24)
store i32 %25, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %84
27: ; preds = %23
%28 = load i8*, i8** %9
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i8*, i8** %9
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 2
store i32 %33, i32* %11
br label %35
34: ; preds = %27
store i32 2, i32* %11
br label %35
35: ; preds = %34, %30
%36 = load i32, i32* %11
%37 = call i8* @malloc(i32 %36)
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = load i8*, i8** %9
%40 = load i32, i32* %11
%41 = sub nsw i32 %40, 2
%42 = call i32 @strncpy(i8* %38, i8* %39, i32 %41)
%43 = load i32, i32* %11
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %9
%45 = load i8*, i8** %9
%46 = load i32, i32* %11
%47 = load i8*, i8** %10
%48 = load i32, i32* %7
%49 = call i32 @snprintf(i8* %45, i32 %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %47, i32 %48)
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
%52 = load i32, i32* %7
%53 = icmp eq i32 %52, 10
br i1 %53, label %54, label %82
54: ; preds = %35
%55 = load i32, i32* %6
%56 = icmp eq i32 %55, 2
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i32, i32* %8
%59 = icmp eq i32 %58, 113
br i1 %59, label %60, label %61
60: ; preds = %57
br label %84
61: ; preds = %57
br label %62
62: ; preds = %61, %54
%63 = load i32, i32* %6
%64 = icmp sgt i32 %63, 1
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i32, i32* @stdout
%67 = load i8*, i8** %9
%68 = load i32, i32* %6
%69 = sub nsw i32 %68, 1
%70 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %67, i32 %69)
br label %71
71: ; preds = %65, %62
store i32 0, i32* %6
%72 = load i32, i32* %12
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %71
store i8* null, i8** %9
%75 = load i8*, i8** %9
%76 = call i32 @free(i8* %75)
br label %81
77: ; preds = %71
%78 = load i8*, i8** %9
%79 = call i32 @strlen(i8* %78)
%80 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %79)
br label %81
81: ; preds = %77, %74
br label %82
82: ; preds = %81, %35
%83 = load i32, i32* %7
store i32 %83, i32* %8
br label %23
84: ; preds = %60, %23
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"%s%c\00"
@stdout = global i32 0
@.str.1 = [13 x i8] c"%sTotal: %d\0A\00"
@.str.2 = [15 x i8] c"All Total: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp ne i32 %7, 1
br label %9
9: ; preds = %4, %2
%10 = phi i1 [ true, %2 ], [ %8, %4 ]
%11 = load i32, i32* @stdin
%12 = tail call i32 @fgetc(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %53, label %14
14: ; preds = %9, %47
%15 = phi i32 [ %51, %47 ], [ %12, %9 ]
%16 = phi i8* [ %49, %47 ], [ null, %9 ]
%17 = phi i32 [ %15, %47 ], [ undef, %9 ]
%18 = phi i32 [ %48, %47 ], [ 0, %9 ]
%19 = icmp eq i8* %16, null
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = tail call i32 @strlen(i8* %16)
%22 = add nsw i32 %21, 2
br label %23
23: ; preds = %14, %20
%24 = phi i32 [ %22, %20 ], [ 2, %14 ]
%25 = tail call i8* @malloc(i32 %24)
%26 = add nsw i32 %24, -2
%27 = tail call i32 @strncpy(i8* %25, i8* %16, i32 %26)
%28 = tail call i8* @malloc(i32 %24)
%29 = tail call i32 @snprintf(i8* %28, i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %15)
%30 = add nsw i32 %18, 1
%31 = icmp eq i32 %15, 10
br i1 %31, label %32, label %47
32: ; preds = %23
%33 = icmp eq i32 %30, 2
%34 = icmp eq i32 %17, 113
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %53, label %36
36: ; preds = %32
%37 = icmp sgt i32 %18, 0
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = load i32, i32* @stdout
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %18)
br label %41
41: ; preds = %38, %36
br i1 %10, label %42, label %44
42: ; preds = %41
%43 = tail call i32 @free(i8* null)
br label %47
44: ; preds = %41
%45 = tail call i32 @strlen(i8* %28)
%46 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %42, %44, %23
%48 = phi i32 [ 0, %42 ], [ 0, %44 ], [ %30, %23 ]
%49 = phi i8* [ null, %42 ], [ %28, %44 ], [ %28, %23 ]
%50 = load i32, i32* @stdin
%51 = tail call i32 @fgetc(i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %14
53: ; preds = %47, %32, %9
ret i32 0
}