#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 EINVAL;
int errno;
long strtol(char *, char **, int);
int pop3_parse_integer(char *str, int *error) {
  char *end = NULL;
  errno = 0;
  long ret = strtol(str, &end, 10);
  *error = 0;
  if (end && *end) {
    *error = EINVAL;
    return ret;
  }
  *error = errno;
  return ret;
}


x86 assembly (clang, -O0):
<pop3_parse_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2eb1(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     118b <pop3_parse_integer+0x7b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118b <pop3_parse_integer+0x7b>
mov    0x2e61(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11a1 <pop3_parse_integer+0x91>
mov    0x2e4e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pop3_parse_integer>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movq   $0x0,(%rsp)
mov    0x2eba(%rip),%rbx
movl   $0x0,(%rbx)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
movl   $0x0,(%r14)
mov    (%rsp),%rcx
test   %rcx,%rcx
je     1155 <pop3_parse_integer+0x45>
cmpb   $0x0,(%rcx)
je     1155 <pop3_parse_integer+0x45>
mov    0x2e83(%rip),%rbx
mov    (%rbx),%ecx
mov    %ecx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
@EINVAL = global i32 0
define i32 @pop3_parse_integer(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* null, i8** %6
store i32 0, i32* @errno
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %6, i32 10)
store i64 %9, i64* %7
%10 = load i32*, i32** %5
store i32 0, i32* %10
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %23
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 %23
18: ; preds = %13
%19 = load i32, i32* @EINVAL
%20 = load i32*, i32** %5
store i32 %19, i32* %20
%21 = load i64, i64* %7
%22 = trunc i64 %21 to i32
store i32 %22, i32* %3
br label %28
23: ; preds = %13, %2
%24 = load i32, i32* @errno
%25 = load i32*, i32** %5
store i32 %24, i32* %25
%26 = load i64, i64* %7
%27 = trunc i64 %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %23, %18
%29 = load i32, i32* %3
ret i32 %29
}

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