#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 */
struct wav_file_headers {
  int dummy;
};

/* Variables and functions */
float calc_real_time(int, struct wav_file_headers *);
int /*<<< orphan*/ printf(char *, float, char *, float);
int /*<<< orphan*/ sprintf(char *, char *, int);
unsigned int time(int /*<<< orphan*/ *);
void display_stats(int sample_c, int bytecount, unsigned int start_time,
                   struct wav_file_headers *wav_headers) {
  float wavtime;
  int total;
  char human[256];
  int orig_byte_count;
  unsigned int current_time;
  float kbps;
  current_time = time(NULL);
  wavtime = calc_real_time(sample_c, wav_headers);
  orig_byte_count = bytecount;
  if ((bytecount % 1024) == bytecount) {
    sprintf(human, "%5i b ", bytecount);
    bytecount = -1;
  } else {
    bytecount = total = bytecount / 1024;
  }
  if ((total % 1024) == bytecount) {
    sprintf(human, "%5i KB", total);
    bytecount = -1;
  } else {
    total = total / 1024;
  }
  if (bytecount != -1)
    sprintf(human, "%5i MB", total);
  kbps = (float)(orig_byte_count / 1024) / (float)(current_time - start_time);
  printf("\rProcessed %.2f s - %s total - %.1f KB/s throughput\r", wavtime,
         human, kbps);
}


