#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 */

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ errno;
unsigned long strtoul(char const *, char **, int);
int parse_heartbeat(const char *s, unsigned long *x, unsigned long *y) {
  unsigned long tmp_x, tmp_y;
  char *endptr;
  const char *nptr = s;
  if (!s) {
    errno = EINVAL;
    return -1;
  }
  errno = 0;
  tmp_x = strtoul(nptr, &endptr, 10);
  if (errno != 0) {
    errno = EINVAL;
    return -1;
  }
  if (tmp_x < 0) {
    errno = EINVAL;
    return -1;
  }
  if (endptr == nptr) {
    errno = EINVAL;
    return -1;
  }
  if (*endptr != ',') {
    errno = EINVAL;
    return -1;
  }
  nptr = endptr;
  nptr++;
  errno = 0;
  tmp_y = strtoul(nptr, &endptr, 10);
  if (errno != 0) {
    errno = EINVAL;
    return -1;
  }
  if (tmp_y < 0) {
    errno = EINVAL;
    return -1;
  }
  if (endptr == nptr) {
    errno = EINVAL;
    return -1;
  }
  *x = tmp_x;
  *y = tmp_y;
  return 0;
}


x86 assembly (clang, -O0):
<parse_heartbeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <parse_heartbeat+0x47>
mov    0x2e9a(%rip),%rax
mov    (%rax),%rcx
mov    0x2e98(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
mov    0x2e82(%rip),%rax
movq   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e5e(%rip),%rax
cmpq   $0x0,(%rax)
je     11ac <parse_heartbeat+0x9c>
mov    0x2e45(%rip),%rax
mov    (%rax),%rcx
mov    0x2e43(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
cmpq   $0x0,-0x28(%rbp)
jae    11d7 <parse_heartbeat+0xc7>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rcx
mov    0x2e18(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    1205 <parse_heartbeat+0xf5>
mov    0x2dec(%rip),%rax
mov    (%rax),%rcx
mov    0x2dea(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1235 <parse_heartbeat+0x125>
mov    0x2dbc(%rip),%rax
mov    (%rax),%rcx
mov    0x2dba(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    0x2d90(%rip),%rax
movq   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d6c(%rip),%rax
cmpq   $0x0,(%rax)
je     129e <parse_heartbeat+0x18e>
mov    0x2d53(%rip),%rax
mov    (%rax),%rcx
mov    0x2d51(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
cmpq   $0x0,-0x30(%rbp)
jae    12c9 <parse_heartbeat+0x1b9>
mov    0x2d28(%rip),%rax
mov    (%rax),%rcx
mov    0x2d26(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    12f7 <parse_heartbeat+0x1e7>
mov    0x2cfa(%rip),%rax
mov    (%rax),%rcx
mov    0x2cf8(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <parse_heartbeat+0x204>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_heartbeat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     115c <parse_heartbeat+0x4c>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2eb0(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
cmpq   $0x0,0x0(%rbp)
je     1184 <parse_heartbeat+0x74>
mov    0x2e85(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x0(%rbp)
jmp    1170 <parse_heartbeat+0x60>
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%r13
cmp    %rbx,%r13
je     114c <parse_heartbeat+0x3c>
cmpb   $0x2c,0x0(%r13)
jne    114c <parse_heartbeat+0x3c>
mov    %rax,%r15
add    $0x1,%r13
movq   $0x0,0x0(%rbp)
mov    %rsp,%rsi
mov    %r13,%rdi
mov    $0xa,%edx
call   1030 <strtoul@plt>
cmpq   $0x0,0x0(%rbp)
jne    114c <parse_heartbeat+0x3c>
cmp    %r13,(%rsp)
je     114c <parse_heartbeat+0x3c>
mov    %r15,(%r12)
mov    %rax,(%r14)
xor    %eax,%eax
jmp    1175 <parse_heartbeat+0x65>

LLVM IR (-O0):
@EINVAL = global i64 0
@errno = global i64 0
define i32 @parse_heartbeat(i8* %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%12 = load i8*, i8** %5
store i8* %12, i8** %11
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = load i64, i64* @EINVAL
store i64 %16, i64* @errno
store i32 -1, i32* %4
br label %68
17: ; preds = %3
store i64 0, i64* @errno
%18 = load i8*, i8** %11
%19 = call i64 @strtoul(i8* %18, i8** %10, i32 10)
store i64 %19, i64* %8
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i64, i64* @EINVAL
store i64 %23, i64* @errno
store i32 -1, i32* %4
br label %68
24: ; preds = %17
%25 = load i64, i64* %8
%26 = icmp ult i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i64, i64* @EINVAL
store i64 %28, i64* @errno
store i32 -1, i32* %4
br label %68
29: ; preds = %24
%30 = load i8*, i8** %10
%31 = load i8*, i8** %11
%32 = icmp eq i8* %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = load i64, i64* @EINVAL
store i64 %34, i64* @errno
store i32 -1, i32* %4
br label %68
35: ; preds = %29
%36 = load i8*, i8** %10
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 44
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = load i64, i64* @EINVAL
store i64 %41, i64* @errno
store i32 -1, i32* %4
br label %68
42: ; preds = %35
%43 = load i8*, i8** %10
store i8* %43, i8** %11
%44 = load i8*, i8** %11
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %11
store i64 0, i64* @errno
%46 = load i8*, i8** %11
%47 = call i64 @strtoul(i8* %46, i8** %10, i32 10)
store i64 %47, i64* %9
%48 = load i64, i64* @errno
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %42
%51 = load i64, i64* @EINVAL
store i64 %51, i64* @errno
store i32 -1, i32* %4
br label %68
52: ; preds = %42
%53 = load i64, i64* %9
%54 = icmp ult i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = load i64, i64* @EINVAL
store i64 %56, i64* @errno
store i32 -1, i32* %4
br label %68
57: ; preds = %52
%58 = load i8*, i8** %10
%59 = load i8*, i8** %11
%60 = icmp eq i8* %58, %59
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = load i64, i64* @EINVAL
store i64 %62, i64* @errno
store i32 -1, i32* %4
br label %68
63: ; preds = %57
%64 = load i64, i64* %8
%65 = load i64*, i64** %6
store i64 %64, i64* %65
%66 = load i64, i64* %9
%67 = load i64*, i64** %7
store i64 %66, i64* %67
store i32 0, i32* %4
br label %68
68: ; preds = %63, %61, %55, %50, %40, %33, %27, %22, %15
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
@EINVAL = global i64 0
@errno = global i64 0
define i32 @parse_heartbeat(i8* %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8* %0, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = load i64, i64* @EINVAL
store i64 %8, i64* @errno
br label %38
9: ; preds = %3
store i64 0, i64* @errno
%10 = call i64 @strtoul(i8* %0, i8** %4, i32 10)
%11 = load i64, i64* @errno
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = load i64, i64* @EINVAL
store i64 %14, i64* @errno
br label %38
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, %0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i64, i64* @EINVAL
store i64 %19, i64* @errno
br label %38
20: ; preds = %15
%21 = load i8, i8* %16
%22 = icmp eq i8 %21, 44
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = load i64, i64* @EINVAL
store i64 %24, i64* @errno
br label %38
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %16, i64 1
store i64 0, i64* @errno
%27 = call i64 @strtoul(i8* %26, i8** %4, i32 10)
%28 = load i64, i64* @errno
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = load i64, i64* @EINVAL
store i64 %31, i64* @errno
br label %38
32: ; preds = %25
%33 = load i8*, i8** %4
%34 = icmp eq i8* %33, %26
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = load i64, i64* @EINVAL
store i64 %36, i64* @errno
br label %38
37: ; preds = %32
store i64 %10, i64* %1
store i64 %27, i64* %2
br label %38
38: ; preds = %37, %35, %30, %23, %18, %13, %7
%39 = phi i32 [ -1, %13 ], [ -1, %18 ], [ -1, %23 ], [ -1, %30 ], [ -1, %35 ], [ 0, %37 ], [ -1, %7 ]
ret i32 %39
}