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

/* Variables and functions */
long strtol(char const *, char **, int);
int parseInt32(const char *s, int32_t *x) {
  char *end;
  long lval = strtol(s, &end, 10);
  if (end == s || (*end != '\0' && *end != ',')) {
    return -1;
  }
  *x = (int32_t)lval;
  return 0;
}


x86 assembly (clang, -O0):
<parseInt32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1164 <parseInt32+0x54>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1170 <parseInt32+0x60>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1170 <parseInt32+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1182 <parseInt32+0x72>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseInt32>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    (%rsp),%rdx
mov    $0xffffffff,%eax
cmp    %rbx,%rdx
je     1148 <parseInt32+0x38>
mov    (%rdx),%dl
cmp    $0x2c,%dl
je     1143 <parseInt32+0x33>
test   %dl,%dl
jne    1148 <parseInt32+0x38>
mov    %rcx,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @parseInt32(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %6, i32 10)
store i64 %9, i64* %7
%10 = load i8*, i8** %6
%11 = load i8*, i8** %4
%12 = icmp eq i8* %10, %11
br i1 %12, label %23, label %13
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 44
br i1 %22, label %23, label %24
23: ; preds = %18, %2
store i32 -1, i32* %3
br label %27
24: ; preds = %18, %13
%25 = load i64, i64* %7
%26 = load i64*, i64** %5
store i64 %25, i64* %26
store i32 0, i32* %3
br label %27
27: ; preds = %24, %23
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @parseInt32(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8, i8* %6
switch i8 %9, label %11 [
i8 0, label %10
i8 44, label %10
]
10: ; preds = %8, %8
store i64 %5, i64* %1
br label %11
11: ; preds = %2, %8, %10
%12 = phi i32 [ 0, %10 ], [ -1, %8 ], [ -1, %2 ]
ret i32 %12
}