x86 assembly (clang, -O0):
<display_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x128(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <calc_real_time@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    -0x8(%rbp),%edx
jne    11b7 <display_stats+0x77>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe5a(%rip),%rsi
call   1060 <sprintf@plt>
movl   $0xffffffff,-0x8(%rbp)
jmp    11c8 <display_stats+0x88>
mov    -0x8(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    -0x8(%rbp),%edx
jne    11fe <display_stats+0xbe>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe1a(%rip),%rsi
call   1060 <sprintf@plt>
movl   $0xffffffff,-0x8(%rbp)
jmp    120c <display_stats+0xcc>
mov    -0x20(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     122c <display_stats+0xec>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xde7(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x124(%rbp),%eax
mov    %eax,%ecx
add    $0x3ff,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
sar    $0xa,%eax
cvtsi2ss %eax,%xmm0
mov    -0x128(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    %ecx,%eax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x12c(%rbp)
ff
movss  -0x1c(%rbp),%xmm0
lea    -0x120(%rbp),%rsi
movss  -0x12c(%rbp),%xmm1
ff
lea    0xd98(%rip),%rdi
call   1030 <printf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_stats>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rcx,%r12
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %r12,%rsi
call   1050 <calc_real_time@plt>
lea    0x3ff(%rbx),%eax
test   %ebx,%ebx
mov    %ebx,%ebp
cmovs  %eax,%ebp
sar    $0xa,%ebp
test   $0x3fffff,%ebp
jne    1195 <display_stats+0x55>
lea    0xe74(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %ebx,%edx
jmp    11e8 <display_stats+0xa8>
test   %ebx,%ebx
cmovns %ebx,%eax
mov    %eax,%ebp
sar    $0xa,%ebp
lea    0x3ff(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
test   $0xfffffc00,%eax
jne    11c1 <display_stats+0x81>
lea    0xe4f(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %ebp,%edx
jmp    11e8 <display_stats+0xa8>
lea    0x7ff(%rbx),%eax
cmp    $0x400,%eax
jb     11f9 <display_stats+0xb9>
lea    0xfffff(%rbx),%edx
test   %ebx,%ebx
cmovns %ebx,%edx
sar    $0x14,%edx
lea    0xe2b(%rip),%rsi
lea    0x10(%rsp),%rdi
movss  %xmm0,0xc(%rsp)
call   1060 <sprintf@plt>
movss  0xc(%rsp),%xmm0
cvtsi2ss %ebp,%xmm1
sub    %r14d,%r15d
cvtsi2ss %r15,%xmm2
divss  %xmm2,%xmm1
lea    0xe05(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1030 <printf@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.wav_file_headers = type { i32 }
@.str = [7 x i8] c"%5i b \00"
@.str.1 = [7 x i8] c"%5i KB\00"
@.str.2 = [7 x i8] c"%5i MB\00"
@.str.3 = [53 x i8] c"\0DProcessed %.2f s - %s total - %.1f KB/s throughput\0D\00"
define void @display_stats(i32 %0, i32 %1, i32 %2, %struct.wav_file_headers* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.wav_file_headers*
%9 = alloca float
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store %struct.wav_file_headers* %3, %struct.wav_file_headers** %8
%15 = call i32 @time(i32* null)
store i32 %15, i32* %13
%16 = load i32, i32* %5
%17 = load %struct.wav_file_headers*, %struct.wav_file_headers** %8
%18 = call float @calc_real_time(i32 %16, %struct.wav_file_headers* %17)
store float %18, float* %9
%19 = load i32, i32* %6
store i32 %19, i32* %12
%20 = load i32, i32* %6
%21 = srem i32 %20, 1024
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%26 = load i32, i32* %6
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %26)
store i32 -1, i32* %6
br label %31
28: ; preds = %4
%29 = load i32, i32* %6
%30 = sdiv i32 %29, 1024
store i32 %30, i32* %10
store i32 %30, i32* %6
br label %31
31: ; preds = %28, %24
%32 = load i32, i32* %10
%33 = srem i32 %32, 1024
%34 = load i32, i32* %6
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%38 = load i32, i32* %10
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %38)
store i32 -1, i32* %6
br label %43
40: ; preds = %31
%41 = load i32, i32* %10
%42 = sdiv i32 %41, 1024
store i32 %42, i32* %10
br label %43
43: ; preds = %40, %36
%44 = load i32, i32* %6
%45 = icmp ne i32 %44, -1
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%48 = load i32, i32* %10
%49 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %46, %43
%51 = load i32, i32* %12
%52 = sdiv i32 %51, 1024
%53 = sitofp i32 %52 to float
%54 = load i32, i32* %13
%55 = load i32, i32* %7
%56 = sub i32 %54, %55
%57 = uitofp i32 %56 to float
%58 = fdiv float %53, %57
store float %58, float* %14
%59 = load float, float* %9
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%61 = load float, float* %14
%62 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), float %59, i8* %60, float %61)
ret void
}

LLVM IR (-O2):
%struct.wav_file_headers = type { i32 }
@.str = [7 x i8] c"%5i b \00"
@.str.1 = [7 x i8] c"%5i KB\00"
@.str.2 = [7 x i8] c"%5i MB\00"
@.str.3 = [53 x i8] c"\0DProcessed %.2f s - %s total - %.1f KB/s throughput\0D\00"
define void @display_stats(i32 %0, i32 %1, i32 %2, %struct.wav_file_headers* %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @time(i32* null)
%8 = tail call float @calc_real_time(i32 %0, %struct.wav_file_headers* %3)
%9 = srem i32 %1, 1024
%10 = sdiv i32 %1, 1024
%11 = icmp eq i32 %9, %1
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = sdiv i32 %1, 1024
%14 = srem i32 %13, 1024
%15 = icmp eq i32 %14, %13
br i1 %15, label %18, label %20
16: ; preds = %4
%17 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %26
18: ; preds = %12
%19 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %26
20: ; preds = %12
%21 = add i32 %1, 2047
%22 = icmp ult i32 %21, 1024
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = sdiv i32 %1, 1048576
%25 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %16, %18, %23, %20
%27 = phi i32 [ %10, %16 ], [ %13, %18 ], [ %13, %23 ], [ %13, %20 ]
%28 = sitofp i32 %27 to float
%29 = sub i32 %7, %2
%30 = uitofp i32 %29 to float
%31 = fdiv float %28, %30
%32 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), float %8, i8* %6, float %31)
ret void
}