#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 *, ...);
char *total_snow_depth_to_sss(char *target, double r) {
  int i;
  if (r >= 0.0)
    i = (int)(r * 100.0 + 0.5);
  else
    i = (int)(r * 100.0 - 0.5);
  if (i > 0 && i <= 996) {
    sprintf(target, "%03d", i);
  } else if (i == -1) {
    sprintf(target, "997");
  } else if (i == -2) {
    sprintf(target, "998");
  } else {
    sprintf(target, "999");
  }
  return target;
}


x86 assembly (clang, -O0):
<total_snow_depth_to_sss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     115c <total_snow_depth_to_sss+0x4c>
movsd  -0x10(%rbp),%xmm0
movsd  0xec0(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xec4(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <total_snow_depth_to_sss+0x70>
movsd  -0x10(%rbp),%xmm0
movsd  0xe97(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe93(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b1 <total_snow_depth_to_sss+0xa1>
cmpl   $0x3e4,-0x14(%rbp)
jg     11b1 <total_snow_depth_to_sss+0xa1>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    120f <total_snow_depth_to_sss+0xff>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d2 <total_snow_depth_to_sss+0xc2>
mov    -0x8(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    120a <total_snow_depth_to_sss+0xfa>
cmpl   $0xfffffffe,-0x14(%rbp)
jne    11f3 <total_snow_depth_to_sss+0xe3>
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1205 <total_snow_depth_to_sss+0xf5>
mov    -0x8(%rbp),%rdi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    120a <total_snow_depth_to_sss+0xfa>
jmp    120f <total_snow_depth_to_sss+0xff>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<total_snow_depth_to_sss>:
push   %rbx
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mulsd  0xeda(%rip),%xmm0
setb   %al
lea    0xed8(%rip),%rcx
addsd  (%rcx,%rax,8),%xmm0
cvttsd2si %xmm0,%edx
lea    -0x1(%rdx),%eax
cmp    $0x3e3,%eax
ja     1156 <total_snow_depth_to_sss+0x46>
lea    0xece(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    1176 <total_snow_depth_to_sss+0x66>
cmp    $0xfffffffe,%edx
je     1168 <total_snow_depth_to_sss+0x58>
cmp    $0xffffffff,%edx
jne    1170 <total_snow_depth_to_sss+0x60>
movl   $0x373939,(%rbx)
jmp    1176 <total_snow_depth_to_sss+0x66>
movl   $0x383939,(%rbx)
jmp    1176 <total_snow_depth_to_sss+0x66>
movl   $0x393939,(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%03d\00"
define i8* @total_snow_depth_to_sss(i8* returned writeonly %0, double %1) {
%3 = fcmp ult double %1, 0.000000e+00
%4 = tail call double @llvm.fmuladd.f64(double %1, double 1.000000e+02, double 5.000000e-01)
%5 = tail call double @llvm.fmuladd.f64(double %1, double 1.000000e+02, double -5.000000e-01)
%6 = select i1 %3, double %5, double %4
%7 = fptosi double %6 to i32
%8 = add i32 %7, -1
%9 = icmp ult i32 %8, 996
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %19
12: ; preds = %2
switch i32 %7, label %17 [
i32 -1, label %13
i32 -2, label %15
]
13: ; preds = %12
%14 = bitcast i8* %0 to i32*
store i32 3619129, i32* %14
br label %19
15: ; preds = %12
%16 = bitcast i8* %0 to i32*
store i32 3684665, i32* %16
br label %19
17: ; preds = %12
%18 = bitcast i8* %0 to i32*
store i32 3750201, i32* %18
br label %19
19: ; preds = %13, %17, %15, %10
ret i8* %0
}