#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*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char const *, char **, int /*<<< orphan*/);
unsigned long getnumber(char *key, char *word, char stopchar, int *ec) {
  char *endp;
  unsigned long no = strtoul((const char *)word, &endp, 0);
  if (word == 0 || *word == '\0') {
    fprintf(stderr, "key %s has missing number\n", key);
    *ec = 1;
    return 0;
  }
  if (*endp != stopchar) {
    fprintf(stderr, "key %s has invalid parameter %s\n", key, word);
    *ec = 1;
    return 0;
  }
  *ec = 0;
  return no;
}


x86 assembly (clang, -O0):
<getnumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1167 <getnumber+0x47>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1199 <getnumber+0x79>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11f4 <getnumber+0xd4>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
je     11e2 <getnumber+0xc2>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11f4 <getnumber+0xd4>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnumber>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
test   %rbx,%rbx
je     1161 <getnumber+0x41>
cmpb   $0x0,(%rbx)
je     1161 <getnumber+0x41>
mov    %rax,%r12
mov    0x8(%rsp),%rax
cmp    %bpl,(%rax)
jne    1180 <getnumber+0x60>
xor    %eax,%eax
jmp    11a5 <getnumber+0x85>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
xor    %r12d,%r12d
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a0 <getnumber+0x80>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
xor    %r12d,%r12d
mov    %r15,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%eax
mov    %eax,(%r14)
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"key %s has missing number\0A\00"
@.str.1 = [33 x i8] c"key %s has invalid parameter %s\0A\00"
define i64 @getnumber(i8* %0, i8* %1, i8 signext %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = call i64 @strtoul(i8* %1, i8** %5, i32 0)
%8 = icmp eq i8* %1, null
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9, %4
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %22
15: ; preds = %9
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, %2
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %22
22: ; preds = %15, %19, %12
%23 = phi i32 [ 1, %19 ], [ 1, %12 ], [ 0, %15 ]
%24 = phi i64 [ 0, %19 ], [ 0, %12 ], [ %7, %15 ]
store i32 %23, i32* %3
ret i64 %24
}