#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 */
typedef int int64_t;

/* Variables and functions */
float const ceilf(float const);
float const floorf(float const);
scalar_t__ roundf(float const);
scalar_t__ truncf(float const);
void round_l_s(const float *source, int64_t *dest) {
  float remainder = *source - floorf(*source);
  if (remainder == 0.5) {
    if (*source < 0) {
      *dest =
          (int64_t)truncf(*source) % 2 != 0 ? floorf(*source) : ceilf(*source);
    } else {
      *dest =
          (int64_t)truncf(*source) % 2 != 0 ? ceilf(*source) : floorf(*source);
    }
  } else {
    *dest = (int64_t)roundf(*source);
  }
}


x86 assembly (clang, -O0):
<round_l_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1030 <floorf@plt>
movaps %xmm0,%xmm1
movss  -0x18(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe74(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1262 <round_l_s+0x122>
jp     1262 <round_l_s+0x122>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
ucomiss (%rax),%xmm0
jbe    1207 <round_l_s+0xc7>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1050 <truncf@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11e1 <round_l_s+0xa1>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1030 <floorf@plt>
movss  %xmm0,-0x1c(%rbp)
jmp    11f3 <round_l_s+0xb3>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1040 <ceilf@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvttss2si %xmm0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    125d <round_l_s+0x11d>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1050 <truncf@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     123c <round_l_s+0xfc>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1040 <ceilf@plt>
movss  %xmm0,-0x20(%rbp)
jmp    124e <round_l_s+0x10e>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1030 <floorf@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvttss2si %xmm0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1277 <round_l_s+0x137>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1060 <roundf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round_l_s>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  %xmm0,0x4(%rsp)
call   1030 <floorf@plt>
movss  0x4(%rsp),%xmm1
subss  %xmm0,%xmm1
ucomiss 0xe96(%rip),%xmm1
movss  (%rbx),%xmm0
jne    1196 <round_l_s+0x56>
jp     1196 <round_l_s+0x56>
movss  %xmm0,0x4(%rsp)
call   1050 <truncf@plt>
xorps  %xmm0,%xmm0
ucomiss 0x4(%rsp),%xmm0
movss  (%rbx),%xmm0
jbe    119d <round_l_s+0x5d>
test   $0x1,%al
jne    11a1 <round_l_s+0x61>
call   1040 <ceilf@plt>
jmp    11a6 <round_l_s+0x66>
call   1060 <roundf@plt>
jmp    11aa <round_l_s+0x6a>
test   $0x1,%al
jne    118f <round_l_s+0x4f>
call   1030 <floorf@plt>
cvttss2si %xmm0,%eax
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @round_l_s(float* %0, i32* %1) {
%3 = alloca float*
%4 = alloca i32*
%5 = alloca float
store float* %0, float** %3
store i32* %1, i32** %4
%6 = load float*, float** %3
%7 = load float, float* %6
%8 = load float*, float** %3
%9 = load float, float* %8
%10 = call float @floorf(float %9)
%11 = fsub float %7, %10
store float %11, float* %5
%12 = load float, float* %5
%13 = fpext float %12 to double
%14 = fcmp oeq double %13, 5.000000e-01
br i1 %14, label %15, label %58
15: ; preds = %2
%16 = load float*, float** %3
%17 = load float, float* %16
%18 = fcmp olt float %17, 0.000000e+00
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load float*, float** %3
%21 = load float, float* %20
%22 = call i64 @truncf(float %21)
%23 = trunc i64 %22 to i32
%24 = srem i32 %23, 2
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load float*, float** %3
%28 = load float, float* %27
%29 = call float @floorf(float %28)
br label %34
30: ; preds = %19
%31 = load float*, float** %3
%32 = load float, float* %31
%33 = call float @ceilf(float %32)
br label %34
34: ; preds = %30, %26
%35 = phi float [ %29, %26 ], [ %33, %30 ]
%36 = fptosi float %35 to i32
%37 = load i32*, i32** %4
store i32 %36, i32* %37
br label %57
38: ; preds = %15
%39 = load float*, float** %3
%40 = load float, float* %39
%41 = call i64 @truncf(float %40)
%42 = trunc i64 %41 to i32
%43 = srem i32 %42, 2
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = load float*, float** %3
%47 = load float, float* %46
%48 = call float @ceilf(float %47)
br label %53
49: ; preds = %38
%50 = load float*, float** %3
%51 = load float, float* %50
%52 = call float @floorf(float %51)
br label %53
53: ; preds = %49, %45
%54 = phi float [ %48, %45 ], [ %52, %49 ]
%55 = fptosi float %54 to i32
%56 = load i32*, i32** %4
store i32 %55, i32* %56
br label %57
57: ; preds = %53, %34
br label %64
58: ; preds = %2
%59 = load float*, float** %3
%60 = load float, float* %59
%61 = call i64 @roundf(float %60)
%62 = trunc i64 %61 to i32
%63 = load i32*, i32** %4
store i32 %62, i32* %63
br label %64
64: ; preds = %58, %57
ret void
}

LLVM IR (-O2):
define void @round_l_s(float* nocapture %0, i32* nocapture writeonly %1) {
%3 = load float, float* %0
%4 = tail call float @floorf(float %3)
%5 = fsub float %3, %4
%6 = fcmp oeq float %5, 5.000000e-01
%7 = load float, float* %0
br i1 %6, label %8, label %30
8: ; preds = %2
%9 = fcmp olt float %7, 0.000000e+00
%10 = tail call i64 @truncf(float %7)
%11 = and i64 %10, 1
%12 = icmp eq i64 %11, 0
%13 = load float, float* %0
br i1 %9, label %14, label %22
14: ; preds = %8
br i1 %12, label %17, label %15
15: ; preds = %14
%16 = tail call float @floorf(float %13)
br label %19
17: ; preds = %14
%18 = tail call float @ceilf(float %13)
br label %19
19: ; preds = %17, %15
%20 = phi float [ %16, %15 ], [ %18, %17 ]
%21 = fptosi float %20 to i32
br label %33
22: ; preds = %8
br i1 %12, label %25, label %23
23: ; preds = %22
%24 = tail call float @ceilf(float %13)
br label %27
25: ; preds = %22
%26 = tail call float @floorf(float %13)
br label %27
27: ; preds = %25, %23
%28 = phi float [ %24, %23 ], [ %26, %25 ]
%29 = fptosi float %28 to i32
br label %33
30: ; preds = %2
%31 = tail call i64 @roundf(float %7)
%32 = trunc i64 %31 to i32
br label %33
33: ; preds = %19, %27, %30
%34 = phi i32 [ %21, %19 ], [ %29, %27 ], [ %32, %30 ]
store i32 %34, i32* %1
ret void
}