#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int percent(double);
int /*<<< orphan*/ print(char *, double);
int /*<<< orphan*/ printf(char *, int, int);
double ratio(int, int);
int shoco_compress(char *, int /*<<< orphan*/, char *, int);
int shoco_decompress(char *, int, char *, int);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  char buffer[1024] = {0};
  char comp[1024] = {0};
  char out[1024] = {0};
  int count = 0;
  double ratios = 0;
  double rat = 0;
  int inlen, complen, outlen;
  while (fgets(buffer, 1024, stdin) != NULL) {
    char *end = strchr(buffer, '\n');
    if (end != NULL)
      *end = '\0';
    else
      break;
    inlen = strlen(buffer);
    complen = shoco_compress(buffer, 0, comp, 1024);
    outlen = shoco_decompress(comp, complen, out, 1024);
    rat = ratio(inlen, complen);
    if (complen != 0) {
      ++count;
      ratios += rat;
    }
    if ((argc > 1) &&
        ((strcmp(argv[1], "-v") == 0) || (strcmp(argv[1], "--verbose") == 0))) {
      print(buffer, rat);
    }
    assert(inlen == outlen);
    assert(strcmp(buffer, out) == 0);
  }
  printf("Number of compressed strings: %d, average compression ratio: %d%%\n",
         count, percent(ratios / count));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0xc10(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0xc14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xc20(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xc28(%rbp)
ff
lea    -0x410(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     13cf <main+0x20f>
lea    -0x410(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0xc40(%rbp)
cmpq   $0x0,-0xc40(%rbp)
je     128b <main+0xcb>
mov    -0xc40(%rbp),%rax
movb   $0x0,(%rax)
jmp    1290 <main+0xd0>
jmp    13cf <main+0x20f>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc2c(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rdx
xor    %esi,%esi
mov    $0x400,%ecx
call   10c0 <shoco_compress@plt>
mov    %eax,-0xc30(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0xc30(%rbp),%esi
lea    -0xc10(%rbp),%rdx
mov    $0x400,%ecx
call   1090 <shoco_decompress@plt>
mov    %eax,-0xc34(%rbp)
mov    -0xc2c(%rbp),%edi
mov    -0xc30(%rbp),%esi
call   10d0 <ratio@plt>
movsd  %xmm0,-0xc28(%rbp)
ff
cmpl   $0x0,-0xc30(%rbp)
je     1333 <main+0x173>
mov    -0xc14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc14(%rbp)
movsd  -0xc28(%rbp),%xmm0
ff
addsd  -0xc20(%rbp),%xmm0
ff
movsd  %xmm0,-0xc20(%rbp)
ff
cmpl   $0x1,-0x8(%rbp)
jle    138d <main+0x1cd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcb4(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1379 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc99(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    138d <main+0x1cd>
lea    -0x410(%rbp),%rdi
movsd  -0xc28(%rbp),%xmm0
ff
call   1070 <print@plt>
mov    -0xc2c(%rbp),%eax
cmp    -0xc34(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x410(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
jmp    1232 <main+0x72>
mov    -0xc14(%rbp),%eax
mov    %eax,-0xc44(%rbp)
movsd  -0xc20(%rbp),%xmm0
ff
cvtsi2sdl -0xc14(%rbp),%xmm1
ff
divsd  %xmm1,%xmm0
call   10e0 <percent@plt>
mov    -0xc44(%rbp),%esi
mov    %eax,%edx
lea    0xc0a(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xc50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc38,%rsp
mov    %rsi,0x18(%rsp)
mov    %edi,0x10(%rsp)
lea    0x830(%rsp),%rbp
xor    %ebx,%ebx
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x430(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x30(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
je     13b2 <main+0x1f2>
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
lea    0x830(%rsp),%r12
lea    0x30(%rsp),%rbp
jmp    12d5 <main+0x115>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
movsd  0x20(%rsp),%xmm0
call   1070 <print@plt>
mov    %bl,%r13b
mov    0x14(%rsp),%ebx
add    %r13d,%ebx
movsd  0x8(%rsp),%xmm0
addsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
cmp    %ebp,%r14d
sete   %dil
call   10b0 <assert@plt>
mov    %r12,%rdi
lea    0x30(%rsp),%rbp
mov    %rbp,%rsi
call   10a0 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10b0 <assert@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     13b8 <main+0x1f8>
mov    %r12,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     13b8 <main+0x1f8>
mov    %ebx,0x14(%rsp)
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %r12,%r15
mov    %r12,%rdi
xor    %esi,%esi
lea    0x430(%rsp),%rbx
mov    %rbx,%rdx
mov    $0x400,%ecx
call   10c0 <shoco_compress@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
mov    $0x400,%ecx
call   1090 <shoco_decompress@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %r12d,%esi
call   10d0 <ratio@plt>
movapd %xmm0,%xmm1
xor    %r13d,%r13d
movsd  0xcb5(%rip),%xmm0
test   %r12d,%r12d
setne  %bl
je     1357 <main+0x197>
movapd %xmm1,%xmm0
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x28(%rsp)
cmpl   $0x2,0x10(%rsp)
mov    %r15,%r12
jl     126e <main+0xae>
mov    0x18(%rsp),%rax
mov    0x8(%rax),%rdi
lea    0xc87(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1260 <main+0xa0>
mov    0x18(%rsp),%rax
mov    0x8(%rax),%rdi
lea    0xc6c(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    126e <main+0xae>
jmp    1260 <main+0xa0>
movsd  %xmm0,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   10e0 <percent@plt>
lea    0xc40(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xc38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"-v\00"
@.str.1 = [10 x i8] c"--verbose\00"
@.str.2 = [67 x i8] c"Number of compressed strings: %d, average compression ratio: %d%%\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [1024 x i8]* %6 to i8*
%17 = bitcast [1024 x i8]* %7 to i8*
%18 = bitcast [1024 x i8]* %8 to i8*
store i32 0, i32* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
br label %19
19: ; preds = %72, %2
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32* @fgets(i8* %20, i32 1024, i32 %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %84
24: ; preds = %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 10)
store i8* %26, i8** %15
%27 = load i8*, i8** %15
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i8*, i8** %15
store i8 0, i8* %30
br label %32
31: ; preds = %24
br label %84
32: ; preds = %29
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %12
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = call i32 @shoco_compress(i8* %35, i32 0, i8* %36, i32 1024)
store i32 %37, i32* %13
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%39 = load i32, i32* %13
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = call i32 @shoco_decompress(i8* %38, i32 %39, i8* %40, i32 1024)
store i32 %41, i32* %14
%42 = load i32, i32* %12
%43 = load i32, i32* %13
%44 = call double @ratio(i32 %42, i32 %43)
store double %44, double* %11
%45 = load i32, i32* %13
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %32
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
%50 = load double, double* %11
%51 = load double, double* %10
%52 = fadd double %51, %50
store double %52, double* %10
br label %53
53: ; preds = %47, %32
%54 = load i32, i32* %4
%55 = icmp sgt i32 %54, 1
br i1 %55, label %56, label %72
56: ; preds = %53
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %68, label %62
62: ; preds = %56
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %62, %56
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%70 = load double, double* %11
%71 = call i32 @print(i8* %69, double %70)
br label %72
72: ; preds = %68, %62, %53
%73 = load i32, i32* %12
%74 = load i32, i32* %14
%75 = icmp eq i32 %73, %74
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%80 = call i64 @strcmp(i8* %78, i8* %79)
%81 = icmp eq i64 %80, 0
%82 = zext i1 %81 to i32
%83 = call i32 @assert(i32 %82)
br label %19
84: ; preds = %31, %19
%85 = load i32, i32* %9
%86 = load double, double* %10
%87 = load i32, i32* %9
%88 = sitofp i32 %87 to double
%89 = fdiv double %86, %88
%90 = call i32 @percent(double %89)
%91 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0), i32 %85, i32 %90)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"-v\00"
@.str.1 = [10 x i8] c"--verbose\00"
@.str.2 = [67 x i8] c"Number of compressed strings: %d, average compression ratio: %d%%\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %6, i32 1024, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %52, label %12
12: ; preds = %2
%13 = icmp sgt i32 %0, 1
%14 = getelementptr inbounds i8*, i8** %1, i64 1
br label %15
15: ; preds = %12, %41
%16 = phi i32 [ 0, %12 ], [ %30, %41 ]
%17 = phi double [ 0.000000e+00, %12 ], [ %27, %41 ]
%18 = call i8* @strchr(i8* %6, i8 signext 10)
%19 = icmp eq i8* %18, null
br i1 %19, label %52, label %20
20: ; preds = %15
store i8 0, i8* %18
%21 = call i32 @strlen(i8* %6)
%22 = call i32 @shoco_compress(i8* %6, i32 0, i8* %7, i32 1024)
%23 = call i32 @shoco_decompress(i8* %7, i32 %22, i8* %8, i32 1024)
%24 = call double @ratio(i32 %21, i32 %22)
%25 = icmp eq i32 %22, 0
%26 = select i1 %25, double -0.000000e+00, double %24
%27 = fadd double %17, %26
%28 = xor i1 %25, true
%29 = zext i1 %28 to i32
%30 = add nuw nsw i32 %16, %29
br i1 %13, label %31, label %41
31: ; preds = %20
%32 = load i8*, i8** %14
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load i8*, i8** %14
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35, %31
%40 = call i32 @print(i8* %6, double %24)
br label %41
41: ; preds = %20, %35, %39
%42 = icmp eq i32 %21, %23
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = call i64 @strcmp(i8* %6, i8* %8)
%46 = icmp eq i64 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i32, i32* @stdin
%50 = call i32* @fgets(i8* %6, i32 1024, i32 %49)
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %15
52: ; preds = %41, %15, %2
%53 = phi double [ 0.000000e+00, %2 ], [ %17, %15 ], [ %27, %41 ]
%54 = phi i32 [ 0, %2 ], [ %16, %15 ], [ %30, %41 ]
%55 = sitofp i32 %54 to double
%56 = fdiv double %53, %55
%57 = call i32 @percent(double %56)
%58 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %57)
ret i32 0
}