#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*/ do_exit(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int /*<<< orphan*/);
short int parse_reg_val(char *optarg) {
  int i;
  char *p;
  errno = 0;
  i = strtol(optarg, &p, 0);
  if (errno || p == optarg) {
    fprintf(stderr, "can't parse register value\n");
    do_exit(1);
  }
  return i;
}


x86 assembly (clang, -O0):
<parse_reg_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e75(%rip),%rax
cmpq   $0x0,(%rax)
jne    117b <parse_reg_val+0x4b>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    119a <parse_reg_val+0x6a>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <do_exit@plt>
mov    -0xc(%rbp),%eax
cwtl
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_reg_val>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e96(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,%r14d
cmpq   $0x0,0x0(%rbp)
jne    1167 <parse_reg_val+0x37>
cmp    %rbx,0x8(%rsp)
jne    1186 <parse_reg_val+0x56>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <do_exit@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [28 x i8] c"can't parse register value\0A\00"
define signext i16 @parse_reg_val(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i32 @strtol(i8* %5, i8** %4, i32 0)
store i32 %6, i32* %3
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = load i8*, i8** %2
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9, %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @do_exit(i32 1)
br label %17
17: ; preds = %13, %9
%18 = load i32, i32* %3
%19 = trunc i32 %18 to i16
ret i16 %19
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [28 x i8] c"can't parse register value\0A\00"
define signext i16 @parse_reg_val(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i32 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i64, i64* @errno
%6 = icmp ne i64 %5, 0
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, %0
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @do_exit(i32 1)
br label %14
14: ; preds = %1, %10
%15 = trunc i32 %4 to i16
ret i16 %15
}