#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 */
void _set_uchar(char *data, size_t pos, double value) {
  unsigned char *buf = (unsigned char *)data;
  buf[pos] = (unsigned char)((((value + 0.5) > 0.0
                                   ? (int)(value + 0.5)
                                   : (((int)(value + 0.5) - value + 0.5) != 0.0
                                          ? (int)(value + 0.5) - 1
                                          : (int)(value + 0.5)))));
  return;
}


x86 assembly (clang, -O0):
<_set_uchar>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movsd  0xedf(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    114c <_set_uchar+0x4c>
movsd  0xec5(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
jmp    11c0 <_set_uchar+0xc0>
movsd  0xeac(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118a <_set_uchar+0x8a>
jp     118a <_set_uchar+0x8a>
jmp    11a6 <_set_uchar+0xa6>
movsd  0xe6e(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ba <_set_uchar+0xba>
movsd  0xe52(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<_set_uchar>:
movsd  0xef8(%rip),%xmm2
addsd  %xmm0,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
cvttsd2si %xmm2,%eax
ja     1138 <_set_uchar+0x38>
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
subsd  %xmm0,%xmm2
addsd  0xed3(%rip),%xmm2
ucomisd %xmm1,%xmm2
jne    1135 <_set_uchar+0x35>
jnp    1138 <_set_uchar+0x38>
add    $0xffffffff,%eax
mov    %al,(%rdi,%rsi,1)
ret

LLVM IR (-O0):
define void @_set_uchar(i8* %0, i64 %1, double %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca double
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store double %2, double* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load double, double* %6
%10 = fadd double %9, 5.000000e-01
%11 = fcmp ogt double %10, 0.000000e+00
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load double, double* %6
%14 = fadd double %13, 5.000000e-01
%15 = fptosi double %14 to i32
br label %36
16: ; preds = %3
%17 = load double, double* %6
%18 = fadd double %17, 5.000000e-01
%19 = fptosi double %18 to i32
%20 = sitofp i32 %19 to double
%21 = load double, double* %6
%22 = fsub double %20, %21
%23 = fadd double %22, 5.000000e-01
%24 = fcmp une double %23, 0.000000e+00
br i1 %24, label %25, label %30
25: ; preds = %16
%26 = load double, double* %6
%27 = fadd double %26, 5.000000e-01
%28 = fptosi double %27 to i32
%29 = sub nsw i32 %28, 1
br label %34
30: ; preds = %16
%31 = load double, double* %6
%32 = fadd double %31, 5.000000e-01
%33 = fptosi double %32 to i32
br label %34
34: ; preds = %30, %25
%35 = phi i32 [ %29, %25 ], [ %33, %30 ]
br label %36
36: ; preds = %34, %12
%37 = phi i32 [ %15, %12 ], [ %35, %34 ]
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %7
%40 = load i64, i64* %5
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 %38, i8* %41
ret void
}

LLVM IR (-O2):
define void @_set_uchar(i8* nocapture writeonly %0, i64 %1, double %2) {
%4 = fadd double %2, 5.000000e-01
%5 = fcmp ogt double %4, 0.000000e+00
%6 = fptosi double %4 to i32
br i1 %5, label %14, label %7
7: ; preds = %3
%8 = sitofp i32 %6 to double
%9 = fsub double %8, %2
%10 = fadd double %9, 5.000000e-01
%11 = fcmp une double %10, 0.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = add nsw i32 %6, -1
br label %14
14: ; preds = %3, %7, %12
%15 = phi i32 [ %13, %12 ], [ %6, %7 ], [ %6, %3 ]
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %0, i64 %1
store i8 %16, i8* %17
ret void
}