#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__ int64_t;

/* Variables and functions */
int a2double(char const *, double *);
int a2int64(const char *str, int64_t *pval) {
  double dval = 0.0;
  int rc = 0;
  static const int ERR_OVFLW = -2;
  if (0 != (rc = a2double(str, &dval)))
    return rc;
  if (dval > 9223372036854775807.0 || dval < (-9223372036854775807.0 - 1.0))
    return ERR_OVFLW;
  if (NULL != pval) {
    *pval = (int64_t)dval;
  }
  return rc;
}


x86 assembly (clang, -O0):
<a2int64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <a2double@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     1156 <a2int64+0x46>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <a2int64+0x9b>
movsd  -0x20(%rbp),%xmm0
movsd  0xe9d(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1180 <a2int64+0x70>
movsd  0xe93(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    118c <a2int64+0x7c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11ab <a2int64+0x9b>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     11a5 <a2int64+0x95>
cvttsd2si -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2int64>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1030 <a2double@plt>
test   %eax,%eax
je     1135 <a2int64+0x25>
add    $0x10,%rsp
pop    %rbx
ret
movsd  0x8(%rsp),%xmm0
ucomisd 0xebd(%rip),%xmm0
mov    $0xfffffffe,%eax
ja     112f <a2int64+0x1f>
movsd  0xeb6(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     112f <a2int64+0x1f>
xor    %eax,%eax
test   %rbx,%rbx
je     112f <a2int64+0x1f>
cvttsd2si %xmm0,%rcx
mov    %rcx,(%rbx)
jmp    112f <a2int64+0x1f>

LLVM IR (-O0):
@a2int64.ERR_OVFLW = internal constant i32 -2
define i32 @a2int64(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca double
%7 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %5
store double 0.000000e+00, double* %6
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i32 @a2double(i8* %8, double* %6)
store i32 %9, i32* %7
%10 = icmp ne i32 0, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %7
store i32 %12, i32* %3
br label %29
13: ; preds = %2
%14 = load double, double* %6
%15 = fcmp ogt double %14, 0x43E0000000000000
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load double, double* %6
%18 = fcmp olt double %17, 0xC3E0000000000000
br i1 %18, label %19, label %20
19: ; preds = %16, %13
store i32 -2, i32* %3
br label %29
20: ; preds = %16
%21 = load i64*, i64** %5
%22 = icmp ne i64* null, %21
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load double, double* %6
%25 = fptosi double %24 to i64
%26 = load i64*, i64** %5
store i64 %25, i64* %26
br label %27
27: ; preds = %23, %20
%28 = load i32, i32* %7
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %19, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @a2int64(i8* %0, i64* writeonly %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
store double 0.000000e+00, double* %3
%5 = call i32 @a2double(i8* %0, double* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = load double, double* %3
%9 = fcmp ogt double %8, 0x43E0000000000000
%10 = fcmp olt double %8, 0xC3E0000000000000
%11 = or i1 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = icmp eq i64* %1, null
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = fptosi double %8 to i64
store i64 %15, i64* %1
br label %16
16: ; preds = %12, %14, %7, %2
%17 = phi i32 [ %5, %2 ], [ -2, %7 ], [ 0, %14 ], [ 0, %12 ]
ret i32 %17
}