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

/* Variables and functions */
scalar_t__ INT64_MAX;
scalar_t__ UINT64_MAX;
int read_uint64(char const **, char const *, scalar_t__ *);
int read_int64(const char **s, const char *end, uint64_t *out) {
  int has_sign = 0;
  if (**s == '-') {
    has_sign = 1;
    (*s)++;
  }
  uint64_t value;
  int result = read_uint64(s, end, &value);
  if (has_sign) {
    if (value > (uint64_t)INT64_MAX + 1)
      return 0;
    value = UINT64_MAX - value + 1;
  }
  *out = value;
  return result;
}


x86 assembly (clang, -O0):
<read_int64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1153 <read_int64+0x43>
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <read_uint64@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ae <read_int64+0x9e>
mov    -0x30(%rbp),%rax
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jle    1198 <read_int64+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11bf <read_int64+0xaf>
mov    0x2e31(%rip),%rax
mov    (%rax),%rax
sub    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int64>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    (%rdi),%rax
cmpb   $0x2d,(%rax)
jne    1160 <read_int64+0x50>
add    $0x1,%rax
mov    %rax,(%rdi)
lea    0x8(%rsp),%rdx
call   1030 <read_uint64@plt>
mov    0x8(%rsp),%rdx
mov    0x2eab(%rip),%rcx
mov    (%rcx),%rsi
add    $0x1,%rsi
xor    %ecx,%ecx
cmp    %rsi,%rdx
jg     1174 <read_int64+0x64>
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%rsi
sub    %rdx,%rsi
add    $0x1,%rsi
mov    %eax,%ecx
jmp    1171 <read_int64+0x61>
lea    0x8(%rsp),%rdx
call   1030 <read_uint64@plt>
mov    %eax,%ecx
mov    0x8(%rsp),%rsi
mov    %rsi,(%rbx)
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@INT64_MAX = global i64 0
@UINT64_MAX = global i64 0
define i32 @read_int64(i8** %0, i8* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
store i32 0, i32* %8
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 45
br i1 %15, label %16, label %20
16: ; preds = %3
store i32 1, i32* %8
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %17
br label %20
20: ; preds = %16, %3
%21 = load i8**, i8*** %5
%22 = load i8*, i8** %6
%23 = call i32 @read_uint64(i8** %21, i8* %22, i64* %9)
store i32 %23, i32* %10
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %20
%27 = load i64, i64* %9
%28 = load i64, i64* @INT64_MAX
%29 = add nsw i64 %28, 1
%30 = icmp sgt i64 %27, %29
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 0, i32* %4
br label %41
32: ; preds = %26
%33 = load i64, i64* @UINT64_MAX
%34 = load i64, i64* %9
%35 = sub nsw i64 %33, %34
%36 = add nsw i64 %35, 1
store i64 %36, i64* %9
br label %37
37: ; preds = %32, %20
%38 = load i64, i64* %9
%39 = load i64*, i64** %7
store i64 %38, i64* %39
%40 = load i32, i32* %10
store i32 %40, i32* %4
br label %41
41: ; preds = %37, %31
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@INT64_MAX = global i64 0
@UINT64_MAX = global i64 0
define i32 @read_int64(i8** %0, i8* %1, i64* nocapture writeonly %2) {
%4 = alloca i64
%5 = load i8*, i8** %0
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 45
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = bitcast i64* %4 to i8*
%10 = call i32 @read_uint64(i8** %0, i8* %1, i64* %4)
%11 = load i64, i64* %4
br label %24
12: ; preds = %3
%13 = getelementptr inbounds i8, i8* %5, i64 1
store i8* %13, i8** %0
%14 = bitcast i64* %4 to i8*
%15 = call i32 @read_uint64(i8** %0, i8* %1, i64* %4)
%16 = load i64, i64* %4
%17 = load i64, i64* @INT64_MAX
%18 = add nsw i64 %17, 1
%19 = icmp sgt i64 %16, %18
br i1 %19, label %27, label %20
20: ; preds = %12
%21 = load i64, i64* @UINT64_MAX
%22 = sub i64 1, %16
%23 = add i64 %22, %21
br label %24
24: ; preds = %8, %20
%25 = phi i64 [ %23, %20 ], [ %11, %8 ]
%26 = phi i32 [ %15, %20 ], [ %10, %8 ]
store i64 %25, i64* %2
br label %27
27: ; preds = %12, %24
%28 = phi i32 [ %26, %24 ], [ 0, %12 ]
%29 = bitcast i64* %4 to i8*
ret i32 %28
}