#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 *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *prec_to_RRR(char *target, double r) {
  if (r == 0.0) {
    strcpy(target, "000");
  } else if (r > -0.11 && r < -0.09) {
    strcpy(target, "990");
  } else if (r < 0.95) {
    sprintf(target, "99%d", (int)(r * 10.0 + 0.5));
  } else if (r >= 989.0) {
    strcpy(target, "989");
  } else {
    sprintf(target, "%03d", (int)(r + 0.5));
  }
  return target;
}


x86 assembly (clang, -O0):
<prec_to_RRR>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115e <prec_to_RRR+0x3e>
jp     115e <prec_to_RRR+0x3e>
mov    -0x8(%rbp),%rdi
lea    0xedc(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1242 <prec_to_RRR+0x122>
movsd  -0x10(%rbp),%xmm0
movsd  0xe95(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119d <prec_to_RRR+0x7d>
movsd  0xe8b(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    119d <prec_to_RRR+0x7d>
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1030 <strcpy@plt>
jmp    123d <prec_to_RRR+0x11d>
movsd  0xe6b(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11e6 <prec_to_RRR+0xc6>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe53(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe5c(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1238 <prec_to_RRR+0x118>
movsd  -0x10(%rbp),%xmm0
movsd  0xe25(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1212 <prec_to_RRR+0xf2>
mov    -0x8(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1233 <prec_to_RRR+0x113>
mov    -0x8(%rbp),%rdi
movsd  0xe02(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe13(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1238 <prec_to_RRR+0x118>
jmp    123d <prec_to_RRR+0x11d>
jmp    1242 <prec_to_RRR+0x122>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prec_to_RRR>:
push   %rbx
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1139 <prec_to_RRR+0x19>
jp     1139 <prec_to_RRR+0x19>
lea    0xef9(%rip),%rsi
jmp    11b3 <prec_to_RRR+0x93>
ucomisd 0xebf(%rip),%xmm0
jbe    115a <prec_to_RRR+0x3a>
movsd  0xebd(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    115a <prec_to_RRR+0x3a>
lea    0xedc(%rip),%rsi
jmp    11b3 <prec_to_RRR+0x93>
movsd  0xeae(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1185 <prec_to_RRR+0x65>
mulsd  0xeb8(%rip),%xmm0
addsd  0xea8(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xeb5(%rip),%rsi
jmp    11a2 <prec_to_RRR+0x82>
ucomisd 0xe8b(%rip),%xmm0
jae    11ac <prec_to_RRR+0x8c>
addsd  0xe89(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
jmp    11bb <prec_to_RRR+0x9b>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"000\00"
@.str.1 = [4 x i8] c"990\00"
@.str.2 = [5 x i8] c"99%d\00"
@.str.3 = [4 x i8] c"989\00"
@.str.4 = [5 x i8] c"%03d\00"
define i8* @prec_to_RRR(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
store i8* %0, i8** %3
store double %1, double* %4
%5 = load double, double* %4
%6 = fcmp oeq double %5, 0.000000e+00
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %43
10: ; preds = %2
%11 = load double, double* %4
%12 = fcmp ogt double %11, -1.100000e-01
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load double, double* %4
%15 = fcmp olt double %14, 0xBFB70A3D70A3D70A
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %42
19: ; preds = %13, %10
%20 = load double, double* %4
%21 = fcmp olt double %20, 0x3FEE666666666666
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load double, double* %4
%25 = call double @llvm.fmuladd.f64(double %24, double 1.000000e+01, double 5.000000e-01)
%26 = fptosi double %25 to i32
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %41
28: ; preds = %19
%29 = load double, double* %4
%30 = fcmp oge double %29, 9.890000e+02
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %40
34: ; preds = %28
%35 = load i8*, i8** %3
%36 = load double, double* %4
%37 = fadd double %36, 5.000000e-01
%38 = fptosi double %37 to i32
%39 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %34, %31
br label %41
41: ; preds = %40, %22
br label %42
42: ; preds = %41, %16
br label %43
43: ; preds = %42, %7
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@.str = [4 x i8] c"000\00"
@.str.1 = [4 x i8] c"990\00"
@.str.2 = [5 x i8] c"99%d\00"
@.str.3 = [4 x i8] c"989\00"
@.str.4 = [5 x i8] c"%03d\00"
define i8* @prec_to_RRR(i8* returned %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %26
6: ; preds = %2
%7 = fcmp ogt double %1, -1.100000e-01
%8 = fcmp olt double %1, 0xBFB70A3D70A3D70A
%9 = and i1 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %26
12: ; preds = %6
%13 = fcmp olt double %1, 0x3FEE666666666666
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = tail call double @llvm.fmuladd.f64(double %1, double 1.000000e+01, double 5.000000e-01)
%16 = fptosi double %15 to i32
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %26
18: ; preds = %12
%19 = fcmp ult double %1, 9.890000e+02
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %26
22: ; preds = %18
%23 = fadd double %1, 5.000000e-01
%24 = fptosi double %23 to i32
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %10, %20, %22, %14, %4
ret i8* %0
}