#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 */
int /*<<< orphan*/ assert(int *);
long strtol(char const *, char **, int);
char *lace_parse_int(int *ret, const char *in) {
  long v;
  char *out = NULL;
  assert(ret);
  if (!in) {
    return NULL;
  }
  v = strtol(in, &out, 10);
  if (out == in)
    out = NULL;
  if (out) {
    *ret = (int)v;
    if (*ret != v)
      out = NULL;
  }
  return out;
}


x86 assembly (clang, -O0):
<lace_parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1159 <lace_parse_int+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <lace_parse_int+0xa2>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1185 <lace_parse_int+0x65>
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ba <lace_parse_int+0x9a>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
cmp    -0x20(%rbp),%rax
je     11b5 <lace_parse_int+0x95>
movq   $0x0,-0x28(%rbp)
jmp    11ba <lace_parse_int+0x9a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lace_parse_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,(%rsp)
call   1030 <assert@plt>
test   %rbx,%rbx
je     1170 <lace_parse_int+0x50>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    (%rsp),%rdx
xor    %eax,%eax
cmp    %rbx,%rdx
je     1172 <lace_parse_int+0x52>
test   %rdx,%rdx
je     1172 <lace_parse_int+0x52>
mov    %ecx,(%r14)
movslq %ecx,%rsi
xor    %eax,%eax
cmp    %rcx,%rsi
cmove  %rdx,%rax
jmp    1172 <lace_parse_int+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @lace_parse_int(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = tail call i32 @assert(i32* %0)
%6 = icmp eq i8* %1, null
br i1 %6, label %18, label %7
7: ; preds = %2
%8 = call i64 @strtol(i8* %1, i8** %3, i32 10)
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, %1
%11 = icmp eq i8* %9, null
%12 = or i1 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %7
%14 = trunc i64 %8 to i32
store i32 %14, i32* %0
%15 = add i64 %8, 2147483648
%16 = icmp ult i64 %15, 4294967296
%17 = select i1 %16, i8* %9, i8* null
br label %18
18: ; preds = %13, %7, %2
%19 = phi i8* [ null, %2 ], [ null, %7 ], [ %17, %13 ]
ret i8* %19
}