#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ perror(char *);
int sscanf(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ stderr;
int parse_int(char option, char *arg_str, int *data) {
  int rc;
  rc = sscanf(optarg, "%d", data);
  if (rc < 0) {
    perror("Unable to parse argument");
    return rc;
  } else if (rc != 1) {
    fprintf(stderr,
            "Error: Unable to parse argument '-%c %s' as an "
            "integer.\n",
            option, arg_str);
    return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xea6(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1183 <parse_int+0x53>
lea    0xe90(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <parse_int+0x9b>
cmpl   $0x1,-0x1c(%rbp)
je     11bf <parse_int+0x8f>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rcx
lea    0xe78(%rip),%rsi
movsbl %al,%edx
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    0x2e1b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <parse_int+0x9b>
jmp    11c4 <parse_int+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2eb8(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1187 <parse_int+0x57>
xor    %eax,%eax
cmp    $0x1,%ebx
je     1182 <parse_int+0x52>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
movsbl %bpl,%edx
lea    0xead(%rip),%rsi
mov    %r14,%rcx
call   1030 <fprintf@plt>
mov    0x2e52(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%eax
jmp    1182 <parse_int+0x52>

LLVM IR (-O0):
@optarg = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [25 x i8] c"Unable to parse argument\00"
@stderr = global i32 0
@.str.2 = [57 x i8] c"Error: Unable to parse argument '-%c %s' as an integer.\0A\00"
@EINVAL = global i32 0
define i32 @parse_int(i8 signext %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i8 %0, i8* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%9 = load i32, i32* @optarg
%10 = load i32*, i32** %7
%11 = call i32 @sscanf(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %29
17: ; preds = %3
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i8, i8* %5
%23 = load i8*, i8** %6
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8 signext %22, i8* %23)
%25 = load i32, i32* @EINVAL
%26 = sub nsw i32 0, %25
store i32 %26, i32* %4
br label %29
27: ; preds = %17
br label %28
28: ; preds = %27
store i32 0, i32* %4
br label %29
29: ; preds = %28, %20, %14
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@optarg = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [25 x i8] c"Unable to parse argument\00"
@stderr = global i32 0
@.str.2 = [57 x i8] c"Error: Unable to parse argument '-%c %s' as an integer.\0A\00"
@EINVAL = global i32 0
define i32 @parse_int(i8 signext %0, i8* %1, i32* %2) {
%4 = load i32, i32* @optarg
%5 = tail call i32 @sscanf(i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %3
%10 = icmp eq i32 %5, 1
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8 signext %0, i8* %1)
%14 = load i32, i32* @EINVAL
%15 = sub nsw i32 0, %14
br label %16
16: ; preds = %9, %11, %7
%17 = phi i32 [ %5, %7 ], [ %15, %11 ], [ 0, %9 ]
ret i32 %17
}