#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*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strcpy(char *, char *);
char *format_percent(double v) {
  static char result[10];
  if (v < 0 || v >= 10000.) {
    strcpy(result, "  ???");
  } else if (v > 99.99) {
    sprintf(result, "%4.0f", v);
  } else {
    sprintf(result, "%4.1f", v);
  }
  return result;
}


x86 assembly (clang, -O0):
<format_percent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     1152 <format_percent+0x32>
movsd  -0x8(%rbp),%xmm0
movsd  0xeb8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     116a <format_percent+0x4a>
lea    0x2ed8(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bb <format_percent+0x9b>
movsd  -0x8(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119e <format_percent+0x7e>
movsd  -0x8(%rbp),%xmm0
lea    0x2ea4(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11b6 <format_percent+0x96>
movsd  -0x8(%rbp),%xmm0
lea    0x2e87(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11bb <format_percent+0x9b>
lea    0x2e6f(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_percent>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     114f <format_percent+0x2f>
ucomisd 0xecd(%rip),%xmm0
jae    114f <format_percent+0x2f>
lea    0x2ef5(%rip),%rdi
ucomisd 0xec4(%rip),%xmm0
jbe    1164 <format_percent+0x44>
lea    0xec9(%rip),%rsi
jmp    116b <format_percent+0x4b>
lea    0x2edb(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1170 <format_percent+0x50>
lea    0xeb1(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2eba(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@format_percent.result = internal global [10 x i8] zeroinitializer
@.str = [6 x i8] c" ???\00"
@.str.1 = [6 x i8] c"%4.0f\00"
@.str.2 = [6 x i8] c"%4.1f\00"
define i8* @format_percent(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fcmp olt double %3, 0.000000e+00
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load double, double* %2
%7 = fcmp oge double %6, 1.000000e+04
br i1 %7, label %8, label %10
8: ; preds = %5, %1
%9 = call i32 @strcpy(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %20
10: ; preds = %5
%11 = load double, double* %2
%12 = fcmp ogt double %11, 0x4058FF5C28F5C28F
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load double, double* %2
%15 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %14)
br label %19
16: ; preds = %10
%17 = load double, double* %2
%18 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19, %8
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0)
}

LLVM IR (-O2):
@format_percent.result = internal global [10 x i8] zeroinitializer
@.str = [6 x i8] c" ???\00"
@.str.1 = [6 x i8] c"%4.0f\00"
@.str.2 = [6 x i8] c"%4.1f\00"
define i8* @format_percent(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fcmp oge double %0, 1.000000e+04
%4 = or i1 %2, %3
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @strcpy(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %13
7: ; preds = %1
%8 = fcmp ogt double %0, 0x4058FF5C28F5C28F
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %0)
br label %13
11: ; preds = %7
%12 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %0)
br label %13
13: ; preds = %9, %11, %5
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @format_percent.result, i64 0, i64 0)
}