#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;
typedef int int32_t;

/* Variables and functions */
void resampler_float_to_s32(int32_t *restrict out, const float *restrict in,
                            size_t samples) {
  for (int i = 0; i < (int)samples; i++) {
    int64_t temp = in[i] + 0.5;
    if (temp > 0x7FFFFFFE)
      out[i] = 0x7FFFFFFE;
    else if (temp < -0x7FFFFFFF)
      out[i] = -0x7FFFFFFF;
    else
      out[i] = (int32_t)temp;
  }
}


x86 assembly (clang, -O0):
<resampler_float_to_s32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jge    11b2 <resampler_float_to_s32+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xec1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x7ffffffe,-0x20(%rbp)
jle    116b <resampler_float_to_s32+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x7ffffffe,(%rax,%rcx,4)
jmp    119f <resampler_float_to_s32+0x9f>
cmpl   $0x80000001,-0x20(%rbp)
jge    118c <resampler_float_to_s32+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x80000001,(%rax,%rcx,4)
jmp    119a <resampler_float_to_s32+0x9a>
mov    -0x20(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    119f <resampler_float_to_s32+0x9f>
jmp    11a4 <resampler_float_to_s32+0xa4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <resampler_float_to_s32+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<resampler_float_to_s32>:
test   %edx,%edx
jle    11f6 <resampler_float_to_s32+0xf6>
mov    %edx,%r8d
and    $0x1,%edx
cmp    $0x1,%r8
jne    1156 <resampler_float_to_s32+0x56>
xor    %eax,%eax
test   %rdx,%rdx
je     11f6 <resampler_float_to_s32+0xf6>
movss  (%rsi,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xed0(%rip),%xmm0
cvttsd2si %xmm0,%ecx
cmp    $0x7fffffff,%ecx
je     11ee <resampler_float_to_s32+0xee>
cmp    $0x80000000,%ecx
jne    11f3 <resampler_float_to_s32+0xf3>
mov    $0x80000001,%ecx
jmp    11f3 <resampler_float_to_s32+0xf3>
sub    %rdx,%r8
xor    %eax,%eax
movsd  0xe9d(%rip),%xmm0
jmp    1184 <resampler_float_to_s32+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x80000001,%r9d
mov    %r9d,0x4(%rdi,%rax,4)
add    $0x2,%rax
cmp    %rax,%r8
je     1116 <resampler_float_to_s32+0x16>
movss  (%rsi,%rax,4),%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%ecx
mov    $0x7ffffffe,%r9d
mov    $0x7ffffffe,%r10d
cmp    $0x7fffffff,%ecx
je     11c3 <resampler_float_to_s32+0xc3>
cmp    $0x80000000,%ecx
jne    11c0 <resampler_float_to_s32+0xc0>
mov    $0x80000001,%r10d
jmp    11c3 <resampler_float_to_s32+0xc3>
nopl   0x0(%rax)
mov    %ecx,%r10d
mov    %r10d,(%rdi,%rax,4)
movss  0x4(%rsi,%rax,4),%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%ecx
cmp    $0x7fffffff,%ecx
je     1176 <resampler_float_to_s32+0x76>
cmp    $0x80000000,%ecx
je     1170 <resampler_float_to_s32+0x70>
mov    %ecx,%r9d
jmp    1176 <resampler_float_to_s32+0x76>
mov    $0x7ffffffe,%ecx
mov    %ecx,(%rdi,%rax,4)
ret

LLVM IR (-O0):
define void @resampler_float_to_s32(i32* noalias %0, float* noalias %1, i64 %2) {
%4 = alloca i32*
%5 = alloca float*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store float* %1, float** %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %9
9: ; preds = %46, %3
%10 = load i32, i32* %7
%11 = load i64, i64* %6
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %49
14: ; preds = %9
%15 = load float*, float** %5
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds float, float* %15, i64 %17
%19 = load float, float* %18
%20 = fpext float %19 to double
%21 = fadd double %20, 5.000000e-01
%22 = fptosi double %21 to i32
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp sgt i32 %23, 2147483646
br i1 %24, label %25, label %30
25: ; preds = %14
%26 = load i32*, i32** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 2147483646, i32* %29
br label %45
30: ; preds = %14
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, -2147483647
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32*, i32** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 -2147483647, i32* %37
br label %44
38: ; preds = %30
%39 = load i32, i32* %8
%40 = load i32*, i32** %4
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
br label %44
44: ; preds = %38, %33
br label %45
45: ; preds = %44, %25
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %9
49: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @resampler_float_to_s32(i32* noalias nocapture writeonly %0, float* noalias nocapture %1, i64 %2) {
%4 = trunc i64 %2 to i32
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %26
6: ; preds = %3
%7 = and i64 %2, 4294967295
%8 = and i64 %2, 1
%9 = icmp eq i64 %7, 1
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = sub nsw i64 %7, %8
br label %27
12: ; preds = %48, %6
%13 = phi i64 [ 0, %6 ], [ %51, %48 ]
%14 = icmp eq i64 %8, 0
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = getelementptr inbounds float, float* %1, i64 %13
%17 = load float, float* %16
%18 = fpext float %17 to double
%19 = fadd double %18, 5.000000e-01
%20 = fptosi double %19 to i32
switch i32 %20, label %22 [
i32 2147483647, label %23
i32 -2147483648, label %21
]
21: ; preds = %15
br label %23
22: ; preds = %15
br label %23
23: ; preds = %22, %21, %15
%24 = phi i32 [ -2147483647, %21 ], [ %20, %22 ], [ 2147483646, %15 ]
%25 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %24, i32* %25
br label %26
26: ; preds = %23, %12, %3
ret void
27: ; preds = %48, %10
%28 = phi i64 [ 0, %10 ], [ %51, %48 ]
%29 = phi i64 [ 0, %10 ], [ %52, %48 ]
%30 = getelementptr inbounds float, float* %1, i64 %28
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = fadd double %32, 5.000000e-01
%34 = fptosi double %33 to i32
switch i32 %34, label %36 [
i32 2147483647, label %37
i32 -2147483648, label %35
]
35: ; preds = %27
br label %37
36: ; preds = %27
br label %37
37: ; preds = %27, %35, %36
%38 = phi i32 [ -2147483647, %35 ], [ %34, %36 ], [ 2147483646, %27 ]
%39 = getelementptr inbounds i32, i32* %0, i64 %28
store i32 %38, i32* %39
%40 = or i64 %28, 1
%41 = getelementptr inbounds float, float* %1, i64 %40
%42 = load float, float* %41
%43 = fpext float %42 to double
%44 = fadd double %43, 5.000000e-01
%45 = fptosi double %44 to i32
switch i32 %45, label %47 [
i32 2147483647, label %48
i32 -2147483648, label %46
]
46: ; preds = %37
br label %48
47: ; preds = %37
br label %48
48: ; preds = %47, %46, %37
%49 = phi i32 [ -2147483647, %46 ], [ %45, %47 ], [ 2147483646, %37 ]
%50 = getelementptr inbounds i32, i32* %0, i64 %40
store i32 %49, i32* %50
%51 = add nuw nsw i64 %28, 2
%52 = add i64 %29, 2
%53 = icmp eq i64 %52, %11
br i1 %53, label %12, label %27
}