#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 /*<<< orphan*/ print_usage(int);
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);
    print_usage(false);
    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    0x2e9b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe96(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1193 <parse_int+0x53>
lea    0xe80(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <parse_int+0xa2>
cmpl   $0x1,-0x1c(%rbp)
je     11d6 <parse_int+0x96>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rcx
lea    0xe68(%rip),%rsi
movsbl %al,%edx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1060 <print_usage@plt>
xor    %eax,%eax
mov    0x2e04(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <parse_int+0xa2>
jmp    11db <parse_int+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11aa <parse_int+0x6a>
xor    %ebx,%ebx
cmp    $0x1,%ebp
je     119d <parse_int+0x5d>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
movsbl %r15b,%edx
lea    0xe99(%rip),%rsi
mov    %r14,%rcx
call   1030 <fprintf@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <print_usage@plt>
mov    0x2e35(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe52(%rip),%rdi
call   1050 <perror@plt>
mov    %ebp,%ebx
jmp    119d <parse_int+0x5d>

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 %30
17: ; preds = %3
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %28
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 = call i32 @print_usage(i32 0)
%26 = load i32, i32* @EINVAL
%27 = sub nsw i32 0, %26
store i32 %27, i32* %4
br label %30
28: ; preds = %17
br label %29
29: ; preds = %28
store i32 0, i32* %4
br label %30
30: ; preds = %29, %20, %14
%31 = load i32, i32* %4
ret i32 %31
}

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 %17
9: ; preds = %3
%10 = icmp eq i32 %5, 1
br i1 %10, label %17, 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 = tail call i32 @print_usage(i32 0)
%15 = load i32, i32* @EINVAL
%16 = sub nsw i32 0, %15
br label %17
17: ; preds = %9, %11, %7
%18 = phi i32 [ %5, %7 ], [ %16, %11 ], [ 0, %9 ]
ret i32 %18
}