#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 */
typedef int uint16_t;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int);
uint16_t __attribute__((nonnull))
parse_arg(char *str, bool odd, char *err_str) {
  uint16_t parsed = (uint16_t)strtoul(str, NULL, 10);
  if (parsed == 0 || (odd && parsed % 2 == 0) || errno != 0) {
    fprintf(stderr, "[ERROR] invalid %s: '%s'\n", err_str, str);
    exit(1);
  }
  return parsed;
}


x86 assembly (clang, -O0):
<parse_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1191 <parse_arg+0x61>
cmpl   $0x0,-0xc(%rbp)
je     1180 <parse_arg+0x50>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1191 <parse_arg+0x61>
mov    0x2e51(%rip),%rax
cmpq   $0x0,(%rax)
je     11b8 <parse_arg+0x88>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe57(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_arg>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
test   %eax,%eax
je     1166 <parse_arg+0x36>
test   %ebp,%ebp
je     1154 <parse_arg+0x24>
test   $0x1,%al
je     1166 <parse_arg+0x36>
mov    0x2e7d(%rip),%rcx
cmpq   $0x0,(%rcx)
jne    1166 <parse_arg+0x36>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"[ERROR] invalid %s: '%s'\0A\00"
define i32 @parse_arg(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i32 @strtoul(i8* %8, i32* null, i32 10)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* %7
%17 = srem i32 %16, 2
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15, %12
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19, %15, %3
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %6
%25 = load i8*, i8** %4
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"[ERROR] invalid %s: '%s'\0A\00"
define i32 @parse_arg(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @strtoul(i8* nocapture %0, i32* null, i32 10)
%5 = icmp eq i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = icmp eq i32 %1, 0
br i1 %7, label %14, label %8
8: ; preds = %6
%9 = and i32 %4, 1
%10 = icmp eq i32 %9, 0
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %17, label %21
14: ; preds = %6
%15 = load i64, i64* @errno
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14, %8, %3
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %0)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %8, %14
ret i32 %4
}