#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
int trickled_getinfo(int *, int *, int *, int *);
int /*<<< orphan*/ warnx(char *, int, int, double);
void handle_command(int cmd, int ac, char **av) {
  switch (cmd) {
  case 0: {
    uint32_t uplim, uprate, downlim, downrate;
    if (trickled_getinfo(&uplim, &uprate, &downlim, &downrate) == -1)
      err(1, "trickled_getinfo()");
    warnx("DOWNLOAD: %d.%d KB/s (utilization: %.1f%%)", downrate / 1024,
          (downrate % 1024) * 100 / 1024,
          ((1.0 * downrate) / (1.0 * downlim)) * 100);
    if (uprate == 0)
      uprate = 1;
    warnx("UPLOAD: %d.%d KB/s (utilization: %.1f%%)", uprate / 1024,
          (uprate % 1024) * 100 / 1024, ((1.0 * uprate) / (1.0 * uplim)) * 100);
  }
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<handle_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
test   %eax,%eax
jne    1258 <handle_command+0x128>
jmp    1152 <handle_command+0x22>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1030 <trickled_getinfo@plt>
cmp    $0xffffffff,%eax
jne    1181 <handle_command+0x51>
mov    $0x1,%edi
lea    0xe94(%rip),%rsi
call   1050 <err@plt>
mov    -0x20(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x20(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
imul   $0x64,%edx,%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
cvtsi2sdl -0x20(%rbp),%xmm1
movsd  0xe55(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm2
movsd  0xe44(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe2c(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xe44(%rip),%rdi
call   1040 <warnx@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11f5 <handle_command+0xc5>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x18(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
imul   $0x64,%edx,%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xde1(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm2
movsd  0xdd0(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xdb8(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xdfb(%rip),%rdi
call   1040 <warnx@plt>
jmp    125d <handle_command+0x12d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_command>:
test   %edi,%edi
je     1135 <handle_command+0x5>
ret
sub    $0x18,%rsp
lea    0x14(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1030 <trickled_getinfo@plt>
cmp    $0xffffffff,%eax
jne    1168 <handle_command+0x38>
lea    0xeaa(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    0xc(%rsp),%eax
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    %ecx,%esi
sar    $0xa,%esi
and    $0xfffffc00,%ecx
cvtsi2sd %eax,%xmm0
sub    %ecx,%eax
imul   $0x64,%eax,%eax
lea    0x3ff(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
cvtsi2sdl 0x10(%rsp),%xmm1
sar    $0xa,%edx
divsd  %xmm1,%xmm0
mulsd  0xe55(%rip),%xmm0
lea    0xe69(%rip),%rdi
call   1040 <warnx@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jne    11cc <handle_command+0x9c>
movl   $0x1,0x8(%rsp)
mov    $0x1,%eax
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    %ecx,%esi
sar    $0xa,%esi
and    $0xfffffc00,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
sub    %ecx,%eax
imul   $0x64,%eax,%eax
lea    0x3ff(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
xorps  %xmm1,%xmm1
cvtsi2sdl 0x14(%rsp),%xmm1
sar    $0xa,%edx
divsd  %xmm1,%xmm0
mulsd  0xdef(%rip),%xmm0
lea    0xe2e(%rip),%rdi
call   1040 <warnx@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"trickled_getinfo()\00"
@.str.1 = [43 x i8] c"DOWNLOAD: %d.%d KB/s (utilization: %.1f%%)\00"
@.str.2 = [41 x i8] c"UPLOAD: %d.%d KB/s (utilization: %.1f%%)\00"
define void @handle_command(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%11 = load i32, i32* %4
switch i32 %11, label %52 [
i32 0, label %12
]
12: ; preds = %3
%13 = call i32 @trickled_getinfo(i32* %7, i32* %8, i32* %9, i32* %10)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* %10
%19 = sdiv i32 %18, 1024
%20 = load i32, i32* %10
%21 = srem i32 %20, 1024
%22 = mul nsw i32 %21, 100
%23 = sdiv i32 %22, 1024
%24 = load i32, i32* %10
%25 = sitofp i32 %24 to double
%26 = fmul double 1.000000e+00, %25
%27 = load i32, i32* %9
%28 = sitofp i32 %27 to double
%29 = fmul double 1.000000e+00, %28
%30 = fdiv double %26, %29
%31 = fmul double %30, 1.000000e+02
%32 = call i32 @warnx(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %23, double %31)
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %17
store i32 1, i32* %8
br label %36
36: ; preds = %35, %17
%37 = load i32, i32* %8
%38 = sdiv i32 %37, 1024
%39 = load i32, i32* %8
%40 = srem i32 %39, 1024
%41 = mul nsw i32 %40, 100
%42 = sdiv i32 %41, 1024
%43 = load i32, i32* %8
%44 = sitofp i32 %43 to double
%45 = fmul double 1.000000e+00, %44
%46 = load i32, i32* %7
%47 = sitofp i32 %46 to double
%48 = fmul double 1.000000e+00, %47
%49 = fdiv double %45, %48
%50 = fmul double %49, 1.000000e+02
%51 = call i32 @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %42, double %50)
br label %52
52: ; preds = %3, %36
br label %53
53: ; preds = %52
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"trickled_getinfo()\00"
@.str.1 = [43 x i8] c"DOWNLOAD: %d.%d KB/s (utilization: %.1f%%)\00"
@.str.2 = [41 x i8] c"UPLOAD: %d.%d KB/s (utilization: %.1f%%)\00"
define void @handle_command(i32 %0, i32 %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = icmp eq i32 %0, 0
br i1 %8, label %9, label %45
9: ; preds = %3
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = call i32 @trickled_getinfo(i32* %4, i32* %5, i32* %6, i32* %7)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
%19 = load i32, i32* %7
%20 = sdiv i32 %19, 1024
%21 = srem i32 %19, 1024
%22 = mul nsw i32 %21, 100
%23 = sdiv i32 %22, 1024
%24 = sitofp i32 %19 to double
%25 = load i32, i32* %6
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
%28 = fmul double %27, 1.000000e+02
%29 = call i32 @warnx(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %23, double %28)
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %18
store i32 1, i32* %5
br label %33
33: ; preds = %32, %18
%34 = phi i32 [ 1, %32 ], [ %30, %18 ]
%35 = sdiv i32 %34, 1024
%36 = srem i32 %34, 1024
%37 = mul nsw i32 %36, 100
%38 = sdiv i32 %37, 1024
%39 = sitofp i32 %34 to double
%40 = load i32, i32* %4
%41 = sitofp i32 %40 to double
%42 = fdiv double %39, %41
%43 = fmul double %42, 1.000000e+02
%44 = call i32 @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %38, double %43)
br label %45
45: ; preds = %33, %3
ret void
}