#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*/ op;

/* Variables and functions */
scalar_t__ ECANCELED;
int /*<<< orphan*/ assert(int);
int dill_chrecv(int, int *, int, int);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, int, int, int);
__attribute__((no)) void statistics(int ch) {
  int active = 0;
  int succeeded = 0;
  int failed = 0;
  while (1) {
    int op;
    int rc = dill_chrecv(ch, &op, sizeof(op), -1);
    if (rc < 0 && errno == ECANCELED)
      return;
    assert(rc == 0);
    switch (op) {
    case 1:
      ++active;
      break;
    case 2:
      --active;
      ++succeeded;
      break;
    case 3:
      --active;
      ++failed;
      break;
    }
    printf("active: %-5d  succeeded: %-5d  failed: %-5d\n", active, succeeded,
           failed);
  }
}


x86 assembly (clang, -O0):
<statistics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
mov    $0xffffffff,%ecx
call   1040 <dill_chrecv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1193 <statistics+0x63>
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jne    1193 <statistics+0x63>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%eax
test   %eax,%eax
sete   %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     11d9 <statistics+0xa9>
jmp    11b7 <statistics+0x87>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     11e7 <statistics+0xb7>
jmp    11c8 <statistics+0x98>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     11fe <statistics+0xce>
jmp    1210 <statistics+0xe0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1210 <statistics+0xe0>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1210 <statistics+0xe0>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
jmp    1150 <statistics+0x20>

x86 assembly (clang, -O2):
<statistics>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
xor    %r13d,%r13d
lea    0x4(%rsp),%r14
lea    0xeb3(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1175 <statistics+0x45>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebp
add    $0x1,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %ebx,%ecx
call   1030 <printf@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
mov    $0xffffffff,%ecx
call   1040 <dill_chrecv@plt>
test   %eax,%eax
jns    11a4 <statistics+0x74>
mov    0x2e43(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e49(%rip),%rdx
cmp    (%rdx),%rcx
je     11d9 <statistics+0xa9>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x4(%rsp),%eax
cmp    $0x3,%eax
je     1160 <statistics+0x30>
cmp    $0x2,%eax
je     11d0 <statistics+0xa0>
cmp    $0x1,%eax
jne    1166 <statistics+0x36>
add    $0x1,%ebp
jmp    1166 <statistics+0x36>
nopl   0x0(%rax)
add    $0xffffffff,%ebp
add    $0x1,%r13d
jmp    1166 <statistics+0x36>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ECANCELED = global i64 0
@.str = [45 x i8] c"active: %-5d succeeded: %-5d failed: %-5d\0A\00"
define void @statistics(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %1, %37
%9 = load i32, i32* %2
%10 = call i32 @dill_chrecv(i32 %9, i32* %6, i32 4, i32 -1)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i64, i64* @errno
%15 = load i64, i64* @ECANCELED
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13
ret void
18: ; preds = %13, %8
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %6
switch i32 %23, label %37 [
i32 1, label %24
i32 2, label %27
i32 3, label %32
]
24: ; preds = %18
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %37
27: ; preds = %18
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %37
32: ; preds = %18
%33 = load i32, i32* %3
%34 = add nsw i32 %33, -1
store i32 %34, i32* %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %37
37: ; preds = %18, %32, %27, %24
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39, i32 %40)
br label %8
}

LLVM IR (-O2):
@errno = global i64 0
@ECANCELED = global i64 0
@.str = [45 x i8] c"active: %-5d succeeded: %-5d failed: %-5d\0A\00"
define void @statistics(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %27, %1
%5 = phi i32 [ 0, %1 ], [ %28, %27 ]
%6 = phi i32 [ 0, %1 ], [ %29, %27 ]
%7 = phi i32 [ 0, %1 ], [ %30, %27 ]
%8 = call i32 @dill_chrecv(i32 %0, i32* %2, i32 4, i32 -1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = load i64, i64* @errno
%12 = load i64, i64* @ECANCELED
%13 = icmp eq i64 %11, %12
br i1 %13, label %32, label %14
14: ; preds = %10, %4
%15 = icmp eq i32 %8, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %2
switch i32 %18, label %27 [
i32 1, label %19
i32 2, label %21
i32 3, label %24
]
19: ; preds = %14
%20 = add nsw i32 %7, 1
br label %27
21: ; preds = %14
%22 = add nsw i32 %7, -1
%23 = add nsw i32 %5, 1
br label %27
24: ; preds = %14
%25 = add nsw i32 %7, -1
%26 = add nsw i32 %6, 1
br label %27
27: ; preds = %19, %21, %24, %14
%28 = phi i32 [ %5, %14 ], [ %5, %24 ], [ %23, %21 ], [ %5, %19 ]
%29 = phi i32 [ %6, %14 ], [ %26, %24 ], [ %6, %21 ], [ %6, %19 ]
%30 = phi i32 [ %7, %14 ], [ %25, %24 ], [ %22, %21 ], [ %20, %19 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %28, i32 %29)
br label %4
32: ; preds = %10
ret void
}