#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__ errno;
int /*<<< orphan*/ prerror(char *, char const *);
int strtol(char const *, int /*<<< orphan*/ *, int);
int parse_int(const char *str, int *value, const char *param) {
  int v;
  errno = 0;
  v = strtol(str, NULL, 10);
  if (errno)
    goto error;
  *value = v;
  return 0;
error:
  if (param) {
    prerror("%s value parsing error. Format: 1234\n", param);
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2ea5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e82(%rip),%rax
cmpq   $0x0,(%rax)
je     116d <parse_int+0x4d>
jmp    1182 <parse_int+0x62>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11a4 <parse_int+0x84>
cmpq   $0x0,-0x20(%rbp)
je     119d <parse_int+0x7d>
mov    -0x20(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1040 <prerror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    0x2eab(%rip),%r12
movq   $0x0,(%r12)
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
cmpq   $0x0,(%r12)
je     116d <parse_int+0x4d>
mov    $0xffffffff,%ebx
test   %r14,%r14
je     1170 <parse_int+0x50>
lea    0xe9d(%rip),%rdi
mov    %r14,%rsi
call   1040 <prerror@plt>
jmp    1170 <parse_int+0x50>
mov    %eax,(%r15)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [38 x i8] c"%s value parsing error. Format: 1234\0A\00"
define i32 @parse_int(i8* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i64 0, i64* @errno
%9 = load i8*, i8** %5
%10 = call i32 @strtol(i8* %9, i32* null, i32 10)
store i32 %10, i32* %8
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
br label %17
14: ; preds = %3
%15 = load i32, i32* %8
%16 = load i32*, i32** %6
store i32 %15, i32* %16
store i32 0, i32* %4
br label %24
17: ; preds = %13
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %7
%22 = call i32 @prerror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %17
store i32 -1, i32* %4
br label %24
24: ; preds = %23, %14
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [38 x i8] c"%s value parsing error. Format: 1234\0A\00"
define i32 @parse_int(i8* nocapture %0, i32* nocapture writeonly %1, i8* %2) {
store i64 0, i64* @errno
%4 = tail call i32 @strtol(i8* nocapture %0, i32* null, i32 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %3
store i32 %4, i32* %1
br label %12
8: ; preds = %3
%9 = icmp eq i8* %2, null
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 @prerror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %12
12: ; preds = %8, %10, %7
%13 = phi i32 [ 0, %7 ], [ -1, %10 ], [ -1, %8 ]
ret i32 %13
}