#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 scalar_t__ int32_t;

/* Variables and functions */
int32_t conv_dbl_to_int(int32_t *dst, const double *src, int32_t num) {
  int32_t i;
  for (i = 0; i < num; i++) {
    double tmp = *src++;
    *dst++ = (int)(tmp > 0) ? tmp + 0.5 : tmp - 0.5;
  }
  return num;
}


x86 assembly (clang, -O0):
<conv_dbl_to_int>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11aa <conv_dbl_to_int+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1167 <conv_dbl_to_int+0x67>
movsd  0xea8(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    117d <conv_dbl_to_int+0x7d>
movsd  -0x28(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%rcx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x8(%rbp)
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1118 <conv_dbl_to_int+0x18>
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<conv_dbl_to_int>:
mov    %rdx,%rax
test   %rdx,%rdx
jle    11d4 <conv_dbl_to_int+0xd4>
cmp    $0x1,%rax
je     11ab <conv_dbl_to_int+0xab>
mov    %rax,%r8
and    $0xfffffffffffffffe,%r8
xor    %r9d,%r9d
movsd  0xed8(%rip),%xmm0
movsd  0xed8(%rip),%xmm1
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rsi,%rdx,8),%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm2,%xmm3
movapd %xmm3,%xmm4
andpd  %xmm0,%xmm4
andnpd %xmm1,%xmm3
orpd   %xmm4,%xmm3
addsd  %xmm2,%xmm3
cvttsd2si %xmm3,%rcx
mov    %rcx,(%rdi,%rdx,8)
movsd  0x8(%rsi,%rdx,8),%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm2,%xmm3
movapd %xmm3,%xmm4
andpd  %xmm0,%xmm4
andnpd %xmm1,%xmm3
orpd   %xmm4,%xmm3
addsd  %xmm2,%xmm3
cvttsd2si %xmm3,%rcx
mov    %rcx,0x8(%rdi,%rdx,8)
add    $0x2,%rdx
add    $0xfffffffffffffff0,%r9
cmp    %rdx,%r8
jne    1140 <conv_dbl_to_int+0x40>
sub    %r9,%rdi
sub    %r9,%rsi
test   $0x1,%al
je     11d4 <conv_dbl_to_int+0xd4>
movsd  (%rsi),%xmm0
xorpd  %xmm1,%xmm1
xor    %ecx,%ecx
ucomisd %xmm1,%xmm0
seta   %cl
lea    0xe49(%rip),%rdx
addsd  (%rdx,%rcx,8),%xmm0
cvttsd2si %xmm0,%rcx
mov    %rcx,(%rdi)
ret

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

LLVM IR (-O2):
define i64 @conv_dbl_to_int(i64* nocapture writeonly %0, double* nocapture %1, i64 returned %2) {
%4 = icmp sgt i64 %2, 0
br i1 %4, label %5, label %40
5: ; preds = %3
%6 = and i64 %2, 1
%7 = icmp eq i64 %2, 1
br i1 %7, label %30, label %8
8: ; preds = %5
%9 = and i64 %2, -2
br label %10
10: ; preds = %10, %8
%11 = phi i64* [ %0, %8 ], [ %27, %10 ]
%12 = phi double* [ %1, %8 ], [ %21, %10 ]
%13 = phi i64 [ 0, %8 ], [ %28, %10 ]
%14 = getelementptr inbounds double, double* %12, i64 1
%15 = load double, double* %12
%16 = fcmp ogt double %15, 0.000000e+00
%17 = select i1 %16, double 5.000000e-01, double -5.000000e-01
%18 = fadd double %15, %17
%19 = fptosi double %18 to i64
%20 = getelementptr inbounds i64, i64* %11, i64 1
store i64 %19, i64* %11
%21 = getelementptr inbounds double, double* %12, i64 2
%22 = load double, double* %14
%23 = fcmp ogt double %22, 0.000000e+00
%24 = select i1 %23, double 5.000000e-01, double -5.000000e-01
%25 = fadd double %22, %24
%26 = fptosi double %25 to i64
%27 = getelementptr inbounds i64, i64* %11, i64 2
store i64 %26, i64* %20
%28 = add i64 %13, 2
%29 = icmp eq i64 %28, %9
br i1 %29, label %30, label %10
30: ; preds = %10, %5
%31 = phi i64* [ %0, %5 ], [ %27, %10 ]
%32 = phi double* [ %1, %5 ], [ %21, %10 ]
%33 = icmp eq i64 %6, 0
br i1 %33, label %40, label %34
34: ; preds = %30
%35 = load double, double* %32
%36 = fcmp ogt double %35, 0.000000e+00
%37 = select i1 %36, double 5.000000e-01, double -5.000000e-01
%38 = fadd double %35, %37
%39 = fptosi double %38 to i64
store i64 %39, i64* %31
br label %40
40: ; preds = %34, %30, %3
ret i64 %2
}