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


x86 assembly (clang, -O0):
<prec_to_RRRR>:
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_RRRR+0x44>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1179 <prec_to_RRRR+0x59>
movsd  0xea7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1179 <prec_to_RRRR+0x59>
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c7 <prec_to_RRRR+0xa7>
movsd  0xe87(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11b2 <prec_to_RRRR+0x92>
mov    -0x8(%rbp),%rdi
movsd  0xe78(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe75(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11c2 <prec_to_RRRR+0xa2>
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c7 <prec_to_RRRR+0xa7>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prec_to_RRRR>:
push   %rbx
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1142 <prec_to_RRRR+0x22>
ucomisd %xmm1,%xmm0
jbe    1156 <prec_to_RRRR+0x36>
movsd  0xec4(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1156 <prec_to_RRRR+0x36>
lea    0xecf(%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_RRRR+0x4d>
lea    0xeb7(%rip),%rsi
jmp    1149 <prec_to_RRRR+0x29>
addsd  0xe9b(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
jmp    1151 <prec_to_RRRR+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"8899\00"
define i8* @prec_to_RRRR(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, 8.899000e+03
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load double, double* %4
%22 = fadd double %21, 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"8899\00"
define i8* @prec_to_RRRR(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, 8.899000e+03
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = fadd double %1, 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
}