#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;
typedef scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ INT32_MAX;
scalar_t__ UINT32_MAX;
int read_uint64(char const **, char const *, scalar_t__ *);
int read_int32(const char **s, const char *end, uint32_t *out,
               int allow_signed) {
  uint64_t value;
  int has_sign = 0;
  if (**s == '-') {
    if (!allow_signed)
      return 0;
    has_sign = 1;
    (*s)++;
  }
  int result = read_uint64(s, end, &value);
  if (has_sign) {
    if (value > (uint64_t)INT32_MAX + 1)
      return 0;
    value = UINT32_MAX - value + 1;
  } else {
    if (value > (uint64_t)UINT32_MAX)
      return 0;
  }
  *out = (uint32_t)value;
  return result;
}


x86 assembly (clang, -O0):
<read_int32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    116c <read_int32+0x5c>
cmpl   $0x0,-0x24(%rbp)
jne    1157 <read_int32+0x47>
movl   $0x0,-0x4(%rbp)
jmp    1202 <read_int32+0xf2>
movl   $0x1,-0x34(%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,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11cc <read_int32+0xbc>
mov    -0x30(%rbp),%rax
mov    0x2e43(%rip),%rcx
mov    (%rcx),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jle    11b1 <read_int32+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    1202 <read_int32+0xf2>
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
sub    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11f1 <read_int32+0xe1>
mov    -0x30(%rbp),%rax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%rax
jle    11ec <read_int32+0xdc>
movl   $0x0,-0x4(%rbp)
jmp    1202 <read_int32+0xf2>
jmp    11f1 <read_int32+0xe1>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int32>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    (%rdi),%rax
cmpb   $0x2d,(%rax)
jne    115d <read_int32+0x4d>
xor    %ebp,%ebp
test   %ecx,%ecx
je     117c <read_int32+0x6c>
add    $0x1,%rax
mov    %rax,(%rdi)
mov    %rsp,%rdx
call   1030 <read_uint64@plt>
mov    (%rsp),%rdx
mov    0x2e9a(%rip),%rcx
mov    (%rcx),%rcx
add    $0x1,%rcx
cmp    %rcx,%rdx
jg     117c <read_int32+0x6c>
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%rcx
sub    %rdx,%rcx
add    $0x1,%rcx
jmp    1177 <read_int32+0x67>
mov    %rsp,%rdx
call   1030 <read_uint64@plt>
mov    (%rsp),%rcx
mov    0x2e88(%rip),%rdx
xor    %ebp,%ebp
cmp    (%rdx),%rcx
jg     117c <read_int32+0x6c>
mov    %eax,%ebp
mov    %rcx,(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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