#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 */
char *convert_double(double *, int, float);
int /*<<< orphan*/ sprintf(char *, char *, double, ...);
scalar_t__ strstr(char *, char *);
void format_value_multi_interface(char *buff, double value, char *unit) {
  char *mag;
  if (strstr(unit, "b"))
    value *= 8;
  mag = convert_double(&value, (strstr(unit, "B")) ? 1024 : 1000, 1.0f);
  if (mag[0] == 0)
    sprintf(buff, "%4ld", (long)value);
  else if (value < 10)
    sprintf(buff, "%3.1f%s", value, mag);
  else
    sprintf(buff, "%3.0f%s", value, mag);
}


x86 assembly (clang, -O0):
<format_value_multi_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec4(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1171 <format_value_multi_interface+0x41>
movsd  0xe99(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
mov    $0x3e8,%esi
mov    $0x400,%eax
cmp    $0x0,%rcx
cmovne %eax,%esi
lea    -0x10(%rbp),%rdi
movss  0xe6f(%rip),%xmm0
call   1030 <convert_double@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11dc <format_value_multi_interface+0xac>
mov    -0x8(%rbp),%rdi
cvttsd2si -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
lea    0xe48(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    122f <format_value_multi_interface+0xff>
movsd  0xe24(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    120f <format_value_multi_interface+0xdf>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    122a <format_value_multi_interface+0xfa>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rdx
lea    0xe02(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    122f <format_value_multi_interface+0xff>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_value_multi_interface>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  %xmm0,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1171 <format_value_multi_interface+0x41>
movsd  0x10(%rsp),%xmm0
mulsd  0xe95(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
mov    $0x3e8,%eax
mov    $0x400,%esi
cmove  %eax,%esi
lea    0x8(%rsp),%rdi
movss  0xe73(%rip),%xmm0
call   1030 <convert_double@plt>
cmpb   $0x0,(%rax)
movsd  0x8(%rsp),%xmm0
je     11c4 <format_value_multi_interface+0x94>
movsd  0xe53(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11e4 <format_value_multi_interface+0xb4>
lea    0xe5b(%rip),%rsi
jmp    11eb <format_value_multi_interface+0xbb>
cvttsd2si %xmm0,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
lea    0xe40(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    11f8 <format_value_multi_interface+0xc8>
lea    0xe3a(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
mov    $0x1,%al
call   1040 <sprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"B\00"
@.str.2 = [5 x i8] c"%4ld\00"
@.str.3 = [8 x i8] c"%3.1f%s\00"
@.str.4 = [8 x i8] c"%3.0f%s\00"
define void @format_value_multi_interface(i8* %0, double %1, i8* %2) {
%4 = alloca i8*
%5 = alloca double
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store double %1, double* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i64 @strstr(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load double, double* %5
%13 = fmul double %12, 8.000000e+00
store double %13, double* %5
br label %14
14: ; preds = %11, %3
%15 = load i8*, i8** %6
%16 = call i64 @strstr(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 1024, i32 1000
%20 = call i8* @convert_double(double* %5, i32 %19, float 1.000000e+00)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %14
%27 = load i8*, i8** %4
%28 = load double, double* %5
%29 = fptosi double %28 to i64
%30 = sitofp i64 %29 to double
%31 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %30)
br label %46
32: ; preds = %14
%33 = load double, double* %5
%34 = fcmp olt double %33, 1.000000e+01
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8*, i8** %4
%37 = load double, double* %5
%38 = load i8*, i8** %7
%39 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %37, i8* %38)
br label %45
40: ; preds = %32
%41 = load i8*, i8** %4
%42 = load double, double* %5
%43 = load i8*, i8** %7
%44 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %42, i8* %43)
br label %45
45: ; preds = %40, %35
br label %46
46: ; preds = %45, %26
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"B\00"
@.str.2 = [5 x i8] c"%4ld\00"
@.str.3 = [8 x i8] c"%3.1f%s\00"
@.str.4 = [8 x i8] c"%3.0f%s\00"
define void @format_value_multi_interface(i8* nocapture writeonly %0, double %1, i8* %2) {
%4 = alloca double
store double %1, double* %4
%5 = tail call i64 @strstr(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = fmul double %1, 8.000000e+00
store double %8, double* %4
br label %9
9: ; preds = %7, %3
%10 = tail call i64 @strstr(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i32 1000, i32 1024
%13 = call i8* @convert_double(double* %4, i32 %12, float 1.000000e+00)
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
%16 = load double, double* %4
br i1 %15, label %17, label %21
17: ; preds = %9
%18 = fptosi double %16 to i64
%19 = sitofp i64 %18 to double
%20 = call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %19)
br label %27
21: ; preds = %9
%22 = fcmp olt double %16, 1.000000e+01
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %16, i8* %13)
br label %27
25: ; preds = %21
%26 = call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %16, i8* %13)
br label %27
27: ; preds = %23, %25, %17
ret void
}