#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_RRRR24(char *target, double r) {
  if (r < 0.0 || (r > 0.0 && r < 0.1)) {
    strcpy(target, "9999");
  } else if (r <= 999.8) {
    sprintf(target, "%04d", (int)(r * 10.0 + 0.5));
  } else {
    strcpy(target, "9998");
  }
  return target;
}


x86 assembly (clang, -O0):
<prec_to_RRRR24>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     1164 <prec_to_RRRR24+0x44>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1179 <prec_to_RRRR24+0x59>
movsd  0xea7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1179 <prec_to_RRRR24+0x59>
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d7 <prec_to_RRRR24+0xb7>
movsd  0xe87(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11c2 <prec_to_RRRR24+0xa2>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe73(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe6f(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe6d(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11d2 <prec_to_RRRR24+0xb2>
mov    -0x8(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d7 <prec_to_RRRR24+0xb7>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prec_to_RRRR24>:
push   %rbx
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1142 <prec_to_RRRR24+0x22>
ucomisd %xmm1,%xmm0
jbe    1156 <prec_to_RRRR24+0x36>
movsd  0xec4(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1156 <prec_to_RRRR24+0x36>
lea    0xed7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
ret
movsd  0xeaa(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    116d <prec_to_RRRR24+0x4d>
lea    0xebf(%rip),%rsi
jmp    1149 <prec_to_RRRR24+0x29>
mulsd  0xe9b(%rip),%xmm0
addsd  0xe9b(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
jmp    1151 <prec_to_RRRR24+0x31>

LLVM IR (-O0):
@.str = [5 x i8] c"9999\00"
@.str.1 = [5 x i8] c"%04d\00"
@.str.2 = [5 x i8] c"9998\00"
define i8* @prec_to_RRRR24(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 olt double %5, 0.000000e+00
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = load double, double* %4
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load double, double* %4
%12 = fcmp olt double %11, 1.000000e-01
br i1 %12, label %13, label %16
13: ; preds = %10, %2
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %29
16: ; preds = %10, %7
%17 = load double, double* %4
%18 = fcmp ole double %17, 0x408F3E6666666666
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load double, double* %4
%22 = call double @llvm.fmuladd.f64(double %21, double 1.000000e+01, double 5.000000e-01)
%23 = fptosi double %22 to i32
%24 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %28
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %19
br label %29
29: ; preds = %28, %13
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"9999\00"
@.str.1 = [5 x i8] c"%04d\00"
@.str.2 = [5 x i8] c"9998\00"
define i8* @prec_to_RRRR24(i8* returned %0, double %1) {
%3 = fcmp olt double %1, 0.000000e+00
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = fcmp ogt double %1, 0.000000e+00
%6 = fcmp olt double %1, 1.000000e-01
%7 = and i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %4, %2
%9 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %18
10: ; preds = %4
%11 = fcmp ugt double %1, 0x408F3E6666666666
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = tail call double @llvm.fmuladd.f64(double %1, double 1.000000e+01, double 5.000000e-01)
%14 = fptosi double %13 to i32
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %18
16: ; preds = %10
%17 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %12, %16, %8
ret i8* %0
}