#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*/ print_usage();
int /*<<< orphan*/ printf(char *, int, ...);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int parse_option(char *optarg, int opt, long unsigned int *number) {
  char *endptr;
  if ((optarg == NULL) || (*optarg == '\0')) {
    printf("wmem -%c: option expected\n", opt);
    print_usage();
    return -EINVAL;
  }
  *number = strtoul(optarg, &endptr, 0);
  if (*endptr != '\0') {
    printf("wmem -%c: invalid option: %s\n", opt, optarg);
    print_usage();
    return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115e <parse_option+0x2e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1189 <parse_option+0x59>
mov    -0x14(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <print_usage@plt>
xor    %eax,%eax
mov    0x2e61(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <parse_option+0xb8>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e1 <parse_option+0xb1>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <print_usage@plt>
xor    %eax,%eax
mov    0x2e09(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <parse_option+0xb8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_option>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
test   %rdi,%rdi
je     117b <parse_option+0x4b>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     117b <parse_option+0x4b>
mov    %rdx,%r15
mov    %rsp,%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,(%r15)
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     119e <parse_option+0x6e>
lea    0xeaf(%rip),%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    118c <parse_option+0x5c>
lea    0xe7e(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <print_usage@plt>
mov    0x2e44(%rip),%rax
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"wmem -%c: option expected\0A\00"
@EINVAL = global i32 0
@.str.1 = [30 x i8] c"wmem -%c: invalid option: %s\0A\00"
define i32 @parse_option(i8* %0, i32 %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64*
%8 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64* %2, i64** %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11, %3
%17 = load i32, i32* %6
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @print_usage()
%20 = load i32, i32* @EINVAL
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %38
22: ; preds = %11
%23 = load i8*, i8** %5
%24 = call i64 @strtoul(i8* %23, i8** %8, i32 0)
%25 = load i64*, i64** %7
store i64 %24, i64* %25
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %22
%31 = load i32, i32* %6
%32 = load i8*, i8** %5
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %31, i8* %32)
%34 = call i32 (...) @print_usage()
%35 = load i32, i32* @EINVAL
%36 = sub nsw i32 0, %35
store i32 %36, i32* %4
br label %38
37: ; preds = %22
store i32 0, i32* %4
br label %38
38: ; preds = %37, %30, %16
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [27 x i8] c"wmem -%c: option expected\0A\00"
@EINVAL = global i32 0
@.str.1 = [30 x i8] c"wmem -%c: invalid option: %s\0A\00"
define i32 @parse_option(i8* %0, i32 %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8* %0, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7, %3
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %19
12: ; preds = %7
%13 = call i64 @strtoul(i8* %0, i8** %4, i32 0)
store i64 %13, i64* %2
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %0)
br label %19
19: ; preds = %10, %17
%20 = tail call i32 (...) @print_usage()
%21 = load i32, i32* @EINVAL
%22 = sub nsw i32 0, %21
br label %23
23: ; preds = %19, %12
%24 = phi i32 [ 0, %12 ], [ %22, %19 ]
ret i32 %24
}