#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int EINVAL;
scalar_t__ strcmp(char const *, char const *);
int /*<<< orphan*/ strtoul(char const *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ warnx(char *, char const *, char const *);
int parse_val(const char *param, const char *args[], uint32_t *val) {
  char *p;
  if (strcmp(param, args[0]) != 0)
    return (EINVAL);
  *val = strtoul(args[1], &p, 0);
  if (p > args[1] && p[0] == 0)
    return (0);
  warnx("parameter \"%s\" has bad \"value\" %s", args[0], args[1]);
  return (EINVAL);
}


x86 assembly (clang, -O0):
<parse_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     116f <parse_val+0x3f>
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <parse_val+0xaf>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jbe    11b8 <parse_val+0x88>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b8 <parse_val+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11df <parse_val+0xaf>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe32(%rip),%rdi
call   1030 <warnx@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_val>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    (%rsi),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1182 <parse_val+0x52>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rax
mov    0x8(%rbx),%rdx
cmp    %rdx,%rax
jbe    1173 <parse_val+0x43>
cmpb   $0x0,(%rax)
je     118b <parse_val+0x5b>
mov    (%rbx),%rsi
lea    0xe83(%rip),%rdi
call   1030 <warnx@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@.str = [34 x i8] c"parameter \22%s\22 has bad \22value\22 %s\00"
define i32 @parse_val(i8* %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = load i8**, i8*** %6
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i64 @strcmp(i8* %9, i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* @EINVAL
store i32 %16, i32* %4
br label %44
17: ; preds = %3
%18 = load i8**, i8*** %6
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strtoul(i8* %20, i8** %8, i32 0)
%22 = load i32*, i32** %7
store i32 %21, i32* %22
%23 = load i8*, i8** %8
%24 = load i8**, i8*** %6
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = icmp ugt i8* %23, %26
br i1 %27, label %28, label %35
28: ; preds = %17
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 0, i32* %4
br label %44
35: ; preds = %28, %17
%36 = load i8**, i8*** %6
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %6
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %38, i8* %41)
%43 = load i32, i32* @EINVAL
store i32 %43, i32* %4
br label %44
44: ; preds = %35, %34, %15
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str = [34 x i8] c"parameter \22%s\22 has bad \22value\22 %s\00"
define i32 @parse_val(i8* %0, i8** nocapture %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = load i8*, i8** %1
%7 = tail call i64 @strcmp(i8* %0, i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = load i32, i32* @EINVAL
br label %25
11: ; preds = %3
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strtoul(i8* %13, i8** %4, i32 0)
store i32 %14, i32* %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %12
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i8, i8* %15
%20 = icmp eq i8 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18, %11
%22 = load i8*, i8** %1
%23 = tail call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %16)
%24 = load i32, i32* @EINVAL
br label %25
25: ; preds = %18, %21, %9
%26 = phi i32 [ %10, %9 ], [ %24, %21 ], [ 0, %18 ]
ret i32 %26
}