#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int /*<<< orphan*/);
int parse_int(char *opt, char *optarg, void *arg) {
  char *tmp;
  *((int *)arg) = strtol(optarg, &tmp, 0);
  if (*tmp != '\0') {
    fprintf(stderr, "set_int: cannot parse %s\n", optarg);
    return 2;
  } else {
    return 0;
  }
}


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    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1180 <parse_int+0x60>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe91(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1187 <parse_int+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1169 <parse_int+0x49>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"set_int: cannot parse %s\0A\00"
define i32 @parse_int(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = call i32 @strtol(i8* %9, i8** %8, i32 0)
%11 = load i8*, i8** %7
%12 = bitcast i8* %11 to i32*
store i32 %10, i32* %12
%13 = load i8*, i8** %8
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %6
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 2, i32* %4
br label %22
21: ; preds = %3
store i32 0, i32* %4
br label %22
22: ; preds = %21, %17
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"set_int: cannot parse %s\0A\00"
define i32 @parse_int(i8* nocapture readnone %0, i8* %1, i8* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @strtol(i8* %1, i8** %4, i32 0)
%7 = bitcast i8* %2 to i32*
store i32 %6, i32* %7
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %14
14: ; preds = %3, %11
%15 = phi i32 [ 2, %11 ], [ 0, %3 ]
ret i32 %15
}