#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 */
long strtol(char const *, char **, int /*<<< orphan*/);
bool parse_number(const char *param, unsigned char *number) {
  char *endptr = (char *)param;
  long int tmp_number = strtol(param, &endptr, 0);
  if (param == endptr) {
    return false;
  }
  if (tmp_number < 0 || tmp_number > 255) {
    return false;
  }
  *number = tmp_number;
  return true;
}


x86 assembly (clang, -O0):
<parse_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1155 <parse_number+0x45>
movl   $0x0,-0x4(%rbp)
jmp    118d <parse_number+0x7d>
cmpq   $0x0,-0x28(%rbp)
jl     116e <parse_number+0x5e>
cmpq   $0xff,-0x28(%rbp)
jle    117a <parse_number+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    118d <parse_number+0x7d>
mov    -0x28(%rbp),%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
xor    %edx,%edx
call   1030 <strtol@plt>
cmp    %rbx,0x8(%rsp)
je     1148 <parse_number+0x38>
cmp    $0xff,%rax
ja     1148 <parse_number+0x38>
mov    %al,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_number(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
%9 = load i8*, i8** %4
%10 = call i64 @strtol(i8* %9, i8** %6, i32 0)
store i64 %10, i64* %7
%11 = load i8*, i8** %4
%12 = load i8*, i8** %6
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %26
15: ; preds = %2
%16 = load i64, i64* %7
%17 = icmp slt i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i64, i64* %7
%20 = icmp sgt i64 %19, 255
br i1 %20, label %21, label %22
21: ; preds = %18, %15
store i32 0, i32* %3
br label %26
22: ; preds = %18
%23 = load i64, i64* %7
%24 = trunc i64 %23 to i8
%25 = load i8*, i8** %5
store i8 %24, i8* %25
store i32 1, i32* %3
br label %26
26: ; preds = %22, %21, %14
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @parse_number(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%5 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
%8 = icmp ugt i64 %5, 255
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = trunc i64 %5 to i8
store i8 %11, i8* %1
br label %12
12: ; preds = %2, %10
%13 = phi i32 [ 1, %10 ], [ 0, %2 ]
ret i32 %13
}