#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*/ aprintf(char *, char *, char *, ...);
int /*<<< orphan*/ hexfade(char *, char *, double, char *);
void calc_traf_sym(int traf, char *status, char *sym, char *col, char *col2) {
  static char hv[4];
  hexfade(col, col2, (double)traf / ((double)500 * (double)1024), hv);
  if (traf > 1024 * 1024) {
    traf /= 1024 * 1024;
    aprintf(status, "^[f%s;%s%dM", hv, sym, traf);
  } else if (traf > 1024) {
    traf /= 1024;
    aprintf(status, "^[f%s;%s%dK", hv, sym, traf);
  } else if (traf > 20) {
    aprintf(status, "^[f%s;%s%d", hv, sym, traf);
  }
  aprintf(status, "^[f444;%s", sym);
}


x86 assembly (clang, -O0):
<calc_traf_sym>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xeb0(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2ed6(%rip),%rdx
call   1040 <hexfade@plt>
cmpl   $0x100000,-0x4(%rbp)
jle    11a1 <calc_traf_sym+0x81>
mov    -0x4(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x4(%rbp),%r8d
lea    0xe7a(%rip),%rsi
lea    0x2e9c(%rip),%rdx
mov    $0x0,%al
call   1030 <aprintf@plt>
jmp    1217 <calc_traf_sym+0xf7>
cmpl   $0x400,-0x4(%rbp)
jle    11e2 <calc_traf_sym+0xc2>
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x4(%rbp),%r8d
lea    0xe45(%rip),%rsi
lea    0x2e5b(%rip),%rdx
mov    $0x0,%al
call   1030 <aprintf@plt>
jmp    1212 <calc_traf_sym+0xf2>
cmpl   $0x14,-0x4(%rbp)
jle    120d <calc_traf_sym+0xed>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x4(%rbp),%r8d
lea    0xe21(%rip),%rsi
lea    0x2e2b(%rip),%rdx
mov    $0x0,%al
call   1030 <aprintf@plt>
jmp    1212 <calc_traf_sym+0xf2>
jmp    1217 <calc_traf_sym+0xf7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1030 <aprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_traf_sym>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
cvtsi2sd %edi,%xmm0
divsd  0xec8(%rip),%xmm0
lea    0x2ef2(%rip),%rdx
mov    %rcx,%rdi
mov    %r8,%rsi
call   1040 <hexfade@plt>
cmp    $0x100001,%ebp
jl     115e <calc_traf_sym+0x3e>
shr    $0x14,%ebp
lea    0xeac(%rip),%rsi
jmp    117e <calc_traf_sym+0x5e>
cmp    $0x401,%ebp
jl     1172 <calc_traf_sym+0x52>
shr    $0xa,%ebp
lea    0xea4(%rip),%rsi
jmp    117e <calc_traf_sym+0x5e>
cmp    $0x15,%ebp
jl     1195 <calc_traf_sym+0x75>
lea    0xea2(%rip),%rsi
lea    0x2eac(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <aprintf@plt>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <aprintf@plt>

LLVM IR (-O0):
@calc_traf_sym.hv = internal global [4 x i8] zeroinitializer
@.str = [12 x i8] c"^[f%s;%s%dM\00"
@.str.1 = [12 x i8] c"^[f%s;%s%dK\00"
@.str.2 = [11 x i8] c"^[f%s;%s%d\00"
@.str.3 = [10 x i8] c"^[f444;%s\00"
define void @calc_traf_sym(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%11 = load i8*, i8** %9
%12 = load i8*, i8** %10
%13 = load i32, i32* %6
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 5.120000e+05
%16 = call i32 @hexfade(i8* %11, i8* %12, double %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0))
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 1048576
br i1 %18, label %19, label %26
19: ; preds = %5
%20 = load i32, i32* %6
%21 = sdiv i32 %20, 1048576
store i32 %21, i32* %6
%22 = load i8*, i8** %7
%23 = load i8*, i8** %8
%24 = load i32, i32* %6
%25 = call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0), i8* %23, i32 %24)
br label %46
26: ; preds = %5
%27 = load i32, i32* %6
%28 = icmp sgt i32 %27, 1024
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %6
%31 = sdiv i32 %30, 1024
store i32 %31, i32* %6
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
%34 = load i32, i32* %6
%35 = call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0), i8* %33, i32 %34)
br label %45
36: ; preds = %26
%37 = load i32, i32* %6
%38 = icmp sgt i32 %37, 20
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8*, i8** %7
%41 = load i8*, i8** %8
%42 = load i32, i32* %6
%43 = call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0), i8* %41, i32 %42)
br label %44
44: ; preds = %39, %36
br label %45
45: ; preds = %44, %29
br label %46
46: ; preds = %45, %19
%47 = load i8*, i8** %7
%48 = load i8*, i8** %8
%49 = call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %48)
ret void
}

LLVM IR (-O2):
@calc_traf_sym.hv = internal global [4 x i8] zeroinitializer
@.str = [12 x i8] c"^[f%s;%s%dM\00"
@.str.1 = [12 x i8] c"^[f%s;%s%dK\00"
@.str.2 = [11 x i8] c"^[f%s;%s%d\00"
@.str.3 = [10 x i8] c"^[f444;%s\00"
define void @calc_traf_sym(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = sitofp i32 %0 to double
%7 = fdiv double %6, 5.120000e+05
%8 = tail call i32 @hexfade(i8* %3, i8* %4, double %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0))
%9 = icmp sgt i32 %0, 1048576
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = lshr i32 %0, 20
%12 = tail call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0), i8* %2, i32 %11)
br label %22
13: ; preds = %5
%14 = icmp sgt i32 %0, 1024
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = lshr i32 %0, 10
%17 = tail call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0), i8* %2, i32 %16)
br label %22
18: ; preds = %13
%19 = icmp sgt i32 %0, 20
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = tail call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @calc_traf_sym.hv, i64 0, i64 0), i8* %2, i32 %0)
br label %22
22: ; preds = %15, %20, %18, %10
%23 = tail call i32 (i8*, i8*, i8*, ...) @aprintf(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %2)
ret void
}